Skip to content

Commit

Permalink
πŸ”– (v0.9.0): add docker support (#21)
Browse files Browse the repository at this point in the history
Added docker support

## Commits

* ✨ (Dockerfile): add Dockerfile

* ✨ (docker-compose.yml): add docker-compose with configs

* πŸ”§ (run.sh): webserver listen all ips

* ✨ (Makefile): add build & push

Image name is based on current dir name.

* πŸ› (src/app.py): fix hardcoded vault's ip

No more hardcoded vault's ip.
Now Vault's ip is retrieved from VAULT_CONF_URL.

* ⁉️ (Makefile): change image name

Changed image name from '<harborurl>/<dirname>' to '<dirname>' for
testings purpose.

* πŸ”§ (docker-compose): update container's ip

Updated container's ip from hardcoded to readable from `.env` file.

* πŸ”₯ (Makefile): removed build & push targets

* ✨ (docker/): add docker folder for images repo

* πŸ€– (ci/cd): docker build image workflow
  • Loading branch information
ncvescera authored Sep 20, 2024
1 parent bb40acd commit b3fa98a
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Build Docker Image

on:
push:
branches: [ "main" ]
pull_request: [ "main" ]

jobs:
build:
runs-on: self-hosted

steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: cd docker && make build
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.PHONY: lint

lint:
poetry run pylint $(shell git ls-files '*.py')
24 changes: 24 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM python:3.12
MAINTAINER NicolΓ² Vescera <[email protected]>

RUN pip install poetry

RUN mkdir /project
COPY . /project

WORKDIR /project

# set envs to activate poetry env
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

RUN poetry install

ENV VIRTUAL_ENV=/project/.venv \
PATH="/project/.venv/bin:$PATH"

EXPOSE 5000

CMD ["./run.sh"]
28 changes: 28 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include buildinfo.mk

.PHONY: all
all: check build push tag

.PHONY: check
check:
ifeq ($(IMAGE),)
$(error "Missing IMAGE")
endif
ifeq ($(DEPLOYED),)
$(error "Missing DEPLOYED")
endif

.PHONY: build
build: check
cd .. && docker build -t $(IMAGE):$(shell date +%Y-%m-%d) -f docker/Dockerfile .

.PHONY: push
push: check
docker push $(IMAGE):$(shell date +%Y-%m-%d)
docker tag $(IMAGE):$(shell date +%Y-%m-%d) $(IMAGE):latest
docker push $(IMAGE):latest

.PHONY: tag
tag: check
docker tag $(IMAGE):$(DEPLOYED) $(IMAGE):deployed
docker push $(IMAGE):deployed
3 changes: 3 additions & 0 deletions docker/buildinfo.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IMAGE=harbor1.fisgeo.unipg.it/uninuvola/web
DEPLOYED=2024-09-20

13 changes: 13 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
web:
networks:
uninuvola:
ipv4_address: $WEB_IP
container_name: web
image: web
build: ./
env_file: ../.env

networks:
uninuvola:
external: true
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

flask --app src run --debug
flask --app src run --debug --host 0.0.0.0
6 changes: 5 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@
oauth.register(
name='vault',
server_metadata_url=app.config['VAULT_CONF_URL'],
api_base_url='http://localhost:8200/v1/',
# splits CONF_URL in order to obtain <protocol>://<IP>:<PORT>
# split(..., 1) perform only 1 split in case of multiple occurrences
api_base_url=f"{app.config['VAULT_CONF_URL'].split('/v1', 1)[0]}/v1/",
client_kwargs={
'scope': 'openid web'
}
)

app.logger.debug("OAUTH CONFIGS: %s", oauth._registry)

0 comments on commit b3fa98a

Please sign in to comment.