@@ -3,34 +3,69 @@ name: Publish Docker Image
33on :
44 release :
55 types : [published]
6+ workflow_dispatch :
7+
8+ # Required for cosign keyless (OIDC) to mint tokens
9+ permissions :
10+ contents : read
11+ packages : write
12+ id-token : write # needed for signing the images with GitHub OIDC Token
613
714jobs :
815 push_to_registry :
9- name : Push Docker image to Docker Hub
16+ name : Push Docker image to GitHub Container registry
1017 runs-on : ubuntu-latest
1118 timeout-minutes : 60
1219 steps :
1320 - name : Check out the repo
14- uses : actions/checkout@v5
21+ 22+
23+ - name : Install cosign
24+ 1525
16- - name : Log in to Docker Hub
17- uses : docker/login-action@v3
26+ - name : Login to GitHub Container Registry
27+ uses : docker/login-action@v3.6.0
1828 with :
19- username : ${{ secrets.DOCKERHUB_USERNAME }}
20- password : ${{ secrets.DOCKERHUB_TOKEN }}
29+ registry : ghcr.io
30+ username : ${{ github.actor }}
31+ password : ${{ secrets.GITHUB_TOKEN }}
2132
2233 - name : Extract metadata (tags, labels) for Docker
2334 id : meta
24- uses : docker/metadata-action@v5
35+ uses : docker/metadata-action@v5.8.0
2536 with :
26- images : OpenModelica/crossbuild
37+ images : ghcr.io/openmodelica/crossbuild
38+ tags : type=ref,event=release
2739
2840 - name : Build and push Docker image
29- uses : docker/build-push-action@v6
41+ id : build-and-push
42+ 3043 with :
3144 context : .
3245 file : ./Dockerfile
3346 tags : ${{ steps.meta.outputs.tags }}
3447 labels : ${{ steps.meta.outputs.labels }}
3548 annotations : ${{ steps.meta.outputs.annotations }}
3649 push : true
50+
51+ - name : Sign the images with GitHub OIDC Token
52+ env :
53+ DIGEST : ${{ steps.build-and-push.outputs.digest }}
54+ TAGS : ${{ steps.meta.outputs.tags }}
55+ run : |
56+ images=""
57+ for tag in ${TAGS}; do
58+ images+="${tag}@${DIGEST} "
59+ done
60+ cosign sign --yes ${images}
61+
62+ - name : Verify signatures
63+ env :
64+ DIGEST : ${{ steps.build-and-push.outputs.digest }}
65+ TAGS : ${{ steps.meta.outputs.tags }}
66+ run : |
67+ images=""
68+ for tag in ${TAGS}; do
69+ images+="${tag}@${DIGEST} "
70+ done
71+ cosign verify ${images}
0 commit comments