Skip to content

Commit 666bb39

Browse files
committed
Push image to GHCR as well
1 parent 8ce50ce commit 666bb39

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

.github/workflows/ci.yaml

+30-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- '[2-9][0-9].[0-1][0-9].?[0-3]?[0-9]?'
1111

1212
env:
13-
REGISTRY_IMAGE: erhhung/al2023-devops
13+
IMAGE_NAME: erhhung/al2023-devops
1414
IMAGE_LABELS: |
1515
org.opencontainers.image.authors=Erhhung Yuan <[email protected]>
1616
@@ -124,7 +124,9 @@ jobs:
124124
id: metadata
125125
uses: docker/metadata-action@v5
126126
with:
127-
images: ${{ env.REGISTRY_IMAGE }}
127+
images: |
128+
docker.io/${{ env.IMAGE_NAME }}
129+
ghcr.io/${{ env.IMAGE_NAME }}
128130
labels: ${{ env.IMAGE_LABELS }}
129131

130132
# https://github.com/aws-actions/configure-aws-credentials
@@ -148,9 +150,19 @@ jobs:
148150
id: docker-hub
149151
uses: docker/login-action@v3
150152
with:
153+
registry: docker.io
151154
username: ${{ secrets.DOCKER_HUB_USERNAME }}
152155
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
153156

157+
# https://github.com/docker/login-action
158+
- name: Log in to GitHub GHCR
159+
id: ghcr
160+
uses: docker/login-action@v3
161+
with:
162+
registry: ghcr.io
163+
username: ${{ github.actor }}
164+
password: ${{ github.token }}
165+
154166
# https://github.com/docker/build-push-action
155167
- name: Build and Push by Digest
156168
id: build
@@ -160,7 +172,7 @@ jobs:
160172
with:
161173
platforms: ${{ matrix.platform }}
162174
labels: ${{ steps.metadata.outputs.labels }}
163-
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
175+
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
164176

165177
# create 0-byte file named /tmp/digests/<digest>
166178
- name: Export Digest
@@ -209,30 +221,42 @@ jobs:
209221
id: metadata
210222
uses: docker/metadata-action@v5
211223
with:
212-
images: ${{ env.REGISTRY_IMAGE }}
224+
images: |
225+
docker.io/${{ env.IMAGE_NAME }}
226+
ghcr.io/${{ env.IMAGE_NAME }}
213227
labels: ${{ env.IMAGE_LABELS }}
214228

215229
# https://github.com/docker/login-action
216230
- name: Log in to Docker Hub
217231
id: docker-hub
218232
uses: docker/login-action@v3
219233
with:
234+
registry: docker.io
220235
username: ${{ secrets.DOCKER_HUB_USERNAME }}
221236
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
222237

238+
# https://github.com/docker/login-action
239+
- name: Log in to GitHub GHCR
240+
id: ghcr
241+
uses: docker/login-action@v3
242+
with:
243+
registry: ghcr.io
244+
username: ${{ github.actor }}
245+
password: ${{ github.token }}
246+
223247
- name: Create Manifests and Push
224248
id: manifests
225249
working-directory: /tmp/digests
226250
run: |
227251
tags=($(jq -cr '[.tags[] | "-t \(.)"] | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON"))
228-
images=($(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *))
252+
images=($(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *))
229253
docker buildx imagetools create "${tags[@]}" "${images[@]}"
230254
231255
# confirm merged image manifests
232256
- name: Inspect Image
233257
id: inspect
234258
run: |
235-
tag="${{ env.REGISTRY_IMAGE }}:$DOCKER_METADATA_OUTPUT_VERSION"
259+
tag="${{ env.IMAGE_NAME }}:$DOCKER_METADATA_OUTPUT_VERSION"
236260
docker buildx imagetools inspect $tag
237261
238262
terminate-runner:

Dockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,16 @@ EOT
454454
# FINAL step of Dockerfile: run custom "versions.sh" script
455455
# (copied in prior stage) to generate "/root/.versions.json":
456456
# manifest of all installed tools and their current versions
457-
RUN /tmp/versions.sh && rm -rf /tmp/*
457+
RUN <<'EOT'
458+
set -e
459+
echo "::group::Generate .versions.json"
460+
( set -uxo pipefail
461+
462+
/tmp/versions.sh
463+
dnf clean all
464+
rm -rf /tmp/* /var/log/* /var/cache/dnf
465+
)
466+
echo "::endgroup::"
467+
EOT
458468

459469
CMD ["bash", "--login"]

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ As well as the following utilities:
3434
Size is approximately 2.5 GB.
3535

3636
Images are available in the following repositories:
37-
- Docker Hub: [`erhhung/al2023-devops`](https://hub.docker.com/repository/docker/erhhung/al2023-devops)
37+
- Docker Hub: [`docker.io/erhhung/al2023-devops`](https://hub.docker.com/repository/docker/erhhung/al2023-devops)
38+
- GitHub Container Registry: [`ghcr.io/erhhung/al2023-devops`](https://github.com/users/erhhung/packages/container/al2023-devops)
3839

3940
Version information about installed components can be found in the Docker image at `/root/.versions.json`.

0 commit comments

Comments
 (0)