Skip to content

Commit 60d6d8c

Browse files
committed
Migrate multi-arch Docker builds to GitHub Actions
Signed-off-by: Krishna Mewara <krishnamewara841@gmail.com>
1 parent 1df6b70 commit 60d6d8c

File tree

1 file changed

+260
-0
lines changed

1 file changed

+260
-0
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
name: docker multi-arch build publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '*'
9+
pull_request:
10+
branches:
11+
- main
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
env:
19+
registry: docker.io
20+
IMAGE_NAME: hyperledger/besu
21+
22+
jobs:
23+
24+
hadolint:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
30+
- name: Lint Dockerfile
31+
run: docker run --rm -i hadolint/hadolint < docker/Dockerfile
32+
33+
build-and-test:
34+
needs: hadolint
35+
runs-on: ${{ matrix.platform }}
36+
permissions:
37+
contents: read
38+
outputs:
39+
version: ${{ steps.meta.outputs.version }}
40+
push: ${{ steps.meta.outputs.push }}
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
include:
45+
- platform: ubuntu-latest
46+
arch: amd64
47+
- platform: besu-arm64
48+
arch: arm64
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
52+
53+
- name: Compute version and push flag
54+
id: meta
55+
run: |
56+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
57+
VERSION="${{ github.ref_name }}"
58+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
59+
VERSION="pr-${{ github.event.pull_request.number }}"
60+
else
61+
VERSION="$(date +'%y.%-m')-develop-${GITHUB_SHA::7}"
62+
fi
63+
PUSH=$([[ "${{ github.event_name }}" != "pull_request" ]] && echo "true" || echo "false")
64+
echo "version=$VERSION" >> $GITHUB_OUTPUT
65+
echo "push=$PUSH" >> $GITHUB_OUTPUT
66+
echo "build-date=$(date --utc --rfc-3339=seconds)" >> $GITHUB_OUTPUT
67+
echo "vcs-ref=${GITHUB_SHA}" >> $GITHUB_OUTPUT
68+
69+
- name: Set up Java
70+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
71+
with:
72+
distribution: temurin
73+
java-version: 21
74+
75+
- name: Set up Gradle
76+
uses: gradle/actions/setup-gradle@39e147cb9de83bb9910b8ef8bd7fff0ee20fcd6f # v6.0.1
77+
78+
- name: Stage Docker build context
79+
run: ./gradlew --no-daemon distDockerCopy
80+
81+
- name: Set up Docker Buildx
82+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
83+
84+
- name: Login to ${{ env.registry }}
85+
if: steps.meta.outputs.push == 'true'
86+
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
87+
with:
88+
registry: ${{ env.registry }}
89+
username: ${{ secrets.DOCKER_USER_RW }}
90+
password: ${{ secrets.DOCKER_PASSWORD_RW }}
91+
92+
- name: Build and load for testing
93+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
94+
env:
95+
DOCKER_BUILD_SUMMARY: false
96+
with:
97+
context: build/docker-besu
98+
load: true
99+
no-cache: true
100+
pull: true
101+
build-args: |
102+
VERSION=${{ steps.meta.outputs.version }}
103+
BUILD_DATE=${{ steps.meta.outputs.build-date }}
104+
VCS_REF=${{ steps.meta.outputs.vcs-ref }}
105+
tags: ${{ env.IMAGE_NAME }}:test-${{ matrix.arch }}
106+
cache-from: type=gha,scope=build-${{ matrix.arch }}
107+
cache-to: type=gha,mode=max,scope=build-${{ matrix.arch }}
108+
109+
- name: Download Goss binaries
110+
run: ./gradlew downloadGossBinaries
111+
112+
- name: Run Docker tests
113+
env:
114+
architecture: ${{ matrix.arch }}
115+
run: |
116+
mkdir -p docker/reports
117+
cd docker && ./test.sh ${{ env.IMAGE_NAME }}:test-${{ matrix.arch }}
118+
119+
- name: Test Summary
120+
if: always()
121+
run: |
122+
SUMMARY="<h2>Docker Test Summary (${{ matrix.arch }})</h2>\n"
123+
SUMMARY+="<details><summary><strong>Details</strong></summary>\n<pre><code>\n"
124+
SUMMARY+=$(cat ./docker/reports/*.xml 2>/dev/null || echo "No report found")
125+
SUMMARY+="\n</code></pre></details>\n"
126+
echo -e "$SUMMARY" >> $GITHUB_STEP_SUMMARY
127+
128+
- name: Build and push by digest
129+
id: push
130+
if: steps.meta.outputs.push == 'true'
131+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
132+
with:
133+
context: build/docker-besu
134+
platforms: linux/${{ matrix.arch }}
135+
no-cache: true
136+
pull: true
137+
build-args: |
138+
VERSION=${{ steps.meta.outputs.version }}
139+
BUILD_DATE=${{ steps.meta.outputs.build-date }}
140+
VCS_REF=${{ steps.meta.outputs.vcs-ref }}
141+
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
142+
cache-from: type=gha,scope=build-${{ matrix.arch }}
143+
144+
- name: Export digest
145+
if: steps.meta.outputs.push == 'true'
146+
run: |
147+
mkdir -p /tmp/digests
148+
digest="${{ steps.push.outputs.digest }}"
149+
touch "/tmp/digests/${digest#sha256:}"
150+
151+
- name: Upload digest artifact
152+
if: steps.meta.outputs.push == 'true'
153+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
154+
with:
155+
name: digests-${{ matrix.arch }}
156+
path: /tmp/digests/*
157+
if-no-files-found: error
158+
retention-days: 1
159+
160+
manifest:
161+
needs: build-and-test
162+
runs-on: ubuntu-latest
163+
if: github.event_name != 'pull_request'
164+
permissions:
165+
contents: read
166+
steps:
167+
- name: Checkout
168+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
169+
170+
- name: Download digests
171+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
172+
with:
173+
pattern: digests-*
174+
merge-multiple: true
175+
path: /tmp/digests
176+
177+
- name: Set up Docker Buildx
178+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
179+
180+
- name: Login to ${{ env.registry }}
181+
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
182+
with:
183+
registry: ${{ env.registry }}
184+
username: ${{ secrets.DOCKER_USER_RW }}
185+
password: ${{ secrets.DOCKER_PASSWORD_RW }}
186+
187+
- name: Compute manifest tags
188+
id: tags
189+
env:
190+
VERSION: ${{ needs.build-and-test.outputs.version }}
191+
run: |
192+
TAGS="-t ${{ env.IMAGE_NAME }}:${VERSION}"
193+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
194+
if [[ ! "${VERSION}" =~ -(RC|SNAPSHOT|alpha|beta) ]]; then
195+
SHORT="${VERSION%.*}"
196+
TAGS+=" -t ${{ env.IMAGE_NAME }}:${SHORT}"
197+
TAGS+=" -t ${{ env.IMAGE_NAME }}:latest"
198+
fi
199+
fi
200+
echo "tags=$TAGS" >> $GITHUB_OUTPUT
201+
202+
- name: Create and push multi-arch manifest
203+
env:
204+
VERSION: ${{ needs.build-and-test.outputs.version }}
205+
run: |
206+
docker buildx imagetools create \
207+
${{ steps.tags.outputs.tags }} \
208+
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' $(ls /tmp/digests/))
209+
210+
- name: Inspect manifest
211+
env:
212+
VERSION: ${{ needs.build-and-test.outputs.version }}
213+
run: docker buildx imagetools inspect "${{ env.IMAGE_NAME }}:${VERSION}"
214+
215+
verify:
216+
needs: [build-and-test, manifest]
217+
if: github.event_name != 'pull_request'
218+
permissions:
219+
contents: read
220+
strategy:
221+
fail-fast: false
222+
matrix:
223+
combination:
224+
- tag: ${{ needs.build-and-test.outputs.version }}
225+
platform: ''
226+
runner: ubuntu-latest
227+
- tag: ${{ needs.build-and-test.outputs.version }}
228+
platform: 'linux/amd64'
229+
runner: ubuntu-latest
230+
- tag: ${{ needs.build-and-test.outputs.version }}
231+
platform: ''
232+
runner: besu-arm64
233+
runs-on: ${{ matrix.combination.runner }}
234+
env:
235+
CONTAINER_NAME: besu-check
236+
steps:
237+
- name: Checkout
238+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
239+
with:
240+
sparse-checkout: '.github/workflows/BesuContainerVerify.sh'
241+
242+
- name: Start container
243+
run: |
244+
PLATFORM_OPT=""
245+
[[ -n "${{ matrix.combination.platform }}" ]] && \
246+
PLATFORM_OPT="--platform ${{ matrix.combination.platform }}"
247+
docker run -d $PLATFORM_OPT \
248+
--name ${{ env.CONTAINER_NAME }} \
249+
${{ env.IMAGE_NAME }}:${{ matrix.combination.tag }}
250+
251+
- name: Verify Besu container
252+
run: bash .github/workflows/BesuContainerVerify.sh
253+
env:
254+
TAG: ${{ matrix.combination.tag }}
255+
VERSION: ${{ needs.build-and-test.outputs.version }}
256+
CHECK_LATEST: false
257+
258+
- name: Stop container
259+
if: always()
260+
run: docker stop ${{ env.CONTAINER_NAME }} || true

0 commit comments

Comments
 (0)