Skip to content

Commit 9c62fce

Browse files
authored
feat: publish container images to GHCR alongside Docker Hub (#1423)
1 parent 0de8a91 commit 9c62fce

1 file changed

Lines changed: 42 additions & 10 deletions

File tree

.github/workflows/docker.yml

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
description: 'tag to containerize'
1212
required: false
1313

14+
permissions:
15+
contents: read
16+
packages: write
17+
1418
concurrency:
1519
group: Containerization
1620
cancel-in-progress: false
@@ -39,12 +43,19 @@ jobs:
3943
docker-images: true
4044
swap-storage: true
4145

42-
- name: Login
46+
- name: Login to Docker Hub
4347
uses: docker/login-action@v3
4448
with:
4549
username: ${{ secrets.DOCKERHUB_USERNAME }}
4650
password: ${{ secrets.DOCKERHUB_PASSWORD }}
4751

52+
- name: Login to GHCR
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ghcr.io
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
4859
- name: Setup Buildx
4960
uses: docker/setup-buildx-action@v3
5061

@@ -92,7 +103,11 @@ jobs:
92103
FC_COMPILER=${{ 'gfortran' }}
93104
COMPILER_PATH=${{ '/usr/bin' }}
94105
COMPILER_LD_LIBRARY_PATH=${{ '/usr/lib' }}
95-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/mfc:${{ env.TAG }}-${{ matrix.config.name }}-${{ matrix.config.runner }}
106+
labels: |
107+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
108+
tags: |
109+
${{ secrets.DOCKERHUB_USERNAME }}/mfc:${{ env.TAG }}-${{ matrix.config.name }}-${{ matrix.config.runner }}
110+
ghcr.io/${{ github.repository_owner }}/mfc:${{ env.TAG }}-${{ matrix.config.name }}-${{ matrix.config.runner }}
96111
push: true
97112

98113
- name: Build and push image (gpu)
@@ -110,35 +125,52 @@ jobs:
110125
FC_COMPILER=${{ 'nvfortran' }}
111126
COMPILER_PATH=/opt/nvidia/hpc_sdk/${{ matrix.config.compiler_arch }}/compilers/bin
112127
COMPILER_LD_LIBRARY_PATH=/opt/nvidia/hpc_sdk/${{ matrix.config.compiler_arch }}/compilers/lib
113-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/mfc:${{ env.TAG }}-${{ matrix.config.name }}-${{ matrix.config.runner}}
128+
labels: |
129+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
130+
tags: |
131+
${{ secrets.DOCKERHUB_USERNAME }}/mfc:${{ env.TAG }}-${{ matrix.config.name }}-${{ matrix.config.runner }}
132+
ghcr.io/${{ github.repository_owner }}/mfc:${{ env.TAG }}-${{ matrix.config.name }}-${{ matrix.config.runner }}
114133
push: true
115134

116135
manifests:
117136
runs-on: ubuntu-latest
118137
needs: Container
119138
steps:
120-
- name: Login
139+
- name: Login to Docker Hub
121140
uses: docker/login-action@v3
122141
with:
123142
username: ${{ secrets.DOCKERHUB_USERNAME }}
124143
password: ${{ secrets.DOCKERHUB_PASSWORD }}
125144

145+
- name: Login to GHCR
146+
uses: docker/login-action@v3
147+
with:
148+
registry: ghcr.io
149+
username: ${{ github.actor }}
150+
password: ${{ secrets.GITHUB_TOKEN }}
151+
126152
- name: Setup Buildx
127153
uses: docker/setup-buildx-action@v3
128154

129155
- name: Create and Push Manifest Lists
130156
env:
131157
TAG: ${{ needs.Container.outputs.tag }}
132-
REGISTRY: ${{ secrets.DOCKERHUB_USERNAME }}/mfc
158+
DH: ${{ secrets.DOCKERHUB_USERNAME }}/mfc
159+
GH: ghcr.io/${{ github.repository_owner }}/mfc
133160
run: |
134-
docker buildx imagetools create -t $REGISTRY:$TAG-cpu $REGISTRY:$TAG-cpu-ubuntu-22.04 $REGISTRY:$TAG-cpu-ubuntu-22.04-arm
135-
docker buildx imagetools create -t $REGISTRY:$TAG-gpu $REGISTRY:$TAG-gpu-ubuntu-22.04 $REGISTRY:$TAG-gpu-ubuntu-22.04-arm
161+
for R in "$DH" "$GH"; do
162+
docker buildx imagetools create -t $R:$TAG-cpu $R:$TAG-cpu-ubuntu-22.04 $R:$TAG-cpu-ubuntu-22.04-arm
163+
docker buildx imagetools create -t $R:$TAG-gpu $R:$TAG-gpu-ubuntu-22.04 $R:$TAG-gpu-ubuntu-22.04-arm
164+
done
136165
137166
- name: Update latest tags
138167
if: github.event_name == 'release'
139168
env:
140169
TAG: ${{ needs.Container.outputs.tag }}
141-
REGISTRY: ${{ secrets.DOCKERHUB_USERNAME }}/mfc
170+
DH: ${{ secrets.DOCKERHUB_USERNAME }}/mfc
171+
GH: ghcr.io/${{ github.repository_owner }}/mfc
142172
run: |
143-
docker buildx imagetools create -t $REGISTRY:latest-cpu $REGISTRY:$TAG-cpu-ubuntu-22.04 $REGISTRY:$TAG-cpu-ubuntu-22.04-arm
144-
docker buildx imagetools create -t $REGISTRY:latest-gpu $REGISTRY:$TAG-gpu-ubuntu-22.04 $REGISTRY:$TAG-gpu-ubuntu-22.04-arm
173+
for R in "$DH" "$GH"; do
174+
docker buildx imagetools create -t $R:latest-cpu $R:$TAG-cpu-ubuntu-22.04 $R:$TAG-cpu-ubuntu-22.04-arm
175+
docker buildx imagetools create -t $R:latest-gpu $R:$TAG-gpu-ubuntu-22.04 $R:$TAG-gpu-ubuntu-22.04-arm
176+
done

0 commit comments

Comments
 (0)