Skip to content

Commit 9e6896c

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 if 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 48da989 commit 9e6896c

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ jobs:
3333
secrets: inherit
3434
with:
3535
version: ${{ needs.basic.outputs.version }}
36-
build_multi_arch_images: ${{ github.ref_name == 'main' || startsWith(github.ref_name, 'release-') }}
3736

3837
e2e-test:
3938
needs:

.github/workflows/image.yaml

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ on:
2020
version:
2121
required: true
2222
type: string
23-
build_multi_arch_images:
24-
required: true
25-
type: string
2623

2724
jobs:
28-
build:
25+
build-amd64:
2926
runs-on: linux-amd64-cpu4
3027
permissions:
3128
contents: read
@@ -34,12 +31,35 @@ jobs:
3431
steps:
3532
- uses: actions/checkout@v5
3633
name: Check out code
37-
- name: Set up QEMU
38-
uses: docker/setup-qemu-action@v3
34+
- name: Login to GitHub Container Registry
35+
uses: docker/login-action@v3
3936
with:
40-
image: tonistiigi/binfmt:master
41-
- name: Set up Docker Buildx
42-
uses: docker/setup-buildx-action@v3
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
- name: Setup Go Proxy
41+
id: setup-go-proxy
42+
uses: nv-gha-runners/setup-artifactory-go-proxy@main
43+
- name: Build image
44+
env:
45+
IMAGE_NAME: ghcr.io/nvidia/k8s-device-plugin
46+
VERSION: ${{ inputs.version }}-amd64
47+
PUSH_ON_BUILD: true
48+
GOPROXY: ${{ steps.setup-go-proxy.outputs.goproxy-url }}
49+
DOCKER_BUILD_PLATFORM_OPTIONS: "--platform=linux/amd64"
50+
run: |
51+
echo "${VERSION}"
52+
make -f deployments/container/Makefile build
53+
54+
build-arm64:
55+
runs-on: linux-arm64-cpu4
56+
permissions:
57+
contents: read
58+
id-token: write
59+
packages: write
60+
steps:
61+
- uses: actions/checkout@v5
62+
name: Check out code
4363
- name: Login to GitHub Container Registry
4464
uses: docker/login-action@v3
4565
with:
@@ -52,10 +72,34 @@ jobs:
5272
- name: Build image
5373
env:
5474
IMAGE_NAME: ghcr.io/nvidia/k8s-device-plugin
55-
VERSION: ${{ inputs.version }}
75+
VERSION: ${{ inputs.version }}-arm64
5676
PUSH_ON_BUILD: true
57-
BUILD_MULTI_ARCH_IMAGES: ${{ inputs.build_multi_arch_images }}
5877
GOPROXY: ${{ steps.setup-go-proxy.outputs.goproxy-url }}
78+
DOCKER_BUILD_PLATFORM_OPTIONS: "--platform=linux/arm64"
5979
run: |
6080
echo "${VERSION}"
6181
make -f deployments/container/Makefile build
82+
83+
build-multi-arch-images:
84+
needs: [ build-arm64, build-amd64 ]
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v5
88+
name: Check out code
89+
- name: Login to GitHub Container Registry
90+
uses: docker/login-action@v3
91+
with:
92+
registry: ghcr.io
93+
username: ${{ github.actor }}
94+
password: ${{ secrets.GITHUB_TOKEN }}
95+
- name: Build Manifest
96+
env:
97+
IMAGE_ARM: ghcr.io/nvidia/k8s-device-plugin:${{ inputs.version }}-arm64
98+
IMAGE_AMD: ghcr.io/nvidia/k8s-device-plugin:${{ inputs.version }}-amd64
99+
MULTIARCH_IMAGE: ghcr.io/nvidia/k8s-device-plugin:${{ inputs.version }}
100+
run: |
101+
docker manifest create \
102+
${MULTIARCH_IMAGE} \
103+
${IMAGE_AMD} \
104+
${IMAGE_ARM}
105+
docker manifest push ${MULTIARCH_IMAGE}

deployments/container/Makefile

Lines changed: 1 addition & 6 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
MKDIR ?= mkdir
2218

2319
##### Global variables #####
@@ -72,8 +68,7 @@ DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile
7268

7369
# Use a generic build target to build the relevant images
7470
$(IMAGE_TARGETS): image-%:
75-
DOCKER_BUILDKIT=1 \
76-
$(DOCKER) $(BUILDX) build --pull \
71+
$(DOCKER) build --pull \
7772
--provenance=false --sbom=false \
7873
$(DOCKER_BUILD_OPTIONS) \
7974
$(DOCKER_BUILD_PLATFORM_OPTIONS) \

deployments/container/multi-arch.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
PUSH_ON_BUILD ?= false
1616
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD)
17-
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64
17+
DOCKER_BUILD_PLATFORM_OPTIONS ?= --platform=linux/amd64,linux/arm64
1818

1919
$(BUILD_TARGETS): build-%: image-%

0 commit comments

Comments
 (0)