diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ef3e8c2..b51d369 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,13 +13,23 @@ env: DOCKER_NAME: ${{ vars.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} jobs: - build-image: + build-certgen-image: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - amd64 + - arm64 permissions: contents: read packages: write steps: + - name: Prepare + run: | + platform=linux/${{ matrix.platform }} + echo "PLATFORM_PAIR_CERTS=${platform//\//-}" >> $GITHUB_ENV - name: Checkout repository uses: actions/checkout@v2 @@ -48,8 +58,60 @@ jobs: uses: docker/build-push-action@v5 with: context: . + platforms: linux/${{ matrix.platform }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=${{github.repository}}:latest cache-to: type=inline + + - name: Export digest + run: | + mkdir -p /tmp/digests/backend + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/backend/${digest#sha256:}" + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR_CERTS }} + path: /tmp/digests/backend/* + if-no-files-found: error + retention-days: 1 + + merge-certgen-platform-images: + runs-on: ubuntu-latest + needs: + - build-certgen-image + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests/backend + pattern: digests-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_NAME }} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests/backend + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.DOCKER_NAME }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.DOCKER_NAME }}:${{ steps.meta.outputs.version }} +