Skip to content

Commit 0455a77

Browse files
Build multiarch images on native GitHub runners
This commit makes the following changes: 1. Builds multiarch images for non-release commits/PRs, in addition to released versions. 2. Runs the docker build for an arch on the respective GitHub runner (e.g. a linux/amd64 docker image will be built on a linux/amd64 runner). This native build reduces build times due to not requiring emulation. 3. Removes explicit use of buildx for docker build. Buildx is now the default builder in Docker. Also removes the related QEMU setup. Signed-off-by: Rajath Agasthya <[email protected]>
1 parent f258dbe commit 0455a77

File tree

4 files changed

+64
-34
lines changed

4 files changed

+64
-34
lines changed

.github/workflows/image.yaml

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,21 @@ on:
2424

2525
jobs:
2626
build-image:
27-
runs-on: linux-amd64-cpu4
27+
strategy:
28+
matrix:
29+
arch:
30+
- amd64
31+
- arm64
32+
dist: [ubi9]
33+
runs-on: linux-${{ matrix.arch }}-cpu4
2834
permissions:
2935
contents: read
3036
id-token: write
3137
packages: write
32-
strategy:
33-
matrix:
34-
dist: [ubi9]
3538
steps:
3639
- uses: actions/checkout@v5
3740
name: Check out code
3841

39-
- name: Set up QEMU
40-
uses: docker/setup-qemu-action@v3
41-
with:
42-
image: tonistiigi/binfmt:master
43-
44-
- name: Set up Docker Buildx
45-
uses: docker/setup-buildx-action@v3
46-
4742
- name: Login to GitHub Container Registry
4843
uses: docker/login-action@v3
4944
with:
@@ -56,10 +51,32 @@ jobs:
5651
- name: Build image
5752
env:
5853
IMAGE_NAME: ghcr.io/nvidia/k8s-driver-manager
59-
VERSION: ${{ inputs.version }}
54+
VERSION: ${{ inputs.version }}-${{ matrix.arch }}
6055
PUSH_ON_BUILD: "true"
61-
BUILD_MULTI_ARCH_IMAGES: "true"
6256
GOPROXY: ${{ steps.setup-go-proxy.outputs.goproxy-url }}
57+
DOCKER_BUILD_PLATFORM_OPTIONS: "--platform=linux/${{ matrix.arch }}"
6358
run: |
6459
echo "${VERSION}"
6560
make -f deployments/container/Makefile build-${{ matrix.dist }}
61+
62+
create-manifest:
63+
needs: [ build-image ]
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v5
67+
name: Check out code
68+
- name: Login to GitHub Container Registry
69+
uses: docker/login-action@v3
70+
with:
71+
registry: ghcr.io
72+
username: ${{ github.actor }}
73+
password: ${{ secrets.GITHUB_TOKEN }}
74+
- name: Build Manifest
75+
env:
76+
MULTIARCH_IMAGE: ghcr.io/nvidia/k8s-driver-manager:${{ inputs.version }}
77+
run: |
78+
docker manifest create \
79+
${MULTIARCH_IMAGE} \
80+
ghcr.io/nvidia/k8s-driver-manager:${{ inputs.version }}-amd64 \
81+
ghcr.io/nvidia/k8s-driver-manager:${{ inputs.version }}-arm64
82+
docker manifest push ${MULTIARCH_IMAGE}

deployments/container/Makefile

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
BUILD_MULTI_ARCH_IMAGES ?= no
1616
DOCKER ?= docker
17-
BUILDX =
18-
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
19-
BUILDX = buildx
20-
endif
2117

2218
##### Global variables #####
2319
include $(CURDIR)/versions.mk
@@ -41,11 +37,12 @@ OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
4137
DISTRIBUTIONS := ubi9
4238
DEFAULT_PUSH_TARGET := ubi9
4339

40+
IMAGE_TARGETS := $(patsubst %,image-%,$(DISTRIBUTIONS))
4441
PUSH_TARGETS := $(patsubst %, push-%, $(DISTRIBUTIONS))
4542
BUILD_TARGETS := $(patsubst %, build-%, $(DISTRIBUTIONS))
4643
TEST_TARGETS := $(patsubst %, build-%, $(DISTRIBUTIONS))
4744

48-
.PHONY: $(DISTRIBUTIONS) $(PUSH_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS)
45+
.PHONY: $(DISTRIBUTIONS) $(PUSH_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS) $(IMAGE_TARGETS)
4946

5047
ifneq ($(BUILD_MULTI_ARCH_IMAGES),true)
5148
include $(CURDIR)/deployments/container/native-only.mk
@@ -56,21 +53,29 @@ endif
5653
build-%: DOCKERFILE_SUFFIX = $(*)
5754
build-%: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile.$(DOCKERFILE_SUFFIX)
5855

56+
image-%: DOCKERFILE_SUFFIX = $(*)
57+
image-%: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile.$(DOCKERFILE_SUFFIX)
58+
5959
# Both ubi9 and build-ubi9 trigger a build of the relevant image
6060
$(DISTRIBUTIONS): %: build-%
61-
$(BUILD_TARGETS): build-%:
62-
DOCKER_BUILDKIT=1 \
63-
$(DOCKER) $(BUILDX) build --pull \
64-
$(DOCKER_BUILD_OPTIONS) \
65-
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
66-
--tag $(IMAGE) \
67-
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
68-
--build-arg VERSION="$(VERSION)" \
69-
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
70-
--build-arg CVE_UPDATES="$(CVE_UPDATES)" \
71-
--build-arg GOPROXY="$(GOPROXY)" \
72-
--file $(DOCKERFILE) \
73-
$(CURDIR)
61+
62+
# Use a generic image target to build the relevant images
63+
$(IMAGE_TARGETS): image-%:
64+
$(DOCKER) build --pull \
65+
$(DOCKER_BUILD_OPTIONS) \
66+
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
67+
--tag $(IMAGE) \
68+
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
69+
--build-arg VERSION="$(VERSION)" \
70+
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
71+
--build-arg CVE_UPDATES="$(CVE_UPDATES)" \
72+
--build-arg GOPROXY="$(GOPROXY)" \
73+
--file $(DOCKERFILE) \
74+
$(CURDIR)
75+
76+
# Handle the default build target.
77+
.PHONY: build
78+
build: $(DEFAULT_PUSH_TARGET)
7479

7580
.PHONY: bump-commit
7681
BUMP_COMMIT := Bump to version $(VERSION)

deployments/container/multi-arch.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
PUSH_ON_BUILD ?= false
1616
ATTACH_ATTESTATIONS ?= false
1717
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD) --provenance=$(ATTACH_ATTESTATIONS) --sbom=$(ATTACH_ATTESTATIONS)
18-
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64
18+
DOCKER_BUILD_PLATFORM_OPTIONS ?= --platform=linux/amd64,linux/arm64
1919

2020
REGCTL ?= regctl
2121
$(PUSH_TARGETS): push-%:

deployments/container/native-only.mk

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
15+
PUSH_ON_BUILD ?= false
16+
DOCKER_BUILD_PLATFORM_OPTIONS ?= --platform=linux/amd64
17+
18+
ifeq ($(PUSH_ON_BUILD),true)
19+
$(BUILD_TARGETS): build-%: image-%
20+
$(DOCKER) push "$(IMAGE)"
21+
else
22+
$(BUILD_TARGETS): build-%: image-%
23+
endif
1624

1725
$(PUSH_TARGETS): push-%:
1826
$(DOCKER) tag "$(IMAGE)" "$(OUT_IMAGE)"

0 commit comments

Comments
 (0)