Skip to content

Commit 2665f5f

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 requring emulation. Signed-off-by: Rajath Agasthya <[email protected]>
1 parent 48da989 commit 2665f5f

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

.github/workflows/image.yaml

Lines changed: 66 additions & 5 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
@@ -54,8 +51,72 @@ jobs:
5451
IMAGE_NAME: ghcr.io/nvidia/k8s-device-plugin
5552
VERSION: ${{ inputs.version }}
5653
PUSH_ON_BUILD: true
57-
BUILD_MULTI_ARCH_IMAGES: ${{ inputs.build_multi_arch_images }}
5854
GOPROXY: ${{ steps.setup-go-proxy.outputs.goproxy-url }}
55+
DOCKER_BUILD_PLATFORM_OPTIONS: "--platform=linux/amd64"
5956
run: |
6057
echo "${VERSION}"
6158
make -f deployments/container/Makefile build
59+
60+
build-arm64:
61+
runs-on: linux-arm64-cpu4
62+
permissions:
63+
contents: read
64+
id-token: write
65+
packages: write
66+
steps:
67+
- uses: actions/checkout@v5
68+
name: Check out code
69+
- name: Set up QEMU
70+
uses: docker/setup-qemu-action@v3
71+
with:
72+
image: tonistiigi/binfmt:master
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
- name: Login to GitHub Container Registry
76+
uses: docker/login-action@v3
77+
with:
78+
registry: ghcr.io
79+
username: ${{ github.actor }}
80+
password: ${{ secrets.GITHUB_TOKEN }}
81+
- name: Setup Go Proxy
82+
id: setup-go-proxy
83+
uses: nv-gha-runners/setup-artifactory-go-proxy@main
84+
- name: Build image
85+
env:
86+
IMAGE_NAME: ghcr.io/nvidia/k8s-device-plugin
87+
VERSION: ${{ inputs.version }}
88+
PUSH_ON_BUILD: true
89+
GOPROXY: ${{ steps.setup-go-proxy.outputs.goproxy-url }}
90+
DOCKER_BUILD_PLATFORM_OPTIONS: "--platform=linux/arm64"
91+
run: |
92+
echo "${VERSION}"
93+
make -f deployments/container/Makefile build
94+
95+
build-multi-arch-images:
96+
needs: [ build-arm64, build-amd64 ]
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v5
100+
name: Check out code
101+
- name: Calculate build vars
102+
id: vars
103+
run: |
104+
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
105+
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
106+
- name: Login to GitHub Container Registry
107+
uses: docker/login-action@v3
108+
with:
109+
registry: ghcr.io
110+
username: ${{ github.actor }}
111+
password: ${{ secrets.GITHUB_TOKEN }}
112+
- name: Build Manifest
113+
env:
114+
IMAGE_ARM: ghcr.io/nvidia/k8s-device-plugin:${{ inputs.version }}-arm64
115+
IMAGE_AMD: ghcr.io/nvidia/k8s-device-plugin:${{ inputs.version }}-amd64
116+
MULTIARCH_IMAGE: ghcr.io/nvidia/k8s-device-plugin:${{ inputs.version }}
117+
run: |
118+
docker manifest create \
119+
${MULTIARCH_IMAGE} \
120+
${IMAGE_AMD} \
121+
${IMAGE_ARM}
122+
docker manifest push ${MULTIARCH_IMAGE}

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)