Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/create-and-publish-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# source: https://docs.github.com/en/actions/tutorials/publish-packages/publish-docker-images#publishing-images-to-docker-hub-and-github-packages
name: Create and publish a Docker image

# manually trigger while testing
on:
workflow_dispatch

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io

jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `PACKAGE_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Set lowercase image name
run: |
IMAGE_NAME=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Format repo slug
uses: actions/github-script@v8
id: repo_slug
with:
result-encoding: string
script: |
return `ghcr.io/${process.env.GITHUB_REPOSITORY.toLowerCase()}`
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: ./TEKDB
file: ./TEKDB/prod.Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/web:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/web:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}

# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v3
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ celerybeat-schedule

# dotenv
.env
.env.prod

# virtualenv
venv/
Expand Down
46 changes: 46 additions & 0 deletions TEKDB/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM python:3.11-slim

# Prevent Python from writing .pyc files and enable unbuffered stdout/stderr
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1

# Install system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
gcc \
gdal-bin \
libgdal-dev \
libgeos-dev \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /usr/src/app

# Copy requirements first (cache pip install step when dependencies don't change)
COPY requirements.txt requirements_linux.txt /usr/src/app/

# Upgrade pip and install Python dependencies
# Note: editable packages (-e) will be installed at runtime via entrypoint.sh
RUN pip install --upgrade pip \
&& pip install -r requirements.txt -r requirements_linux.txt

# Copy the application code
COPY . /usr/src/app

# Copy and make entrypoint executable. The repository contains `docker/entrypoint.sh`
# which runs collectstatic, migrations and launches uWSGI.
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Expose the port the app runs on (entrypoint starts django development server or uWSGI on 8000)
EXPOSE 8000

# Default settings module (can be overridden at runtime)
ENV DJANGO_SETTINGS_MODULE=TEKDB.settings

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

# use prod server in prod Dockerfile
CMD ["prod"]
7 changes: 2 additions & 5 deletions docker/docker-compose.yml → docker/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
interval: 10s
timeout: 5s
retries: 5

web:
build:
context: ../TEKDB/
Expand All @@ -39,7 +39,4 @@ services:
ports:
- "8000:8000"
volumes:
- ../TEKDB:/usr/src/app

volumes:
tekdb_db_data:
- ../TEKDB:/usr/src/app
44 changes: 7 additions & 37 deletions docker/docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -1,46 +1,16 @@
services:
db:
image: postgis/postgis:15-3.4
restart: always
platform: linux/amd64
environment:
POSTGRES_DB: ${SQL_DATABASE}
POSTGRES_USER: ${SQL_USER}
POSTGRES_PASSWORD: ${SQL_PASSWORD}
volumes:
- tekdb_db_data:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${SQL_USER} -d ${SQL_DATABASE} -h localhost -p ${SQL_PORT}"]
interval: 10s
timeout: 5s
retries: 5
extends:
file: common.yaml
service: db

web:
build:
context: ../TEKDB/
dockerfile: ../TEKDB/Dockerfile
extends:
file: common.yaml
service: web
command: ["prod"]
restart: unless-stopped
depends_on:
- db
env_file:
- .env.dev
environment:
ALLOWED_HOSTS: ${ALLOWED_HOSTS}
DEBUG: ${DEBUG}
SQL_ENGINE: ${SQL_ENGINE}
SQL_HOST: ${SQL_HOST}
SQL_PORT: ${SQL_PORT}
SQL_DATABASE: ${SQL_DATABASE}
SQL_USER: ${SQL_USER}
SQL_PASSWORD: ${SQL_PASSWORD}
SECRET_KEY: ${SECRET_KEY}
ports:
- "8000:8000"
volumes:
- ../TEKDB:/usr/src/app
- .env.prod

volumes:
tekdb_db_data:
13 changes: 13 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
db:
extends:
file: common.yaml
service: db

web:
extends:
file: common.yaml
service: web

volumes:
tekdb_db_data: