Skip to content

Commit f2fd67f

Browse files
authored
Merge pull request #27 from uyjulian/ci_fix_multi_arch_docker
Fix multi-arch docker CI build
2 parents 1cea0ff + 511d0c1 commit f2fd67f

File tree

2 files changed

+115
-37
lines changed

2 files changed

+115
-37
lines changed

.github/workflows/docker.yml

Lines changed: 115 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,106 @@ on:
1717

1818
jobs:
1919
build:
20-
env:
21-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
22-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
23-
outputs:
24-
dest-repo: ${{ steps.dest-repo.outputs.DEST_REPO }}
2520
strategy:
2621
matrix:
27-
runs-on:
28-
- ubuntu-latest
29-
- ubuntu-24.04-arm
30-
runs-on: ${{ matrix.runs-on }}
22+
platform:
23+
- runs-on: ubuntu-latest
24+
container-platform: linux/amd64
25+
- runs-on: ubuntu-24.04-arm
26+
container-platform: linux/arm64
27+
runs-on: ${{ matrix.platform.runs-on }}
3128
timeout-minutes: 180
3229

3330
steps:
3431
- name: Checkout repository
3532
uses: actions/checkout@v4
3633

34+
- name: Prepare
35+
run: |
36+
platform=${{ matrix.platform.container-platform }}
37+
printf 'PLATFORM_PAIR=%s\n' "${platform//\//-}" >> $GITHUB_ENV
38+
39+
- name: Login to Github Container Registry
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Prepare additional environment variables from repo
47+
run: if test -f ./config/ci-docker-env.ini; then cat ./config/ci-docker-env.ini | sed -e 's/$REPOSITORY_OWNER/'"${{ github.repository_owner }}"'/g;s/$DOCKER_TAG/'"${{ env.DOCKER_TAG }}"'/g' >> $GITHUB_ENV; fi
48+
3749
- name: Extract DOCKER_TAG using tag name
38-
if: startsWith(github.ref, 'refs/tags/')
50+
if: env.BUILD_ARGS_LIST != null
3951
run: |
40-
printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
52+
printf 'BUILD_ARGS_LIST_NEWLINES<<EOF\n%s\nEOF\n' "${{ env.BUILD_ARGS_LIST }}" | tr ' ' $'\n' >> $GITHUB_ENV
4153
42-
- name: Use default DOCKER_TAG
43-
if: startsWith(github.ref, 'refs/tags/') != true
54+
- name: Docker meta
55+
id: meta
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ghcr.io/${{ github.repository }}
59+
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v3
62+
63+
- name: Build and Push to container registry
64+
id: build
65+
uses: docker/build-push-action@v6
66+
with:
67+
platforms: ${{ matrix.platform.container-platform }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
tags: ghcr.io/${{ github.repository }}
70+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
71+
build-args: ${{ env.BUILD_ARGS_LIST_NEWLINES }}
72+
73+
- name: Export digest
4474
run: |
45-
printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV
75+
mkdir -p ${{ runner.temp }}/digests
76+
digest="${{ steps.build.outputs.digest }}"
77+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
78+
79+
- name: Upload digest
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: digests-${{ env.PLATFORM_PAIR }}
83+
path: ${{ runner.temp }}/digests/*
84+
if-no-files-found: error
85+
retention-days: 1
86+
87+
merge:
88+
needs:
89+
- build
90+
runs-on: ubuntu-latest
91+
timeout-minutes: 20
92+
env:
93+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
94+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
95+
outputs:
96+
dest-repo: ${{ steps.dest-repo.outputs.DEST_REPO }}
97+
98+
steps:
99+
- name: Checkout repository
100+
uses: actions/checkout@v4
101+
102+
- name: Install Ubuntu packages
103+
run: |
104+
sudo apt-get -y update
105+
sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install jq
106+
107+
- name: Download digests
108+
uses: actions/download-artifact@v4
109+
with:
110+
path: ${{ runner.temp }}/digests
111+
pattern: digests-*
112+
merge-multiple: true
46113

47114
- name: Login to DockerHub
48115
uses: docker/login-action@v3
49116
if: env.DOCKER_USERNAME != null
50117
with:
51-
username: ${{ secrets.DOCKER_USERNAME }}
52-
password: ${{ secrets.DOCKER_PASSWORD }}
118+
username: ${{ env.DOCKER_USERNAME }}
119+
password: ${{ env.DOCKER_PASSWORD }}
53120

54121
- name: Login to Github Container Registry
55122
uses: docker/login-action@v3
@@ -58,37 +125,53 @@ jobs:
58125
username: ${{ github.actor }}
59126
password: ${{ secrets.GITHUB_TOKEN }}
60127

128+
- name: Extract DOCKER_TAG using tag name
129+
if: startsWith(github.ref, 'refs/tags/')
130+
run: |
131+
printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
132+
133+
- name: Use default DOCKER_TAG
134+
if: startsWith(github.ref, 'refs/tags/') != true
135+
run: |
136+
printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV
137+
61138
- name: Set docker tag list to include DockerHub if credentials available
62139
if: env.DOCKER_USERNAME != null
63140
run: |
64-
printf 'DOCKER_TAG_LIST=%s\n' "ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }},${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
141+
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}"$'\n'"${{ github.repository }}" >> $GITHUB_ENV
65142
66143
- name: Set docker tag list to not include DockerHub if credentials not available
67144
if: env.DOCKER_USERNAME == null
68145
run: |
69-
printf 'DOCKER_TAG_LIST=%s\n' "ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
146+
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}" >> $GITHUB_ENV
70147
71-
- name: Prepare additional environment variables from repo
72-
run: if test -f ./config/ci-docker-env.ini; then cat ./config/ci-docker-env.ini | sed -e 's/$REPOSITORY_OWNER/'"${{ github.repository_owner }}"'/g;s/$DOCKER_TAG/'"${{ env.DOCKER_TAG }}"'/g' >> $GITHUB_ENV; fi
73-
74-
- name: Build and Push to container registry
75-
uses: docker/build-push-action@v5
148+
- name: Docker meta
149+
id: meta
150+
uses: docker/metadata-action@v5
76151
with:
77-
push: true
78-
tags: ${{ env.DOCKER_TAG_LIST }}
79-
build-args: |
80-
BASE_DOCKER_IMAGE
81-
BASE_DOCKER_DVP_IMAGE
82-
BASE_DOCKER_IOP_IMAGE
83-
BASE_DOCKER_EE_IMAGE
152+
images: ${{ env.DOCKER_CONTAINER_LIST }}
153+
tags: |
154+
type=raw,value=${{ env.DOCKER_TAG }}
155+
156+
- name: Set up Docker Buildx
157+
uses: docker/setup-buildx-action@v3
158+
159+
- name: Create manifest list and push
160+
working-directory: ${{ runner.temp }}/digests
161+
run: |
162+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
163+
164+
- name: Inspect image
165+
run: |
166+
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}
84167
85168
- name: Gather information for repository dispatch
86169
id: dest-repo
87170
run: if test -f ./config/repository-dispatch.ini; then cat ./config/repository-dispatch.ini >> $GITHUB_OUTPUT; fi
88171

89172
perform-repository-dispatch:
90173
needs:
91-
- build
174+
- merge
92175
runs-on: ubuntu-latest
93176
container:
94177
image: ubuntu:20.04
@@ -98,7 +181,7 @@ jobs:
98181
DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
99182
strategy:
100183
matrix:
101-
dest-repo: ${{ fromJson(needs.build.outputs.dest-repo) }}
184+
dest-repo: ${{ fromJson(needs.merge.outputs.dest-repo) }}
102185

103186
steps:
104187
- name: Gather environment variables (normal)

config/ci-docker-env.ini

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)