From 8db2747f90eb1f4f647d644ddad9613a701fec23 Mon Sep 17 00:00:00 2001 From: Alastair Weakley Date: Mon, 24 Jun 2024 15:31:48 +1000 Subject: [PATCH] Add multi-arch build --- .github/workflows/ci.yml | 48 +++++++++++++++++++++++++++++++++++++++- Dockerfile | 9 +++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44e1bd8..2d26a48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: runs-on: - linux - self-hosted - - x64 + - ${{ matrix.arch }} steps: - uses: docker/login-action@v1 with: @@ -35,6 +35,52 @@ jobs: docker tag ${{ env.IMAGE_REPO }}:sha-${{ env.IMAGE_TAG }} ${{ env.IMAGE_REPO }}:latest docker push ${{ env.IMAGE_REPO }}:latest + strategy: + matrix: + arch: + - arm64 + - x64 + + manifest: + env: + IMAGE_REPO: ${{ secrets.DOCKER_ORG }}/${{ secrets.DOCKER_REPO }} + IMAGE_TAG: sha-${{ github.sha }} + needs: image + runs-on: + - linux + - self-hosted + steps: + - uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Push branch manifest list + run: | + docker buildx imagetools create -t \ + ${{ env.IMAGE_REPO }}:${GITHUB_REF#refs/heads/} \ + ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}-arm64 \ + ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}-x64 + - name: Push SHA manifest list + run: | + docker buildx imagetools create -t \ + ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }} \ + ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}-arm64 \ + ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}-x64 + - name: Push 'latest' manifest list + if: github.ref == 'refs/heads/master' + run: | + # Latest. + docker buildx imagetools create -t \ + ${{ env.IMAGE_REPO }}:latest \ + ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}-arm64 \ + ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}-x64 + - name: Remove arch tags + run: | + TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "${{ secrets.DOCKER_USERNAME }}", "password": "${{ secrets.DOCKER_PASSWORD }}"}' "https://hub.docker.com/v2/users/login/" | jq -r '.token') + curl "https://hub.docker.com/v2/repositories/${{ secrets.DOCKER_ORG }}/${{ secrets.DOCKER_REPO }}/tags/${{ env.IMAGE_TAG }}-arm64/" -X DELETE -H "Authorization: JWT ${TOKEN}" + curl "https://hub.docker.com/v2/repositories/${{ secrets.DOCKER_ORG }}/${{ secrets.DOCKER_REPO }}/tags/${{ env.IMAGE_TAG }}-x64/" -X DELETE -H "Authorization: JWT ${TOKEN}" + + readme: needs: image runs-on: diff --git a/Dockerfile b/Dockerfile index 4a1a66c..8e1a17a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,14 @@ RUN apk update \ && rm -rf /var/cache/apk/* ENV DOCKERIZE_VERSION=0.5.0 -RUN wget -nv -O - "https://github.com/jwilder/dockerize/releases/download/v${DOCKERIZE_VERSION}/dockerize-linux-amd64-v${DOCKERIZE_VERSION}.tar.gz" | tar -xz -C /usr/local/bin/ -f - + +RUN apkArch="$(apk --print-arch)"; \ +case "$apkArch" in \ + armhf) export DOCKERIZE_ARCH='armhf' ;; \ + x86) export DOCKERIZE_ARCH='amd64' ;; \ +esac; + +RUN wget -nv -O - "https://github.com/jwilder/dockerize/releases/download/v${DOCKERIZE_VERSION}/dockerize-linux-${DOCKERIZE_ARCH}-v${DOCKERIZE_VERSION}.tar.gz" | tar -xz -C /usr/local/bin/ -f - ENV PATH="$PATH:/opt/restic-pg-dump/bin"