Skip to content

Commit 3ced65f

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 3ced65f

File tree

4 files changed

+57
-37
lines changed

4 files changed

+57
-37
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: [distroless]
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 & 21 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
@@ -38,8 +34,8 @@ OUT_IMAGE_VERSION ?= $(IMAGE_VERSION)
3834
OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
3935

4036
##### Public rules #####
41-
DISTRIBUTIONS := ubi9
42-
DEFAULT_PUSH_TARGET := ubi9
37+
DISTRIBUTIONS := distroless
38+
DEFAULT_PUSH_TARGET := distroless
4339

4440
PUSH_TARGETS := $(patsubst %, push-%, $(DISTRIBUTIONS))
4541
BUILD_TARGETS := $(patsubst %, build-%, $(DISTRIBUTIONS))
@@ -53,24 +49,30 @@ else
5349
include $(CURDIR)/deployments/container/multi-arch.mk
5450
endif
5551

52+
# Both distroless and build-distroless trigger a build of the relevant image
53+
$(DISTRIBUTIONS): %: build-%
54+
5655
build-%: DOCKERFILE_SUFFIX = $(*)
5756
build-%: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile.$(DOCKERFILE_SUFFIX)
58-
59-
# Both ubi9 and build-ubi9 trigger a build of the relevant image
60-
$(DISTRIBUTIONS): %: build-%
6157
$(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)
58+
$(DOCKER) build --pull \
59+
$(DOCKER_BUILD_OPTIONS) \
60+
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
61+
--tag $(IMAGE) \
62+
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
63+
--build-arg VERSION="$(VERSION)" \
64+
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
65+
--build-arg CVE_UPDATES="$(CVE_UPDATES)" \
66+
--build-arg GOPROXY="$(GOPROXY)" \
67+
--file $(DOCKERFILE) \
68+
$(CURDIR)
69+
ifeq ($(PUSH_ON_BUILD),true)
70+
$(DOCKER) push "$(IMAGE)"
71+
endif
72+
73+
# Handle the default build target.
74+
.PHONY: build
75+
build: $(DEFAULT_PUSH_TARGET)
7476

7577
.PHONY: bump-commit
7678
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
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
1617

1718
$(PUSH_TARGETS): push-%:
1819
$(DOCKER) tag "$(IMAGE)" "$(OUT_IMAGE)"

0 commit comments

Comments
 (0)