Skip to content

Commit 74606aa

Browse files
committed
chore: use parallel multi-arch build
1 parent 944bc4a commit 74606aa

4 files changed

Lines changed: 109 additions & 39 deletions

File tree

.github/workflows/merge.yaml

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,51 @@ on:
55
- 'master'
66
- 'release-*'
77
jobs:
8-
merge_master:
9-
runs-on: ubuntu-latest
8+
prepare:
9+
runs-on: ubuntu-24.04
10+
outputs:
11+
branch: ${{ steps.extract_branch.outputs.branch }}
1012
steps:
11-
- name: Checkout
12-
uses: actions/checkout@v6
13-
with:
14-
fetch-depth: 0
1513
- name: Extract branch name
1614
shell: bash
1715
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
1816
id: extract_branch
19-
- name: Set up QEMU
20-
uses: docker/setup-qemu-action@v4
17+
18+
build:
19+
needs: prepare
20+
strategy:
21+
matrix:
22+
include:
23+
- arch: amd64
24+
runner: ubuntu-24.04
25+
- arch: arm64
26+
runner: ubuntu-24.04-arm
27+
runs-on: ${{ matrix.runner }}
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v6
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v4
33+
- name: Docker login
34+
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin
35+
- name: Build and push image
36+
run: make docker-push-arch
37+
env:
38+
ARCH: ${{ matrix.arch }}
39+
TAG: ${{ github.sha }}
40+
IMAGE_TAG: ${{ needs.prepare.outputs.branch }}
41+
42+
manifest:
43+
needs: [prepare, build]
44+
runs-on: ubuntu-24.04
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v6
2148
- name: Set up Docker Buildx
2249
uses: docker/setup-buildx-action@v4
2350
- name: Docker login
2451
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin
25-
- name: Make release
26-
run: make release
52+
- name: Create branch manifest
53+
run: make docker-manifest
2754
env:
28-
TAG: ${{ env.GITHUB_SHA }}
29-
IMAGE_TAG: ${{ steps.extract_branch.outputs.branch }}
55+
IMAGE_TAG: ${{ needs.prepare.outputs.branch }}

.github/workflows/pull-request.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
go-version: [1.25.x]
11-
platform: [ubuntu-latest]
11+
platform: [ubuntu-24.04, ubuntu-24.04-arm]
1212
runs-on: ${{ matrix.platform }}
1313
steps:
1414
# Checkout should always be before setup-go to ensure caching is working
@@ -20,12 +20,12 @@ jobs:
2020
go-version: ${{ matrix.go-version }}
2121
- name: Run unit tests
2222
run: make test
23+
2324
build-test:
2425
strategy:
2526
matrix:
2627
go-version: [1.25.x]
27-
platform: [ubuntu-latest]
28-
arch: [386, amd64, arm, arm64]
28+
platform: [ubuntu-24.04, ubuntu-24.04-arm]
2929
runs-on: ${{ matrix.platform }}
3030
steps:
3131
# Checkout should always be before setup-go to ensure caching is working
@@ -36,4 +36,4 @@ jobs:
3636
with:
3737
go-version: ${{ matrix.go-version }}
3838
- name: Building binary
39-
run: GOARCH=${{ matrix.arch }} make compile
39+
run: make compile

.github/workflows/release.yml

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,68 @@ on:
44
tags:
55
- '*'
66
jobs:
7-
release:
8-
runs-on: ubuntu-latest
7+
prepare:
8+
runs-on: ubuntu-24.04
9+
outputs:
10+
tag: ${{ steps.tagName.outputs.tag }}
11+
is_highest: ${{ steps.highestTag.outputs.is_highest }}
912
steps:
1013
- name: Checkout
1114
uses: actions/checkout@v6
1215
with:
1316
fetch-depth: 0
17+
- name: Get tag
18+
uses: little-core-labs/get-git-tag@v3.0.2
19+
id: tagName
1420
- name: Highest tag
1521
id: highestTag
1622
run: |
1723
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
18-
echo highest=$(git tag | grep -E "^v?([0-9]+\.)+[0-9]+$" | sort -r -V | head -n1) >> $GITHUB_OUTPUT
19-
- name: Set up QEMU
20-
uses: docker/setup-qemu-action@v4
24+
highest=$(git tag | grep -E "^v?([0-9]+\.)+[0-9]+$" | sort -r -V | head -n1)
25+
if [ "${{ steps.tagName.outputs.tag }}" = "$highest" ]; then
26+
echo is_highest=true >> $GITHUB_OUTPUT
27+
else
28+
echo is_highest=false >> $GITHUB_OUTPUT
29+
fi
30+
31+
build:
32+
needs: prepare
33+
strategy:
34+
matrix:
35+
include:
36+
- arch: amd64
37+
runner: ubuntu-24.04
38+
- arch: arm64
39+
runner: ubuntu-24.04-arm
40+
runs-on: ${{ matrix.runner }}
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v6
2144
- name: Set up Docker Buildx
2245
uses: docker/setup-buildx-action@v4
2346
- name: Docker login
2447
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin
25-
- name: Get tag
26-
uses: little-core-labs/get-git-tag@v3.0.2
27-
id: tagName
28-
- name: Make release
29-
run: make release
48+
- name: Build and push image
49+
run: make docker-push-arch
3050
env:
31-
TAG: ${{ steps.tagName.outputs.tag }}
32-
IMAGE_TAG: ${{ steps.tagName.outputs.tag }}
33-
- name: Push latest
34-
if: steps.tagName.outputs.tag == steps.highestTag.outputs.highest
35-
run: make release
51+
ARCH: ${{ matrix.arch }}
52+
TAG: ${{ needs.prepare.outputs.tag }}
53+
IMAGE_TAG: ${{ needs.prepare.outputs.tag }}
54+
55+
manifest:
56+
needs: [prepare, build]
57+
runs-on: ubuntu-24.04
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v6
61+
- name: Set up Docker Buildx
62+
uses: docker/setup-buildx-action@v4
63+
- name: Docker login
64+
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin
65+
- name: Create version manifest
66+
run: make docker-manifest
3667
env:
37-
TAG: ${{ steps.tagName.outputs.tag }}
38-
IMAGE_TAG: latest
68+
IMAGE_TAG: ${{ needs.prepare.outputs.tag }}
69+
- name: Create latest manifest
70+
if: needs.prepare.outputs.is_highest == 'true'
71+
run: make docker-manifest IMAGE_TAG=latest SOURCE_TAG=${{ needs.prepare.outputs.tag }}

Makefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OS ?= $(shell go env GOOS)
22
ARCH ?= $(shell go env GOARCH)
3-
ALL_PLATFORM = linux/amd64,linux/arm/v7,linux/arm64
3+
ARCHS ?= amd64 arm64
44

55
BUILD_DATE ?= $(shell date -Is)
66

@@ -12,6 +12,7 @@ FULL_IMAGE ?= $(REGISTRY)/$(IMAGE)
1212

1313
TAG ?= $(shell git rev-parse HEAD)
1414
IMAGE_TAG ?= $(shell git rev-parse HEAD)
15+
SOURCE_TAG ?= $(IMAGE_TAG)
1516
COMMIT_SHA ?= $(shell git rev-parse HEAD)
1617

1718
DOCKER_CLI_EXPERIMENTAL ?= enabled
@@ -40,11 +41,21 @@ docker-build:
4041
@echo "Building scaleway-cloud-controller-manager for ${ARCH}"
4142
docker build . --platform=linux/$(ARCH) --build-arg ARCH=$(ARCH) --build-arg TAG=$(TAG) --build-arg COMMIT_SHA=$(COMMIT_SHA) --build-arg BUILD_DATE=$(BUILD_DATE) -f Dockerfile -t ${FULL_IMAGE}:${IMAGE_TAG}-$(ARCH)
4243

43-
.PHONY: docker-buildx-all
44-
docker-buildx-all:
45-
@echo "Making release for tag $(IMAGE_TAG)"
46-
docker buildx build --build-arg TAG=$(TAG) --build-arg COMMIT_SHA=$(COMMIT_SHA) --build-arg BUILD_DATE=$(BUILD_DATE) --platform=$(ALL_PLATFORM) --push -t $(FULL_IMAGE):$(IMAGE_TAG) .
44+
.PHONY: docker-push-arch
45+
docker-push-arch:
46+
@echo "Building and pushing scaleway-cloud-controller-manager for $(ARCH)"
47+
docker buildx build . --platform=linux/$(ARCH) --build-arg TAG=$(TAG) --build-arg COMMIT_SHA=$(COMMIT_SHA) --build-arg BUILD_DATE=$(BUILD_DATE) --push -t $(FULL_IMAGE):$(IMAGE_TAG)-$(ARCH)
48+
49+
.PHONY: docker-manifest
50+
docker-manifest:
51+
@echo "Creating manifest $(FULL_IMAGE):$(IMAGE_TAG) from $(foreach arch,$(ARCHS),$(FULL_IMAGE):$(SOURCE_TAG)-$(arch))"
52+
docker buildx imagetools create -t $(FULL_IMAGE):$(IMAGE_TAG) $(foreach arch,$(ARCHS),$(FULL_IMAGE):$(SOURCE_TAG)-$(arch))
53+
54+
.PHONY: docker-push-all
55+
docker-push-all:
56+
@for arch in $(ARCHS); do $(MAKE) docker-push-arch ARCH=$$arch; done
57+
$(MAKE) docker-manifest
4758

4859
## Release
4960
.PHONY: release
50-
release: docker-buildx-all
61+
release: docker-push-all

0 commit comments

Comments
 (0)