From e67c4dd77250f9df726f1dc5271d226d386ab2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Loipf=C3=BChrer?= Date: Wed, 3 Jan 2024 21:40:42 +0100 Subject: [PATCH] ci: enable multi arch docker builds --- .github/workflows/pull_request.yaml | 76 +++++++++++++++++++++++++++ .github/workflows/push_on_master.yaml | 9 ++++ 2 files changed, 85 insertions(+) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index fdc36819..53f2eb51 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -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 @@ -10,3 +15,74 @@ 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/arm/v7, linux/arm64/v8, linux/amd64, linux/arm64 + platforms: linux/arm64/v8, linux/amd64, linux/arm64 + 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/arm64/v8, linux/amd64, linux/arm64 + containerfiles: | + ./docker/Dockerfile-frontend diff --git a/.github/workflows/push_on_master.yaml b/.github/workflows/push_on_master.yaml index a0e4dd39..d13804c3 100644 --- a/.github/workflows/push_on_master.yaml +++ b/.github/workflows/push_on_master.yaml @@ -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 @@ -66,6 +73,7 @@ jobs: with: image: ${{ env.DOCKER_IMAGE_NAME_API }} tags: ${{ needs.get-distros.outputs.tags }} + platforms: linux/arm64/v8, linux/amd64, linux/arm64 containerfiles: | ./docker/Dockerfile-api @@ -89,6 +97,7 @@ jobs: with: image: ${{ env.DOCKER_IMAGE_NAME_FRONTEND }} tags: ${{ needs.get-distros.outputs.tags }} + platforms: linux/arm64/v8, linux/amd64, linux/arm64 containerfiles: | ./docker/Dockerfile-frontend