chore: run build in paralell #68
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Image | |
| on: | |
| push: | |
| # TODO: Remove this once we merge new-api into main | |
| branches: ["new-api"] | |
| # Publish semver tags as releases | |
| tags: ["v*.*.*"] | |
| pull_request: | |
| branches: ["main", "new-api"] | |
| env: | |
| GHCR_REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: linux/amd64 | |
| runner: ubuntu-latest | |
| - platform: linux/arm64 | |
| runner: ubuntu-24.04-arm | |
| runs-on: ${{ matrix.runner }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Prepare | |
| id: platform | |
| run: echo "pair=${platform//\//-}" >> "$GITHUB_OUTPUT" | |
| env: | |
| platform: ${{ matrix.platform }} | |
| - name: Setup Docker buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Login to GitHub Container Registry | |
| - name: Log into GitHub Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| # ${{ env.DOCKERHUB_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./docker/Dockerfile | |
| platforms: ${{ matrix.platform }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=buildkit-${{ steps.platform.outputs.pair }} | |
| cache-to: type=gha,mode=max,scope=buildkit-${{ steps.platform.outputs.pair }} | |
| outputs: ${{ github.event_name != 'pull_request' && format('type=image,"name={0}/{1}",push-by-digest=true,name-canonical=true,push=true', env.GHCR_REGISTRY, env.IMAGE_NAME) || '' }} | |
| - name: Export digest | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| mkdir -p "${RUNNER_TEMP}/digests" | |
| digest="${DIGEST}" | |
| touch "${RUNNER_TEMP}/digests/${digest#sha256:}" | |
| env: | |
| DIGEST: ${{ steps.build.outputs.digest }} | |
| RUNNER_TEMP: ${{ runner.temp }} | |
| - name: Upload digest | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ steps.platform.outputs.pair }} | |
| path: ${{ runner.temp }}/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'pull_request' | |
| needs: build | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ${{ runner.temp }}/digests | |
| pattern: digests-* | |
| merge-multiple: true | |
| - name: Setup Docker buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Login to GitHub Container Registry | |
| - name: Log into GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.GHCR_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| # ${{ env.DOCKERHUB_REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=sha,format=short | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Create manifest list and push | |
| working-directory: ${{ runner.temp }}/digests | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf "${GHCR_REGISTRY}/${IMAGE_NAME}@sha256:%s " *) | |
| env: | |
| GHCR_REGISTRY: ${{ env.GHCR_REGISTRY }} | |
| IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
| - name: Inspect image | |
| run: docker buildx imagetools inspect "${GHCR_REGISTRY}/${IMAGE_NAME}:${VERSION}" | |
| env: | |
| GHCR_REGISTRY: ${{ env.GHCR_REGISTRY }} | |
| IMAGE_NAME: ${{ env.IMAGE_NAME }} | |
| VERSION: ${{ steps.meta.outputs.version }} |