Skip to content

Commit dabd9d9

Browse files
committed
ops: improve ci by attesting build
1 parent 07f8cb3 commit dabd9d9

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

.github/workflows/docker.yml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ on:
55
branches:
66
- main
77

8+
permissions:
9+
contents: read
10+
packages: write
11+
id-token: write
12+
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ghcr.io/${{ github.repository }}
17+
818
jobs:
919
docker:
1020
runs-on: ubuntu-latest
@@ -14,18 +24,33 @@ jobs:
1424
uses: actions/checkout@v4
1525

1626
- name: Setup Nix
17-
uses: cachix/install-nix-action@v27
27+
uses: cachix/install-nix-action@v30
1828

1929
- name: Build Docker image
2030
run: nix build .#docker
2131

22-
- name: Log in to GitHub Container Registry
23-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
32+
- name: Login to GitHub Container Registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
2438

25-
- name: Load Docker image
39+
- name: Push Docker image to GitHub Container Registry
40+
id: push
2641
run: |
2742
docker load < result
28-
docker tag drawbu.dev ghcr.io/${{ github.repository }}:latest
29-
30-
- name: Push Docker image to GitHub Container Registry
31-
run: docker push ghcr.io/${{ github.repository }}:latest
43+
docker tag drawbu.dev ${{ env.IMAGE_NAME }}
44+
docker push ${{ env.IMAGE_NAME }}
45+
digest=$(docker image inspect ${{ env.IMAGE_NAME }} \
46+
| nix run nixpkgs#jq -- --raw-output '.[].RepoDigests[]' \
47+
| cut -d@ -f2)
48+
echo "digest=$digest" >> "$GITHUB_OUTPUT"
49+
50+
- name: Attest
51+
uses: actions/attest-build-provenance@v1
52+
id: attest
53+
with:
54+
subject-name: ${{ env.IMAGE_NAME }}
55+
subject-digest: ${{ steps.push.outputs.digest }}
56+
push-to-registry: true

0 commit comments

Comments
 (0)