Skip to content

Commit aab165a

Browse files
authored
Merge pull request #993 from shivamerla/bootstrap_buildx
hack: add init-buildx.sh with pinned tonistiigi/binfmt for multi-arch Cloud Build
2 parents 9333029 + 1022bab commit aab165a

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

hack/init-buildx.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Bootstrap docker buildx for multi-arch image builds
18+
19+
set -o errexit
20+
set -o nounset
21+
set -o pipefail
22+
23+
BUILDER_NAME="${BUILDER_NAME:-nvidia-dra-driver-gpu-builder}"
24+
25+
# We can skip setup if the current builder already has multi-arch
26+
# AND if it isn't the docker driver, which doesn't work
27+
current_builder="$(docker buildx inspect 2>/dev/null || true)"
28+
if ! grep -Eq "^Driver:\s*docker$" <<<"${current_builder}" && \
29+
grep -q "linux/amd64" <<<"${current_builder}" && \
30+
grep -q "linux/arm64" <<<"${current_builder}"; then
31+
exit 0
32+
fi
33+
34+
# Ensure qemu is in binfmt_misc
35+
# Adapted from https://github.com/kubernetes-sigs/kind/blob/main/hack/build/init-buildx.sh
36+
BINFMT_IMAGE="${BINFMT_IMAGE:-tonistiigi/binfmt:qemu-v7.0.0@sha256:66e11bea77a5ea9d6f0fe79b57cd2b189b5d15b93a2bdb925be22949232e4e55}"
37+
if [ "$(uname)" == 'Linux' ]; then
38+
docker run --rm --privileged "${BINFMT_IMAGE}" --install all
39+
fi
40+
41+
docker buildx rm "${BUILDER_NAME}" || true
42+
docker buildx create --use --name="${BUILDER_NAME}"
43+
docker buildx inspect --bootstrap

scripts/build-and-publish-image.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export DOCKER_CLI_EXPERIMENTAL=enabled
4545
# Required for "docker buildx build --push".
4646
gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
4747

48-
docker buildx create --name nv-dra-driver-gpu-builder || true
49-
docker buildx use nv-dra-driver-gpu-builder
50-
docker buildx inspect --bootstrap
48+
bash "${REPO_ROOT}/hack/init-buildx.sh"
5149

5250
make -f deployments/container/Makefile build \
5351
BUILD_MULTI_ARCH_IMAGES=true \

0 commit comments

Comments
 (0)