Skip to content

Commit cc4d183

Browse files
committed
ci: build docker image on native amd64/arm64 runners
Build each platform on its own runner (ubuntu-24.04 / ubuntu-24.04-arm) and push by digest, then merge into the multi-arch manifest with the same metadata-action tags as before, instead of emulating arm64. Add a per-arch GHA layer cache, and build on pushes to master (the default branch), which the main* filter never matched.
1 parent 2356b8e commit cc4d183

1 file changed

Lines changed: 79 additions & 14 deletions

File tree

‎.github/workflows/build_push.yml‎

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,92 @@ on:
22
workflow_dispatch:
33
push:
44
branches:
5+
- master
56
- main*
67
tags:
78
- 'v*'
89
name: Build and Publish Docker Image
10+
env:
11+
IMAGE: ghcr.io/obolnetwork/goteth
912
jobs:
13+
# One native runner per arch (no QEMU emulation), each pushing its image by
14+
# digest; merge then creates the multi-arch manifest with the usual tags.
1015
build-docker:
11-
runs-on: ubuntu-latest
12-
name: Build Docker Image
16+
name: Build Docker Image (${{ matrix.platform }})
17+
strategy:
18+
matrix:
19+
include:
20+
- platform: linux/amd64
21+
arch: amd64
22+
runner: ubuntu-24.04
23+
- platform: linux/arm64
24+
arch: arm64
25+
runner: ubuntu-24.04-arm
26+
runs-on: ${{ matrix.runner }}
1327
steps:
1428
- uses: actions/checkout@v3
1529
with:
1630
lfs: 'true'
1731
fetch-depth: 0
1832
submodules: 'recursive'
19-
- uses: docker/setup-buildx-action@v2
33+
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
34+
35+
- name: Login to Github container registry
36+
uses: docker/login-action@v2
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Build and push by digest
43+
id: build
44+
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
45+
with:
46+
context: .
47+
platforms: ${{ matrix.platform }}
48+
build-args: |
49+
GITHUB_SHA=${{ github.sha }}
50+
GO_BUILD_FLAG=${{ env.GO_BUILD_FLAG }}
51+
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
52+
# No attestation manifests (they show as unknown/unknown arch in ghcr).
53+
provenance: false
54+
cache-from: type=gha,scope=goteth-${{ matrix.arch }}
55+
cache-to: type=gha,scope=goteth-${{ matrix.arch }},mode=max
56+
57+
- name: Export digest
58+
run: |
59+
mkdir -p "${RUNNER_TEMP}/digests"
60+
digest="${{ steps.build.outputs.digest }}"
61+
touch "${RUNNER_TEMP}/digests/${digest#sha256:}"
62+
63+
- name: Upload digest
64+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
65+
with:
66+
name: digests-${{ matrix.arch }}
67+
path: ${{ runner.temp }}/digests/*
68+
if-no-files-found: error
69+
retention-days: 1
70+
71+
merge:
72+
needs: build-docker
73+
runs-on: ubuntu-24.04
74+
name: Merge Docker Manifests
75+
steps:
76+
- name: Download digests
77+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
2078
with:
21-
driver-opts: "image=moby/buildkit:v0.10.5" # avoid unknown/unknown arch in ghcr
79+
path: ${{ runner.temp }}/digests
80+
pattern: digests-*
81+
merge-multiple: true
82+
83+
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
2284

2385
- name: Define docker image meta data tags
2486
id: meta
2587
uses: docker/metadata-action@v4
2688
with:
2789
images: |
28-
ghcr.io/obolnetwork/goteth
90+
${{ env.IMAGE }}
2991
tags: |
3092
# Tag "git short sha" on all git events
3193
type=sha,prefix=
@@ -46,14 +108,17 @@ jobs:
46108
username: ${{ github.actor }}
47109
password: ${{ secrets.GITHUB_TOKEN }}
48110

49-
- uses: docker/build-push-action@v4
50-
with:
51-
context: .
52-
platforms: linux/amd64,linux/arm64
53-
push: true
54-
build-args: |
55-
GITHUB_SHA=${{ github.sha }}
56-
GO_BUILD_FLAG=${{ env.GO_BUILD_FLAG }}
57-
tags: ${{ steps.meta.outputs.tags }}
111+
- name: Create multi-arch manifest and push
112+
working-directory: ${{ runner.temp }}/digests
113+
env:
114+
TAGS: ${{ steps.meta.outputs.tags }}
115+
run: |
116+
tags=()
117+
while read -r tag; do
118+
if [[ -n "${tag}" ]]; then tags+=(-t "${tag}"); fi
119+
done <<< "${TAGS}"
120+
# shellcheck disable=SC2046 # one source arg per digest file
121+
docker buildx imagetools create "${tags[@]}" $(printf "${IMAGE}@sha256:%s " *)
122+
docker buildx imagetools inspect "${tags[1]}"
58123
59124
# Bring back the branch

0 commit comments

Comments
 (0)