Skip to content

Commit 090ba12

Browse files
authored
Merge pull request #9 from ObolNetwork/ci/native-arm
ci: build docker image on native amd64/arm64 runners
2 parents 2356b8e + de02f61 commit 090ba12

1 file changed

Lines changed: 87 additions & 14 deletions

File tree

‎.github/workflows/build_push.yml‎

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

2393
- name: Define docker image meta data tags
2494
id: meta
2595
uses: docker/metadata-action@v4
2696
with:
2797
images: |
28-
ghcr.io/obolnetwork/goteth
98+
${{ env.IMAGE }}
2999
tags: |
30100
# Tag "git short sha" on all git events
31101
type=sha,prefix=
@@ -46,14 +116,17 @@ jobs:
46116
username: ${{ github.actor }}
47117
password: ${{ secrets.GITHUB_TOKEN }}
48118

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 }}
119+
- name: Create multi-arch manifest and push
120+
working-directory: ${{ runner.temp }}/digests
121+
env:
122+
TAGS: ${{ steps.meta.outputs.tags }}
123+
run: |
124+
tags=()
125+
while read -r tag; do
126+
if [[ -n "${tag}" ]]; then tags+=(-t "${tag}"); fi
127+
done <<< "${TAGS}"
128+
# shellcheck disable=SC2046 # one source arg per digest file
129+
docker buildx imagetools create "${tags[@]}" $(printf "${IMAGE}@sha256:%s " *)
130+
docker buildx imagetools inspect "${tags[1]}"
58131
59132
# Bring back the branch

0 commit comments

Comments
 (0)