1111
1212jobs :
1313 build :
14- name : Build
1514 runs-on : ubuntu-latest
15+ permissions :
16+ contents : read
17+ packages : write
18+ id-token : write
1619
1720 steps :
1821 - name : Checkout repository
1922 uses : actions/checkout@v5
2023
21- - name : Setup Docker buildx
24+ - name : Install cosign
25+ if : github.event_name == 'release'
26+ 27+
28+ - name : Set up Docker Buildx
2229 uses : docker/setup-buildx-action@v3
2330
2431 - name : Log into registry ${{ env.REGISTRY }}
32+ if : github.event_name == 'release'
2533 uses : docker/login-action@v3
2634 with :
2735 registry : ${{ env.REGISTRY }}
28- username : ${{ github.repository_owner }}
36+ username : ${{ github.actor }}
2937 password : ${{ secrets.GITHUB_TOKEN }}
3038
3139 - name : Extract Docker metadata
@@ -35,12 +43,20 @@ jobs:
3543 images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3644
3745 - name : Build and push Docker image
46+ id : build-and-push
3847 uses : docker/build-push-action@v6
3948 with :
4049 context : .
50+ push : ${{ github.event_name == 'release' }}
4151 labels : ${{ steps.meta.outputs.labels }}
52+ tags : ${{ steps.meta.outputs.tags }}
4253 platforms : |
4354 linux/amd64
4455 linux/arm64
45- push : true
46- tags : ${{ steps.meta.outputs.tags }}
56+
57+ - name : Sign the published Docker image
58+ if : github.event_name == 'release'
59+ env :
60+ TAGS : ${{ steps.meta.outputs.tags }}
61+ DIGEST : ${{ steps.build-and-push.outputs.digest }}
62+ run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
0 commit comments