Build and Publish Containers #877
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: Build and Publish Containers | |
| on: | |
| push: | |
| branches: [main, unstable] | |
| tags: ['v*'] | |
| pull_request: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '29 13 * * *' # run daily | |
| jobs: | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| platform: linux/amd64 | |
| - os: ubuntu-latest | |
| platform: linux/386 | |
| - os: ubuntu-24.04-arm | |
| platform: linux/arm64 | |
| - os: ubuntu-24.04-arm | |
| platform: linux/arm/v6 | |
| - os: ubuntu-24.04-arm | |
| platform: linux/arm/v7 | |
| runs-on: ${{ matrix.os }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| steps: | |
| - name: Runner Info | |
| run: printenv | sort | |
| - name: Prepare | |
| id: prep | |
| run: | | |
| echo "platform_pair=${platform//\//-}" >> $GITHUB_OUTPUT | |
| echo "repo_lowercase=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT | |
| env: | |
| platform: ${{ matrix.platform }} | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: '0' # need full history to get version from git tag | |
| - name: Container metadata | |
| id: metadata | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ steps.prep.outputs.repo_lowercase }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: ${{ matrix.platform }} | |
| cache-from: type=gha,scope=build-${{ steps.prep.outputs.platform_pair }} | |
| cache-to: type=gha,mode=max,scope=build-${{ steps.prep.outputs.platform_pair }} | |
| context: . | |
| outputs: type=image,name=ghcr.io/${{ steps.prep.outputs.repo_lowercase }},push-by-digest=true,name-canonical=true,push=true | |
| - name: Export digest | |
| run: | | |
| mkdir -p /tmp/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ steps.prep.outputs.platform_pair }} | |
| path: /tmp/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Runner Info | |
| run: printenv | sort | |
| - name: Prepare | |
| id: prep | |
| run: | | |
| echo "repo_lowercase=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: /tmp/digests | |
| pattern: digests-* | |
| merge-multiple: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Container metadata | |
| id: metadata | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ steps.prep.outputs.repo_lowercase }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create manifest list and push | |
| working-directory: /tmp/digests | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf 'ghcr.io/${{ steps.prep.outputs.repo_lowercase }}@sha256:%s ' *) | |
| - name: Inspect image | |
| run: | | |
| docker buildx imagetools inspect ghcr.io/${{ steps.prep.outputs.repo_lowercase }}:${{ steps.metadata.outputs.version }} |