Skip to content

Commit 1531a97

Browse files
committed
fix(ci): allow GHCR push and use repo-scoped login
- Add packages: write so workflow can push to ghcr.io - Use github.repository as registry username for audit clarity
1 parent 207399e commit 1531a97

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

.github/workflows/build-and-publish-docker-image.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Build and publish docker image
22
on:
3-
workflow_dispatch:
3+
workflow_dispatch:
44
push:
55
branches:
66
- main
@@ -17,6 +17,8 @@ jobs:
1717
runs-on: ubuntu-latest
1818
permissions:
1919
contents: read
20+
# Required to push images to GitHub Container Registry (ghcr.io)
21+
packages: write
2022
# Gives the action the ability to mint the OIDC token necessary to request a Sigstore signing certificate
2123
id-token: write
2224
# Permission necessary to persist the attestation
@@ -32,18 +34,21 @@ jobs:
3234
uses: docker/login-action@v3
3335
with:
3436
registry: ${{ env.REGISTRY }}
35-
username: ${{ github.actor }}
37+
# Repo-scoped username for audit clarity; write access is granted by GITHUB_TOKEN (repo token)
38+
username: ${{ github.repository }}
3639
password: ${{ secrets.GITHUB_TOKEN }}
3740
- name: Extract metadata (tags, labels) for Docker
3841
id: meta
3942
uses: docker/metadata-action@v5
4043
with:
4144
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4245
tags: |
46+
# Branch name as tag (and semver for v* tag pushes only)
4347
type=ref,event=branch
44-
type=ref,event=pr
4548
type=semver,pattern={{version}}
4649
type=semver,pattern={{major}}.{{minor}}
50+
# So GHCR shows "latest" instead of the image digest
51+
type=raw,value=latest
4752
- name: Build and push Docker image
4853
id: push
4954
uses: docker/build-push-action@v6
@@ -57,4 +62,4 @@ jobs:
5762
with:
5863
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
5964
subject-digest: ${{ steps.push.outputs.digest }}
60-
push-to-registry: true
65+
push-to-registry: true

0 commit comments

Comments
 (0)