Skip to content

Commit 3e8d3d9

Browse files
Merge pull request #47 from credativ/arm-build-natively
Build arm64 image on a native arm runner
2 parents af6d143 + db66f0c commit 3e8d3d9

File tree

5 files changed

+161
-143
lines changed

5 files changed

+161
-143
lines changed

.github/workflows/build-image.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# loosely based on https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image-name:
7+
type: string
8+
required: true
9+
dockerfile:
10+
type: string
11+
required: false
12+
default: Dockerfile
13+
context:
14+
type: string
15+
required: false
16+
default: .
17+
build-args:
18+
type: string
19+
required: false
20+
default: ""
21+
secrets-github-token-name:
22+
type: string
23+
required: false
24+
default: "GITHUB_TOKEN"
25+
description: "Make the GITHUB_TOKEN secret available under this name during the build"
26+
27+
env:
28+
REGISTRY: ghcr.io
29+
REGISTRY_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ inputs.image-name }}
30+
31+
jobs:
32+
build:
33+
strategy:
34+
matrix:
35+
build:
36+
- arch: x86_64
37+
runner: ubuntu-24.04
38+
- arch: arm64
39+
runner: ubuntu-24.04-arm
40+
permissions:
41+
contents: read
42+
packages: write
43+
runs-on: ${{ matrix.build.runner }}
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
48+
- name: Log in to the container registry
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Extract metadata (tags, labels) for Docker
59+
id: meta
60+
uses: docker/metadata-action@v5
61+
62+
- name: Build and push Docker image
63+
id: build
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: ${{ inputs.context }}
67+
file: ${{ inputs.dockerfile }}
68+
build-args: ${{ inputs.build-args }}
69+
secrets: ${{ inputs.secrets-github-token-name }}=${{ secrets.GITHUB_TOKEN }}
70+
tags: ${{ env.REGISTRY_IMAGE }}
71+
labels: ${{ steps.meta.outputs.labels }}
72+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
73+
74+
- name: Export digest
75+
run: |
76+
mkdir -p ${{ runner.temp }}/digests
77+
digest="${{ steps.build.outputs.digest }}"
78+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
79+
80+
- name: Upload digest
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: digests___${{ inputs.image-name }}___${{ matrix.build.arch }}
84+
path: ${{ runner.temp }}/digests/*
85+
if-no-files-found: error
86+
retention-days: 1
87+
88+
merge:
89+
needs:
90+
- build
91+
permissions:
92+
packages: write
93+
runs-on: ubuntu-24.04
94+
steps:
95+
- name: Download image digests
96+
uses: actions/download-artifact@v4
97+
with:
98+
path: ${{ runner.temp }}/digests
99+
pattern: digests___${{ inputs.image-name }}___*
100+
merge-multiple: true
101+
102+
- name: Log in to the container registry
103+
uses: docker/login-action@v3
104+
with:
105+
registry: ${{ env.REGISTRY }}
106+
username: ${{ github.actor }}
107+
password: ${{ secrets.GITHUB_TOKEN }}
108+
109+
- name: Set up Docker Buildx
110+
uses: docker/setup-buildx-action@v3
111+
112+
- name: Extract metadata (tags, labels) for Docker
113+
id: meta
114+
uses: docker/metadata-action@v5
115+
with:
116+
images: ${{ env.REGISTRY_IMAGE }}
117+
118+
- name: Create manifest list and push
119+
working-directory: ${{ runner.temp }}/digests
120+
run: |
121+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
122+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
123+
124+
- name: Inspect image
125+
run: |
126+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

.github/workflows/container-image.yml

Lines changed: 25 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8,90 +8,30 @@ on:
88
- "v*"
99
pull_request:
1010

11-
env:
12-
REGISTRY: ghcr.io
11+
permissions:
12+
contents: read
13+
packages: write
1314

1415
jobs:
15-
build-and-push-vali:
16-
runs-on: ubuntu-22.04
17-
permissions:
18-
contents: read
19-
packages: write
20-
env:
21-
IMAGE_NAME: vali
22-
steps:
23-
- name: Checkout repository
24-
uses: actions/checkout@v3
25-
26-
- name: Log in to the container registry
27-
uses: docker/login-action@v2
28-
with:
29-
registry: ${{ env.REGISTRY }}
30-
username: ${{ github.actor }}
31-
password: ${{ secrets.GITHUB_TOKEN }}
32-
33-
- name: Extract metadata (tags, labels) for Docker
34-
id: meta
35-
uses: docker/metadata-action@v4
36-
with:
37-
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
38-
39-
- name: Set up QEMU
40-
uses: docker/setup-qemu-action@v2
41-
42-
- name: Set up Docker Buildx
43-
uses: docker/setup-buildx-action@v2
44-
45-
- name: Build and push Docker image
46-
uses: docker/build-push-action@v3
47-
with:
48-
context: .
49-
file: cmd/vali/Dockerfile
50-
build-args: |
51-
TOUCH_PROTOS=1
52-
push: true
53-
tags: ${{ steps.meta.outputs.tags }}
54-
labels: ${{ steps.meta.outputs.labels }}
55-
platforms: linux/amd64,linux/arm64
56-
57-
build-and-push-valitail:
58-
runs-on: ubuntu-22.04
59-
permissions:
60-
contents: read
61-
packages: write
62-
env:
63-
IMAGE_NAME: valitail
64-
steps:
65-
- name: Checkout repository
66-
uses: actions/checkout@v3
67-
68-
- name: Log in to the container registry
69-
uses: docker/login-action@v2
70-
with:
71-
registry: ${{ env.REGISTRY }}
72-
username: ${{ github.actor }}
73-
password: ${{ secrets.GITHUB_TOKEN }}
74-
75-
- name: Extract metadata (tags, labels) for Docker
76-
id: meta
77-
uses: docker/metadata-action@v4
78-
with:
79-
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
80-
81-
- name: Set up QEMU
82-
uses: docker/setup-qemu-action@v2
83-
84-
- name: Set up Docker Buildx
85-
uses: docker/setup-buildx-action@v2
86-
87-
- name: Build and push Docker image
88-
uses: docker/build-push-action@v3
89-
with:
90-
context: .
91-
file: cmd/valitail/Dockerfile
92-
build-args: |
93-
TOUCH_PROTOS=1
94-
push: true
95-
tags: ${{ steps.meta.outputs.tags }}
96-
labels: ${{ steps.meta.outputs.labels }}
97-
platforms: linux/amd64,linux/arm64
16+
vali:
17+
uses: ./.github/workflows/build-image.yml
18+
with:
19+
image-name: vali
20+
dockerfile: cmd/vali/Dockerfile
21+
build-args: |
22+
TOUCH_PROTOS=1
23+
24+
valitail:
25+
uses: ./.github/workflows/build-image.yml
26+
with:
27+
image-name: valitail
28+
dockerfile: cmd/valitail/Dockerfile
29+
build-args: |
30+
TOUCH_PROTOS=1
31+
32+
vali-build-image:
33+
uses: ./.github/workflows/build-image.yml
34+
with:
35+
image-name: vali-build-image
36+
dockerfile: vali-build-image/Dockerfile
37+
context: vali-build-image

.github/workflows/release.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ on:
1010

1111
jobs:
1212
logcli:
13-
runs-on: ubuntu-22.04
1413
permissions:
1514
contents: read
1615
strategy:
1716
matrix:
18-
arch: [amd64, arm64]
17+
build:
18+
- arch: amd64
19+
runner: ubuntu-22.04
20+
- arch: arm64
21+
runner: ubuntu-22.04-arm
22+
runs-on: ${{ matrix.build.runner }}
1923
steps:
2024
- name: Checkout repository
2125
uses: actions/checkout@v3
@@ -40,17 +44,15 @@ jobs:
4044

4145
- name: Build logcli
4246
run: make BUILD_IN_CONTAINER=false logcli
43-
env:
44-
GOARCH: ${{ matrix.arch }}
4547

4648
- name: Zip logcli
47-
run: zip --junk-paths logcli_${{ matrix.arch }}.zip cmd/logcli/logcli
49+
run: zip --junk-paths logcli_${{ matrix.build.arch }}.zip cmd/logcli/logcli
4850

4951
- name: Upload logcli as artifact
5052
uses: actions/upload-artifact@v4
5153
with:
52-
name: logcli_${{ matrix.arch }}
53-
path: logcli_${{ matrix.arch }}.zip
54+
name: logcli_${{ matrix.build.arch }}
55+
path: logcli_${{ matrix.build.arch }}.zip
5456
retention-days: 3
5557

5658
release:

.github/workflows/vali-build-image.yml

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

vali-build-image/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ COPY --from=faillint /go/bin/faillint /usr/bin/faillint
4040
# Install some necessary dependencies.
4141
RUN go install github.com/golang/protobuf/protoc-gen-go@v1.3.0 && \
4242
go install github.com/gogo/protobuf/protoc-gen-gogoslick@v1.2.1 && \
43-
go install github.com/go-delve/delve/cmd/dlv@v1.3.2 && \
43+
go install github.com/go-delve/delve/cmd/dlv@v1.24.2 && \
4444
# Due to the lack of a proper release tag, we use the commit hash of
4545
# https://github.com/golang/tools/releases v0.1.7
4646
go install golang.org/x/tools/cmd/goyacc@58d531046acdc757f177387bc1725bfa79895d69 && \

0 commit comments

Comments
 (0)