|
| 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 |
0 commit comments