Skip to content

Commit 60c8170

Browse files
committed
ci: push docker images to ghcr.io and keep latest off rc tags
Log in to ghcr.io alongside Docker Hub and publish the image to both registries via docker/metadata-action's multi-image list. Replace the default latest=auto flavor, which moves latest on every tag push, with an explicit rule: only a non-prerelease tag (no 'rc', case-insensitive) updates latest. The docker jobs gain packages:write for GHCR. Signed-off-by: Date Huang <tjjh89017@hotmail.com>
1 parent f2fdfa3 commit 60c8170

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

.github/actions/docker/action.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ inputs:
66
description: 'Application name for Docker image'
77
required: true
88
docker-token:
9-
description: 'Docker registry token'
9+
description: 'Docker Hub registry token'
10+
required: true
11+
ghcr-token:
12+
description: 'GitHub token with packages:write for ghcr.io'
1013
required: true
1114
repository-owner:
1215
description: 'Repository owner for Docker image'
@@ -32,10 +35,22 @@ runs:
3235
username: ${{ inputs.repository-owner }}
3336
password: ${{ inputs.docker-token }}
3437

38+
- uses: docker/login-action@v4
39+
with:
40+
registry: ghcr.io
41+
username: ${{ github.actor }}
42+
password: ${{ inputs.ghcr-token }}
43+
3544
- uses: docker/metadata-action@v6
3645
id: meta
3746
with:
38-
images: ${{ inputs.repository-owner }}/${{ inputs.app-name }}
47+
images: |
48+
${{ inputs.repository-owner }}/${{ inputs.app-name }}
49+
ghcr.io/${{ inputs.repository-owner }}/${{ inputs.app-name }}
50+
# latest=auto would move `latest` on every tag push, rc included;
51+
# only a non-prerelease tag may move it.
52+
flavor: |
53+
latest=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref_name, 'rc') }}
3954
4055
- uses: docker/build-push-action@v7
4156
with:

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ jobs:
257257
if: github.event_name == 'push'
258258
name: Build Docker container
259259
runs-on: ubuntu-latest
260+
permissions:
261+
contents: read
262+
packages: write
260263
# e2e-required transitively covers lint/test/build/build-plugins and the
261264
# realnet report.
262265
needs: e2e-required
@@ -267,6 +270,7 @@ jobs:
267270
with:
268271
app-name: ${{ env.APP }}
269272
docker-token: ${{ secrets.DOCKER_TOKEN }}
273+
ghcr-token: ${{ secrets.GITHUB_TOKEN }}
270274
repository-owner: ${{ github.repository_owner }}
271275

272276
# Runtime test of the real publish -> opendht -> establish pipeline with two

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ jobs:
191191
docker:
192192
name: Build Docker container
193193
runs-on: ubuntu-latest
194+
permissions:
195+
contents: read
196+
packages: write
194197
needs:
195198
- create-release
196199
steps:
@@ -200,4 +203,5 @@ jobs:
200203
with:
201204
app-name: ${{ env.APP }}
202205
docker-token: ${{ secrets.DOCKER_TOKEN }}
206+
ghcr-token: ${{ secrets.GITHUB_TOKEN }}
203207
repository-owner: ${{ github.repository_owner }}

0 commit comments

Comments
 (0)