name: Build Disk Collector Image on: release: types: [published] 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?' required: false type: boolean default: false jobs: setup: name: Resolve version and check authorization runs-on: ubuntu-latest outputs: isAuthorized: ${{ steps.check-auth.outputs.is_authorized }} version: ${{ steps.vars.outputs.version }} tag_latest: ${{ steps.vars.outputs.tag_latest }} steps: - name: check-auth id: check-auth run: | if [ "${{ github.event_name }}" = "release" ]; then echo "is_authorized=true" >> $GITHUB_OUTPUT else echo "is_authorized=${{ contains(secrets.DEPLOYMENT_AUTHORIZED_USERS, github.triggering_actor) }}" >> $GITHUB_OUTPUT fi - name: Resolve version and tag_latest id: vars run: | if [ "${{ github.event_name }}" = "release" ]; then VERSION="${{ github.event.release.tag_name }}" VERSION="${VERSION#v}" TAG_LATEST=${{ !github.event.release.prerelease }} else VERSION="${{ inputs.version }}" TAG_LATEST=${{ inputs.tag_latest }} fi echo "version=$VERSION" >> $GITHUB_OUTPUT echo "tag_latest=$TAG_LATEST" >> $GITHUB_OUTPUT build: name: Build disk-collector image (${{ matrix.platform }}) needs: setup if: needs.setup.outputs.isAuthorized == 'true' runs-on: ubuntu-latest permissions: contents: read packages: write strategy: fail-fast: false matrix: platform: [linux/amd64, linux/arm64] steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - 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: context: install/sidecar-disk-collector platforms: ${{ matrix.platform }} outputs: type=image,name=ghcr.io/${{ github.repository_owner }}/project-nomad-disk-collector,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-${{ 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: [setup, 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 run: | VERSION="${{ needs.setup.outputs.version }}" TAGS="-t ghcr.io/${{ github.repository_owner }}/project-nomad-disk-collector:${VERSION}" TAGS="$TAGS -t ghcr.io/${{ github.repository_owner }}/project-nomad-disk-collector:v${VERSION}" if [ "${{ needs.setup.outputs.tag_latest }}" = "true" ]; then TAGS="$TAGS -t ghcr.io/${{ github.repository_owner }}/project-nomad-disk-collector:latest" fi docker buildx imagetools create $TAGS \ $(printf 'ghcr.io/${{ github.repository_owner }}/project-nomad-disk-collector@sha256:%s ' *) working-directory: /tmp/digests - name: Inspect image run: | docker buildx imagetools inspect ghcr.io/${{ github.repository_owner }}/project-nomad-disk-collector:${{ needs.setup.outputs.version }}