Skip to content

Commit 6d528b1

Browse files
authored
Sign Docker image with cosign (#8)
* Publish to GitHub container registry * Sign and verify Docker image with cosign * Update Readme
1 parent eea896f commit 6d528b1

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

.github/workflows/publish.yml

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,69 @@ name: Publish Docker Image
33
on:
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

714
jobs:
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+
uses: actions/[email protected]
22+
23+
- name: Install cosign
24+
uses: sigstore/[email protected]
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+
uses: docker/[email protected]
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}

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,9 @@ cmake --build build_linux64 --target create_fmu
6666

6767
### Release Versions
6868

69-
The [publish.yml][gh-publish-file] workflow will build and
69+
The [publish.yml][gh-publish-file] workflow will build, sign and
7070
upload the Docker image to
71-
[OpenModelica/crossbuild][docker-hub] DockerHub for each release.
72-
73-
To do it manually run:
74-
75-
```bash
76-
export REGISTRY=openmodelica
77-
export TAG=v1.26.0
78-
docker login
79-
docker image tag crossbuild:$TAG $REGISTRY/crossbuild:$TAG
80-
docker push $REGISTRY/crossbuild:$TAG
81-
```
71+
[GitHub container registry][gh-container-registry] for each release.
8272

8373
### Development Versions
8474

@@ -105,5 +95,4 @@ This repository is part of OpenModelica and licensed with
10595
[gh-publish-file]: ./.github/workflows/publish.yml
10696
[gh-build-file]: ./.github/workflows/build.yml
10797
[gh-container-registry]: https://github.com/OpenModelica/openmodelica-crossbuild/pkgs/container/crossbuild
108-
[docker-hub]: https://hub.docker.com/repository/docker/OpenModelica/crossbuild
10998
[osmc-license]: ./OSMC-License.txt

0 commit comments

Comments
 (0)