Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: enable multi arch docker builds #189

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
5 changes: 5 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 Down
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:abrechnung 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"]
21 changes: 11 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 @@ -17,20 +16,22 @@ def to_bool(data: str):
]


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 +71,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:])
Loading