name: Build Primary Docker Image on: workflow_dispatch: inputs: version: description: 'Semantic version to label the Docker image under (no "v" prefix, e.g. "1.2.3")' required: true type: string tag_latest: description: 'Also tag this image as :latest? (Keep false for RC and beta releases)' required: false type: boolean default: false jobs: check_authorization: name: Check authorization to publish new Docker image runs-on: ubuntu-latest outputs: isAuthorized: ${{ steps.check-auth.outputs.is_authorized }} steps: - name: check-auth id: check-auth run: echo "is_authorized=${{ contains(secrets.DEPLOYMENT_AUTHORIZED_USERS, github.triggering_actor) }}" >> $GITHUB_OUTPUT build: name: Build primary image (${{ matrix.platform }}) needs: check_authorization if: needs.check_authorization.outputs.isAuthorized == 'true' runs-on: ${{ matrix.runner }} permissions: contents: read packages: write strategy: fail-fast: false matrix: include: - platform: linux/amd64 runner: ubuntu-latest - platform: linux/arm64 runner: ubuntu-latest-arm64 steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in 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 }} outputs: type=image,name=ghcr.io/${{ github.repository_owner }}/project-nomad,push-by-digest=true,name-canonical=true,push=true build-args: | VERSION=${{ inputs.version }} BUILD_DATE=${{ github.event.workflow_run.created_at }} VCS_REF=${{ github.sha }} - 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-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 merge: name: Create and push multi-arch manifest needs: build runs-on: ubuntu-latest permissions: contents: read packages: write steps: - 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: Log in 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 \ -t ghcr.io/${{ github.repository_owner }}/project-nomad:${{ inputs.version }} \ -t ghcr.io/${{ github.repository_owner }}/project-nomad:v${{ inputs.version }} \ ${{ inputs.tag_latest && '-t ghcr.io/${{ github.repository_owner }}/project-nomad:latest' || '' }} \ $(printf 'ghcr.io/${{ github.repository_owner }}/project-nomad@sha256:%s ' *) - name: Inspect image run: | docker buildx imagetools inspect ghcr.io/${{ github.repository_owner }}/project-nomad:${{ inputs.version }}