Skip to content

Commit e5fec17

Browse files
refactor: update Docker publish workflow to support GitHub Container Registry
1 parent 9a39ebc commit e5fec17

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

.github/workflows/docker-publish.yml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ on:
88
- 'v*'
99

1010
env:
11-
REGISTRY: docker.io
12-
IMAGE_NAME: productdevbook/nitroping
11+
DOCKERHUB_REGISTRY: docker.io
12+
DOCKERHUB_IMAGE: productdevbook/nitroping
13+
GHCR_REGISTRY: ghcr.io
14+
GHCR_IMAGE: ${{ github.repository }}
1315

1416
jobs:
1517
build-amd64:
@@ -31,11 +33,20 @@ jobs:
3133
username: ${{ secrets.DOCKER_USERNAME }}
3234
password: ${{ secrets.DOCKER_PASSWORD }}
3335

36+
- name: Log in to GitHub Container Registry
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.GHCR_REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
3443
- name: Extract metadata
3544
id: meta
3645
uses: docker/metadata-action@v5
3746
with:
38-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47+
images: |
48+
${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}
49+
${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }}
3950
tags: |
4051
type=ref,event=branch,suffix=-amd64
4152
type=semver,pattern={{version}},suffix=-amd64
@@ -81,11 +92,20 @@ jobs:
8192
username: ${{ secrets.DOCKER_USERNAME }}
8293
password: ${{ secrets.DOCKER_PASSWORD }}
8394

95+
- name: Log in to GitHub Container Registry
96+
uses: docker/login-action@v3
97+
with:
98+
registry: ${{ env.GHCR_REGISTRY }}
99+
username: ${{ github.actor }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
101+
84102
- name: Extract metadata
85103
id: meta
86104
uses: docker/metadata-action@v5
87105
with:
88-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
106+
images: |
107+
${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}
108+
${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }}
89109
tags: |
90110
type=ref,event=branch,suffix=-arm64
91111
type=semver,pattern={{version}},suffix=-arm64
@@ -129,21 +149,49 @@ jobs:
129149
username: ${{ secrets.DOCKER_USERNAME }}
130150
password: ${{ secrets.DOCKER_PASSWORD }}
131151

132-
- name: Extract metadata for manifest
133-
id: meta
152+
- name: Log in to GitHub Container Registry
153+
uses: docker/login-action@v3
154+
with:
155+
registry: ${{ env.GHCR_REGISTRY }}
156+
username: ${{ github.actor }}
157+
password: ${{ secrets.GITHUB_TOKEN }}
158+
159+
- name: Extract metadata for Docker Hub
160+
id: meta-dockerhub
134161
uses: docker/metadata-action@v5
135162
with:
136-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
163+
images: ${{ env.DOCKERHUB_REGISTRY }}/${{ env.DOCKERHUB_IMAGE }}
137164
tags: |
138165
type=ref,event=branch
139166
type=semver,pattern={{version}}
140167
type=semver,pattern={{major}}.{{minor}}
141168
type=semver,pattern={{major}}
142169
type=raw,value=latest,enable={{is_default_branch}}
143170
144-
- name: Create and push manifest
171+
- name: Extract metadata for GHCR
172+
id: meta-ghcr
173+
uses: docker/metadata-action@v5
174+
with:
175+
images: ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE }}
176+
tags: |
177+
type=ref,event=branch
178+
type=semver,pattern={{version}}
179+
type=semver,pattern={{major}}.{{minor}}
180+
type=semver,pattern={{major}}
181+
type=raw,value=latest,enable={{is_default_branch}}
182+
183+
- name: Create and push Docker Hub manifest
184+
run: |
185+
for tag in ${{ steps.meta-dockerhub.outputs.tags }}; do
186+
docker buildx imagetools create \
187+
--tag ${tag} \
188+
${tag}-amd64 \
189+
${tag}-arm64
190+
done
191+
192+
- name: Create and push GHCR manifest
145193
run: |
146-
for tag in ${{ steps.meta.outputs.tags }}; do
194+
for tag in ${{ steps.meta-ghcr.outputs.tags }}; do
147195
docker buildx imagetools create \
148196
--tag ${tag} \
149197
${tag}-amd64 \

0 commit comments

Comments
 (0)