diff --git a/src/git_automation/templates/workflow/docker.yml.j2 b/src/git_automation/templates/workflow/docker.yml.j2 index 9cb6bae..0c53b6f 100644 --- a/src/git_automation/templates/workflow/docker.yml.j2 +++ b/src/git_automation/templates/workflow/docker.yml.j2 @@ -5,7 +5,9 @@ docker: permissions: contents: read packages: write # needed for pushing docker image - id-token: write # needed for signing the images with GitHub OIDC Token + outputs: + tags: ${{ steps.meta.outputs.tags }} + digest: ${{ steps.build-and-push.outputs.digest }} strategy: matrix: platform: @@ -23,14 +25,41 @@ docker: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/sigstore/sample-honk + tags: | + type=ref,event=pr + type=sha + type=raw,value=latest + type=semver,pattern={{version}} - name: Build and push + id: build-and-push uses: docker/build-push-action@v6 with: platforms: ${{ matrix.platform }} sbom: true provenance: true push: true - tags: | - ${{ github.repository }}:${{ github.ref_name }} - ${{ github.repository }}:latest + tags: ${{ steps.docker_meta.outputs.tags }} +docker-sign: + name: Docker sign + runs-on: ubuntu-latest + permissions: + packages: write # needed for pushing docker signature + id-token: write # needed for signing the images with GitHub OIDC Token + needs: [docker] + steps: + - name: Sign the images with GitHub OIDC Token + env: + DIGEST: ${{ needs.docker.outputs.digest }} + TAGS: ${{ needs.docker.outputs.tags }} + run: | + images="" + for tag in ${TAGS}; do + images+="${tag}@${DIGEST} " + done + cosign sign --yes ${images} {%- endraw %} \ No newline at end of file diff --git a/src/git_automation/templates/workflow/release.yml.j2 b/src/git_automation/templates/workflow/release.yml.j2 index c1a884c..d112b94 100644 --- a/src/git_automation/templates/workflow/release.yml.j2 +++ b/src/git_automation/templates/workflow/release.yml.j2 @@ -13,7 +13,7 @@ {%- if package %} {%- if language == "python" %}, publish-package{%- elif language == "go" %}, publish-binary{% endif -%} {% endif -%} -{%- if docker %}, docker{% endif -%} +{%- if docker %}, docker-sign{% endif -%} {%- endset %} name: {{ language }} release on: