diff --git a/.github/workflows/release-package.yaml b/.github/workflows/release-package.yaml new file mode 100644 index 0000000..401fc8f --- /dev/null +++ b/.github/workflows/release-package.yaml @@ -0,0 +1,56 @@ +name: Create and publish a Docker image + +on: + push: + branches: + - main + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + build-args: VERSION=${{ steps.meta.outputs.version }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + diff --git a/Dockerfile b/Dockerfile index bf82b2f..8e6bb1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,15 @@ -FROM python:3-slim +FROM python:3.13.0a4-slim # prepare base image RUN apt update && apt install --yes \ locales \ locales-all \ entr \ - git \ wkhtmltopdf \ && rm -rf /var/lib/apt/lists/* # prepare application folder -RUN mkdir -p /app/src \ - && mkdir -p /app/shared +RUN mkdir -p /app/src # install python dependencies WORKDIR /app @@ -29,8 +27,12 @@ COPY ./src /app/src EXPOSE 8000 ENV SERVICE_PORT=8000 + +ARG VERSION=local # override at build +ENV VERSION=${VERSION} + CMD ["start"] VOLUME [ "/app/src" ] -VOLUME [ "/app/shared" ] -VOLUME [ "/app/htmlcov/" ] +VOLUME [ "/app/data/db.sqlite3" ] + diff --git a/deploy/.helmignore b/deploy/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/deploy/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/deploy/Chart.yaml b/deploy/Chart.yaml new file mode 100644 index 0000000..b2ded6a --- /dev/null +++ b/deploy/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v2 +name: micro-invoicer +description: Deployment chart for my Django application + +version: 0.1.0 +type: application + +appVersion: "1.2.3" diff --git a/deploy/make-values.sh b/deploy/make-values.sh new file mode 100755 index 0000000..0c99748 --- /dev/null +++ b/deploy/make-values.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -euo pipefail + +context=${1:-local} +domain=${2:-fibonet.ro} + +DB_APP_USER=django +DB_APP_PASS=$(pwgen -s1 42) +DB_APP_NAME="microinvoicer_${context}" + +DJANGO_SECRET_KEY=$(pwgen -s1 63) +DJANGO_ADMIN_PASS=$(pwgen -s1 42) + +cat <init-db.sh <