From 1ebea971d77b57036774e02b2e8a63cc3e9853f1 Mon Sep 17 00:00:00 2001 From: Norbert Gruszka <40759761+norbertgruszka@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:23:20 +0100 Subject: [PATCH] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index d4b5c8c..41272c7 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -71,22 +71,25 @@ jobs: uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a with: context: . - push: ${{ github.event_name != 'pull_request' }} + push: ${{ github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/') }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + - name: Sign image with a key + if: ${{ github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/') }} + run: | + cosign sign --yes --key env://COSIGN_PRIVATE_KEY "${TAGS}@${DIGEST}" + env: + TAGS: ${{ steps.docker_meta.outputs.tags }} + COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} + COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} - # Sign the resulting Docker image digest except on PRs. - # This will only write to the public Rekor transparency log when the Docker - # repository is public to avoid leaking data. If you would like to publish - # transparency data even for private images, pass --force to cosign below. - # https://github.com/sigstore/cosign - - name: Sign the published Docker image - if: ${{ github.event_name != 'pull_request' }} + - name: Sign the images with GitHub OIDC Token + if: ${{ github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/') }} 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 }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + TAGS: ${{ steps.docker_meta.outputs.tags }} + run: cosign sign --yes "${TAGS}@${DIGEST}"