Skip to content

Commit

Permalink
ci: enable multi arch docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mikonse committed Jan 3, 2024
1 parent 9d9c32f commit c66013e
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 19 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: Pull Request
on:
pull_request:

env:
DOCKER_IMAGE_NAME_API: api
DOCKER_IMAGE_NAME_FRONTEND: frontend
DOCKER_IMAGE_TAGS: latest ${{ github.sha }} ${{github.ref_name}}

jobs:
build_and_test_frontend:
uses: ./.github/workflows/frontend.yaml
Expand All @@ -10,3 +15,71 @@ jobs:
build_and_test_backend:
uses: ./.github/workflows/backend.yaml
secrets: inherit

get-distros:
name: "Calculate list of debian distros and docker image tags"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- id: set-distros
run: |
# if we're running from a tag, get the full list of distros; otherwise just use debian:sid
dists='["debian:bookworm"]'
tags="latest $GITHUB_SHA"
if [[ $GITHUB_REF == refs/tags/* ]]; then
dists=$(tools/build_debian_packages.py --show-dists-json)
tags="latest $GITHUB_SHA latest-release $GITHUB_REF_NAME"
fi
echo "::set-output name=distros::$dists"
echo "::set-output name=tags::$tags"
# map the step outputs to job outputs
outputs:
distros: ${{ steps.set-distros.outputs.distros }}
tags: ${{ steps.set-distros.outputs.tags }}

test-build-docker:
name: Build and publish ready made docker containers
runs-on: ubuntu-latest
needs:
- get-distros
steps:
- uses: actions/checkout@v4

- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Set up Nodejs
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
cache-dependency-path: frontend/package-lock.json

- name: Install dependencies
run: npm ci
working-directory: frontend

- name: Build API Image
id: build-api-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.DOCKER_IMAGE_NAME_API }}
tags: ${{ needs.get-distros.outputs.tags }}
platforms: linux/amd64, linux/arm64/v8
containerfiles: ./docker/Dockerfile-api

- name: Build Frontend
working-directory: frontend
run: npx nx build web

- name: Build Frontend Image
id: build-frontend-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.DOCKER_IMAGE_NAME_FRONTEND }}
tags: ${{ needs.get-distros.outputs.tags }}
platforms: linux/amd64, linux/arm64/v8
containerfiles: ./docker/Dockerfile-frontend
15 changes: 11 additions & 4 deletions .github/workflows/push_on_master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,19 @@ jobs:
- get-distros
steps:
- uses: actions/checkout@v4

- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Set up Nodejs
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
cache-dependency-path: frontend/package-lock.json

- name: Install dependencies
run: npm ci
working-directory: frontend
Expand All @@ -66,8 +73,8 @@ jobs:
with:
image: ${{ env.DOCKER_IMAGE_NAME_API }}
tags: ${{ needs.get-distros.outputs.tags }}
containerfiles: |
./docker/Dockerfile-api
platforms: linux/arm64/v8, linux/amd64
containerfiles: ./docker/Dockerfile-api

- name: Push API Image To quay.io
id: push-to-quay-api
Expand All @@ -89,8 +96,8 @@ jobs:
with:
image: ${{ env.DOCKER_IMAGE_NAME_FRONTEND }}
tags: ${{ needs.get-distros.outputs.tags }}
containerfiles: |
./docker/Dockerfile-frontend
platforms: linux/arm64/v8, linux/amd64
containerfiles: ./docker/Dockerfile-frontend

- name: Push Frontend Image To quay.io
id: push-to-quay-frontend
Expand Down
16 changes: 11 additions & 5 deletions docker/Dockerfile-api
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# syntax=docker/dockerfile:1.3
FROM python:3.10-alpine as builder
RUN apk add --no-cache build-base libffi-dev
RUN python3 -m venv /opt/abrechnung-venv
ADD . /src
RUN /opt/abrechnung-venv/bin/python3 -m pip install /src

FROM python:3.10-alpine
RUN addgroup -S abrechnung && adduser -S abrechnung -G abrechnung \
&& apk add --no-cache curl
ADD . /usr/share/abrechnung
RUN pip install --editable /usr/share/abrechnung
RUN addgroup -S abrechnung && adduser -S abrechnung -G abrechnung && apk add --no-cache curl
COPY --from=builder /opt/abrechnung-venv/ /opt/abrechnung-venv/
ADD --chmod=644 --chown=abrechnung:abrechung config/abrechnung.yaml /etc/abrechnung/abrechnung.yaml
ADD --chmod=755 ./docker/entrypoint.py /
COPY --chown=abrechnung:abrechnung ./docker/crontab /var/spool/cron/crontabs/abrechnung
ENTRYPOINT ["/entrypoint.py"]
USER abrechnung
ENTRYPOINT ["/opt/abrechnung-venv/bin/python3", "/entrypoint.py"]
20 changes: 10 additions & 10 deletions docker/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
import subprocess
import sys
from os import execlp, execvp, getenv, makedirs
Expand All @@ -16,21 +15,22 @@ def to_bool(data: str):
"on",
]

abrechnung_venv_python = "/opt/abrechnung-venv/bin/python3"

print("generating config")
config = dict()
filename = "/usr/share/abrechnung/config/abrechnung.yaml"
config = {}
filename = "/etc/abrechnung/abrechnung.yaml"
with open(filename, "r", encoding="utf-8") as filehandle:
config = safe_load(filehandle)

if not "service" in config:
config["service"] = dict()
config["service"] = {}
if not "database" in config:
config["database"] = dict()
config["database"] = {}
if not "registration" in config:
config["registration"] = dict()
config["registration"] = {}
if not "email" in config:
config["email"] = dict()
config["email"] = {}

config["service"]["url"] = getenv("SERVICE_URL", "https://localhost")
config["service"]["api_url"] = getenv("SERVICE_API_URL", "https://localhost/api")
Expand Down Expand Up @@ -70,12 +70,12 @@ def to_bool(data: str):
if sys.argv[1] == "api":
print("migrating")
sys.stdout.flush()
subprocess.run("abrechnung db migrate", shell=True, check=True)
subprocess.run([abrechnung_venv_python, "-m", "abrechnung", "db", "migrate"], shell=True, check=True)
print("migrated")
if sys.argv[1] == "cron":
print("running cron...")
sys.stdout.flush()
execlp("crond", "crond", "-f")
print("starting abrechnung...")
print(f"starting abrechnung with forwarded argv {sys.argv}")
sys.stdout.flush()
execvp("abrechnung", sys.argv)
execvp(abrechnung_venv_python, [abrechnung_venv_python, "-m", "abrechnung"] + sys.argv[1:])

0 comments on commit c66013e

Please sign in to comment.