Skip to content

Commit 2ae18fb

Browse files
authored
chore: Split builds between ARM and AMD64 (#409)
* add build matrix * add merge job * do not wait for test * retry * retry * fix build step * retry * retry * fix merge runner * retry * retry * cleanup * add requirement * update publish job * turn cache off * turn cache on
1 parent 1621815 commit 2ae18fb

File tree

2 files changed

+189
-72
lines changed

2 files changed

+189
-72
lines changed

.github/workflows/ci.yaml

Lines changed: 103 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
env:
1010
GOPATH: /home/runner/go/
1111
GOPROXY: "https://proxy.golang.org"
12+
REGISTRY_IMAGE: pluralsh/deployment-operator
1213
jobs:
1314
build:
1415
name: Build
@@ -42,59 +43,114 @@ jobs:
4243
- uses: golangci/golangci-lint-action@v6
4344
with:
4445
version: v1.63.4
45-
publish:
46-
name: Build and push Agent container
47-
runs-on: ubuntu-20.04
48-
needs:
49-
- test
46+
build-image:
47+
name: Build image
48+
needs: [build, test]
5049
permissions:
5150
contents: 'read'
5251
id-token: 'write'
5352
packages: 'write'
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
platforms:
57+
- platform: linux/amd64
58+
runner: ubuntu-24.04
59+
- platform: linux/arm64
60+
runner: ubuntu-24.04-arm
61+
runs-on: ${{ matrix.platforms.runner }}
5462
steps:
55-
- name: Checkout
56-
uses: actions/checkout@v4
57-
with:
58-
fetch-depth: 0
59-
- name: Docker meta
60-
id: meta
61-
uses: docker/metadata-action@v5
62-
with:
63-
# list of Docker images to use as base name for tags
64-
images: |
65-
ghcr.io/pluralsh/deployment-operator
66-
docker.io/pluralsh/deployment-operator
67-
# generate Docker tags based on the following events/attributes
68-
tags: |
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
with:
66+
fetch-depth: 0
67+
- name: Prepare
68+
run: |
69+
platform=${{ matrix.platforms.platform }}
70+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
71+
- name: Docker meta
72+
id: meta
73+
uses: docker/metadata-action@v5
74+
with:
75+
images: ${{ env.REGISTRY_IMAGE }}
76+
- name: Set up QEMU
77+
uses: docker/setup-qemu-action@v3
78+
- name: Set up Docker Buildx
79+
uses: docker/setup-buildx-action@v3
80+
- name: Login to Docker Hub
81+
uses: docker/login-action@v3
82+
with:
83+
username: mjgpluralsh
84+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
85+
- name: Build and push by digest
86+
id: build
87+
uses: docker/build-push-action@v6
88+
with:
89+
context: "."
90+
file: "./Dockerfile"
91+
tags: ${{ env.REGISTRY_IMAGE }}
92+
labels: ${{ steps.meta.outputs.labels }}
93+
platforms: ${{ matrix.platforms.platform }}
94+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
95+
cache-from: type=gha
96+
cache-to: type=gha,mode=max
97+
build-args: |
98+
GIT_COMMIT=${{ github.sha }}
99+
- name: Export digest
100+
run: |
101+
mkdir -p ${{ runner.temp }}/digests
102+
digest="${{ steps.build.outputs.digest }}"
103+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
104+
- name: Upload digest
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: digests-${{ env.PLATFORM_PAIR }}
108+
path: ${{ runner.temp }}/digests/*
109+
if-no-files-found: error
110+
retention-days: 1
111+
publish-image:
112+
name: Publish image
113+
needs: [build-image]
114+
strategy:
115+
fail-fast: false
116+
matrix:
117+
images: [ "ghcr.io/pluralsh/deployment-operator", "docker.io/pluralsh/deployment-operator" ]
118+
runs-on: ubuntu-latest
119+
steps:
120+
- name: Download digests
121+
uses: actions/download-artifact@v4
122+
with:
123+
path: ${{ runner.temp }}/digests
124+
pattern: digests-*
125+
merge-multiple: true
126+
- name: Login to GHCR
127+
uses: docker/login-action@v3
128+
with:
129+
registry: ghcr.io
130+
username: ${{ github.repository_owner }}
131+
password: ${{ secrets.GITHUB_TOKEN }}
132+
- name: Login to Docker Hub
133+
uses: docker/login-action@v3
134+
with:
135+
username: mjgpluralsh
136+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
137+
- name: Set up Docker Buildx
138+
uses: docker/setup-buildx-action@v3
139+
- name: Docker meta
140+
id: meta
141+
uses: docker/metadata-action@v5
142+
with:
143+
images: ${{ matrix.images }}
144+
tags: |
69145
type=sha
70146
type=ref,event=pr
71147
type=ref,event=branch
72148
type=semver,pattern={{version}},value=${{ needs.prepare.outputs.new_release_version }}
73-
- name: Set up QEMU
74-
uses: docker/setup-qemu-action@v3
75-
- name: Set up Docker Buildx
76-
uses: docker/setup-buildx-action@v3
77-
- name: Login to GHCR
78-
uses: docker/login-action@v3
79-
with:
80-
registry: ghcr.io
81-
username: ${{ github.repository_owner }}
82-
password: ${{ secrets.GITHUB_TOKEN }}
83-
- name: Login to Docker
84-
uses: docker/login-action@v3
85-
with:
86-
username: mjgpluralsh
87-
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
88-
- name: Build and push
89-
uses: docker/build-push-action@v5
90-
with:
91-
context: "."
92-
file: "./Dockerfile"
93-
push: true
94-
tags: ${{ steps.meta.outputs.tags }}
95-
labels: ${{ steps.meta.outputs.labels }}
96-
platforms: linux/amd64,linux/arm64
97-
cache-from: type=gha
98-
cache-to: type=gha,mode=max
99-
build-args: |
100-
GIT_COMMIT=${{ github.sha }}
149+
- name: Create manifest list and push
150+
working-directory: ${{ runner.temp }}/digests
151+
run: |
152+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
153+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
154+
- name: Inspect image
155+
run: |
156+
docker buildx imagetools inspect ${{ matrix.images }}:${{ steps.meta.outputs.version }}

.github/workflows/publish.yaml

Lines changed: 86 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
env:
99
GOPATH: /home/runner/go/
1010
GOPROXY: "https://proxy.golang.org"
11-
11+
REGISTRY_IMAGE: pluralsh/deployment-operator
1212
jobs:
1313
test:
1414
name: Unit test
@@ -20,30 +20,36 @@ jobs:
2020
go-version-file: go.mod
2121
check-latest: true
2222
- run: PATH=$PATH:$GOPATH/bin make test
23-
publish-docker:
24-
name: Build and push agent container
25-
runs-on: ubuntu-20.04
23+
build-image:
24+
name: Build image
2625
needs: [test]
2726
permissions:
2827
contents: 'read'
2928
id-token: 'write'
3029
packages: 'write'
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
platforms:
34+
- platform: linux/amd64
35+
runner: ubuntu-24.04
36+
- platform: linux/arm64
37+
runner: ubuntu-24.04-arm
38+
runs-on: ${{ matrix.platforms.runner }}
3139
steps:
3240
- name: Checkout
3341
uses: actions/checkout@v4
3442
with:
3543
fetch-depth: 0
44+
- name: Prepare
45+
run: |
46+
platform=${{ matrix.platforms.platform }}
47+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
3648
- name: Docker meta
3749
id: meta
3850
uses: docker/metadata-action@v5
3951
with:
40-
# list of Docker images to use as base name for tags
41-
images: |
42-
ghcr.io/pluralsh/deployment-operator
43-
docker.io/pluralsh/deployment-operator
44-
# generate Docker tags based on the following events/attributes
45-
tags: |
46-
type=semver,pattern={{version}}
52+
images: ${{ env.REGISTRY_IMAGE }}
4753
- name: Set up QEMU
4854
uses: docker/setup-qemu-action@v3
4955
- name: Set up Docker Buildx
@@ -59,31 +65,86 @@ jobs:
5965
with:
6066
username: mjgpluralsh
6167
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
62-
- name: Build and push
63-
uses: docker/build-push-action@v5
68+
- name: Build and push by digest
69+
id: build
70+
uses: docker/build-push-action@v6
6471
with:
6572
context: "."
6673
file: "./Dockerfile"
67-
push: true
68-
tags: ${{ steps.meta.outputs.tags }}
74+
tags: ${{ env.REGISTRY_IMAGE }}
6975
labels: ${{ steps.meta.outputs.labels }}
70-
platforms: linux/amd64,linux/arm64
76+
platforms: ${{ matrix.platforms.platform }}
77+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
7178
cache-from: type=gha
7279
cache-to: type=gha,mode=max
7380
build-args: |
7481
GIT_COMMIT=${{ github.sha }}
75-
- name: slack webhook
76-
uses: 8398a7/action-slack@v3
82+
- name: Export digest
83+
run: |
84+
mkdir -p ${{ runner.temp }}/digests
85+
digest="${{ steps.build.outputs.digest }}"
86+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
87+
- name: Upload digest
88+
uses: actions/upload-artifact@v4
7789
with:
78-
status: ${{ job.status }}
79-
fields: workflow,job,repo,message,commit,author
80-
env:
81-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required
82-
if: always()
90+
name: digests-${{ env.PLATFORM_PAIR }}
91+
path: ${{ runner.temp }}/digests/*
92+
if-no-files-found: error
93+
retention-days: 1
94+
publish-image:
95+
name: Publish image
96+
needs: [build-image]
97+
strategy:
98+
fail-fast: false
99+
matrix:
100+
images: [ "ghcr.io/pluralsh/deployment-operator", "docker.io/pluralsh/deployment-operator" ]
101+
runs-on: ubuntu-latest
102+
steps:
103+
- name: Download digests
104+
uses: actions/download-artifact@v4
105+
with:
106+
path: ${{ runner.temp }}/digests
107+
pattern: digests-*
108+
merge-multiple: true
109+
- name: Login to GHCR
110+
uses: docker/login-action@v3
111+
with:
112+
registry: ghcr.io
113+
username: ${{ github.repository_owner }}
114+
password: ${{ secrets.GITHUB_TOKEN }}
115+
- name: Login to Docker Hub
116+
uses: docker/login-action@v3
117+
with:
118+
username: mjgpluralsh
119+
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
120+
- name: Set up Docker Buildx
121+
uses: docker/setup-buildx-action@v3
122+
- name: Docker meta
123+
id: meta
124+
uses: docker/metadata-action@v5
125+
with:
126+
images: ${{ matrix.images }}
127+
tags: type=semver,pattern={{version}}
128+
- name: Create manifest list and push
129+
working-directory: ${{ runner.temp }}/digests
130+
run: |
131+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
132+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
133+
- name: Inspect image
134+
run: |
135+
docker buildx imagetools inspect ${{ matrix.images }}:${{ steps.meta.outputs.version }}
136+
- name: slack webhook
137+
uses: 8398a7/action-slack@v3
138+
with:
139+
status: ${{ job.status }}
140+
fields: workflow,job,repo,message,commit,author
141+
env:
142+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required
143+
if: always()
83144
bump:
84145
name: Bump Chart Version
85-
runs-on: ubuntu-20.04
86-
needs: [publish-docker]
146+
runs-on: ubuntu-latest
147+
needs: [publish-image]
87148
permissions:
88149
contents: write
89150
discussions: write

0 commit comments

Comments
 (0)