From d81573e7bc35a8416fbb7e274b4b8acd7bb2ce74 Mon Sep 17 00:00:00 2001 From: yojoshb <68751897+yojoshb@users.noreply.github.com> Date: Thu, 11 Apr 2024 01:54:51 -0500 Subject: [PATCH] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 47 +++++++++++++++------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index bd85a1c..b6953e0 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,9 +1,6 @@ name: DockerBuild - # This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. +# They are provided by a third-party and are governed by separate terms of service, privacy policy, and support documentation. on: workflow_dispatch: @@ -34,19 +31,14 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - - # Install the cosign tool except on PR - # https://github.com/sigstore/cosign-installer + # Install the cosign tool except on PR https://github.com/sigstore/cosign-installer - name: Install cosign if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@v3.5.0 - + uses: sigstore/cosign-installer@v3.5.0 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: Setup Docker buildx uses: docker/setup-buildx-action@v3 - - name: Log into registry ${{ env.REGISTRY }} if: github.event_name != 'pull_request' uses: docker/login-action@v3 @@ -54,14 +46,13 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata id: meta uses: docker/metadata-action@v4 with: flavor: latest=true images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - + tags: type=sha,format=long - name: Build and push Docker image id: build-and-push uses: docker/build-push-action@v5 @@ -71,13 +62,27 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - - # Sign the resulting Docker image digest except on PRs. - # https://github.com/sigstore/cosign - - name: Sign the published Docker image + # Sign the resulting Docker image digest except on PRs. https://github.com/sigstore/cosign + - name: Sign image with a key if: ${{ github.event_name != 'pull_request' }} + run: | + images="" + for tag in ${TAGS}; do + images+="${tag}@${DIGEST} " + done + cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${images} env: - COSIGN_EXPERIMENTAL: "true" - # This step uses the identity token to provision an ephemeral certificate against the sigstore community Fulcio instance. - run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }} + TAGS: ${{ steps.meta.outputs.tags }} + COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} + COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + - name: Sign the images with GitHub OIDC Token + env: + DIGEST: ${{ steps.build-and-push.outputs.digest }} + TAGS: ${{ steps.meta.outputs.tags }} + run: | + images="" + for tag in ${TAGS}; do + images+="${tag}@${DIGEST} " + done + cosign sign --yes ${images}