From 6266845390aed3f82eb18f7d97116aa1c483238a Mon Sep 17 00:00:00 2001 From: Christian Wahl Date: Fri, 26 Dec 2025 18:55:10 +0100 Subject: [PATCH 1/7] - Change base Python image version to 3.13 in Dockerfile - Add `docker-entrypoint.sh` for improved container startup process - Introduce `docker-compose.yml` for multi-service orchestration --- Dockerfile | 14 ++++++--- docker-compose.yml | 67 ++++++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 14 +++++++++ 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 1628c3d..22c8c65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3 +FROM python:3.13 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 @@ -7,10 +7,16 @@ COPY requirements.txt /code/ RUN pip install -r requirements.txt COPY WBSAtool /code/ +# Static files volume RUN mkdir /static VOLUME /static -RUN python manage.py collectstatic --noinput -RUN python manage.py migrate --noinput + +# Copy startup script that will run scripts +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh EXPOSE 8000 -CMD gunicorn WBSAtool.wsgi:application --bind 0.0.0.0:8000 --workers 2 \ No newline at end of file + +# Entrypoint runs scripts then executes the container CMD +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +CMD ["gunicorn", "WBSAtool.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "2"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..54fe587 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,67 @@ +services: + db: + image: postgres:17 + restart: unless-stopped + volumes: + - ./data/db:/var/lib/postgresql/data + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + + web: + image: ff-durlach/wbsa-tool:latest + restart: always + expose: + - 8000 + environment: + - DEBUG=True + - HSTS_SECONDS=31536000 + # public hostname + - ALLOWED_HOSTS= + - TRUSTED_ORIGINS= + - SECRET_KEY=SECRET + - DATABASE=postgres + - POSTGRES_HOST=db + - POSTGRES_USER=postgres + - POSTGRES_PASS=postgres + - POSTGRES_PORT=5432 + # link to publicly reachable nominatim instance + - NOMINATIM_URL=https://nominatim/search + volumes: + - "./data/static:/static" + depends_on: + - nominatim + - db + networks: + - default + - proxy + + nominatim: + image: mediagis/nominatim:4.3 + restart: unless-stopped + environment: + # see https://github.com/mediagis/nominatim-docker/tree/master/4.3#configuration for more options + PBF_URL: https://download.geofabrik.de/europe/germany/baden-wuerttemberg/karlsruhe-regbez-latest.osm.pbf + REPLICATION_URL: https://download.geofabrik.de/europe/germany/baden-wuerttemberg/karlsruhe-regbez-updates/ + NOMINATIM_PASSWORD: very_secure_password + networks: + - proxy + volumes: + - ./data/nominatim:/var/lib/postgresql/14/main + shm_size: 1gb + + + nginx: + image: nginx + restart: always + volumes: + - "./data/static:/usr/share/nginx/html/static:ro" + networks: + - proxy + depends_on: + - web + + +networks: + proxy: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..4ac83be --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh +set -e + +# Ensure we're in the app directory +cd /code + +# Collect static files at container startup (works with a mounted /static volume) +python manage.py collectstatic --noinput + +# Run migrations +RUN python manage.py migrate --noinput + +# Execute the CMD passed to the container +exec "$@" From c07d0b7badfd0a81010c02a00782f9571c198ec5 Mon Sep 17 00:00:00 2001 From: Christian Wahl Date: Fri, 26 Dec 2025 19:39:13 +0100 Subject: [PATCH 2/7] Add GitHub Actions workflow for building and publishing Docker images --- .github/workflows/docker-publish.yml | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..b2db8cd --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,68 @@ +name: Build and Publish Docker Image + +on: + push: + branches: ["**"] + pull_request: + +concurrency: + group: docker-publish-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + packages: write + +env: + IMAGE_NAME: ${{ github.repository }} + REGISTRY: ghcr.io + +jobs: + docker: + name: Build and Publish + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract Docker metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + # Tag latest for default branch (commonly 'master') + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.event_name == 'push' }} + # Branch name tags for non-default branches on push + type=ref,event=branch,enable=${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) && github.event_name == 'push' }} + # PR tags like pr- + type=ref,event=pr + # Always include a short SHA tag for traceability + type=sha,format=short + + - name: Log in to GitHub Container Registry + if: ${{ github.event_name == 'push' }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and (conditionally) push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max + From 48b0f21434cc2811f5f6ccf05c73c90d07c4e861 Mon Sep 17 00:00:00 2001 From: Christian Wahl Date: Fri, 26 Dec 2025 19:40:52 +0100 Subject: [PATCH 3/7] Restrict Docker publish workflow to the master branch --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index b2db8cd..6cb5bc2 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -2,7 +2,7 @@ name: Build and Publish Docker Image on: push: - branches: ["**"] + branches: ["master"] pull_request: concurrency: From c139e7274de9eb76866cecae161937b767e4850c Mon Sep 17 00:00:00 2001 From: Christian Wahl Date: Fri, 26 Dec 2025 19:42:38 +0100 Subject: [PATCH 4/7] Simplify Docker workflow steps in `docker-publish.yml`. --- .github/workflows/docker-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 6cb5bc2..81a3ebe 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -32,7 +32,7 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Extract Docker metadata (tags, labels) + - name: Add Docker metadata id: meta uses: docker/metadata-action@v5 with: @@ -56,7 +56,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and (conditionally) push + - name: Build and push uses: docker/build-push-action@v6 with: context: . From e260438c08581ef944dcd4546116c5c34367df7f Mon Sep 17 00:00:00 2001 From: Christian Wahl Date: Fri, 26 Dec 2025 19:44:26 +0100 Subject: [PATCH 5/7] Add annotations support in Docker publishing workflow --- .github/workflows/docker-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 81a3ebe..8b862e0 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -63,6 +63,7 @@ jobs: file: ./Dockerfile platforms: linux/amd64 tags: ${{ steps.meta.outputs.tags }} + annotations: ${{ steps.meta.outputs.annotations }} cache-from: type=gha cache-to: type=gha,mode=max From b6d516529282ea6bcb411ab49d340c149b1f5be1 Mon Sep 17 00:00:00 2001 From: Christian Wahl Date: Fri, 26 Dec 2025 19:46:34 +0100 Subject: [PATCH 6/7] Enable image push in Docker publish workflow --- .github/workflows/docker-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 8b862e0..ab90eb5 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -62,6 +62,7 @@ jobs: context: . file: ./Dockerfile platforms: linux/amd64 + push: true tags: ${{ steps.meta.outputs.tags }} annotations: ${{ steps.meta.outputs.annotations }} cache-from: type=gha From 81b36a4b84ea0214e0c67587bd4539f8795e5094 Mon Sep 17 00:00:00 2001 From: Christian Wahl Date: Fri, 26 Dec 2025 19:49:36 +0100 Subject: [PATCH 7/7] Remove redundant conditional check in Docker publish workflow --- .github/workflows/docker-publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index ab90eb5..7ccb1bc 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -49,7 +49,6 @@ jobs: type=sha,format=short - name: Log in to GitHub Container Registry - if: ${{ github.event_name == 'push' }} uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }}