|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2020 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 CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +if [ -n "$DEBUG" ]; then |
| 18 | + set -x |
| 19 | +fi |
| 20 | + |
| 21 | +set -o errexit |
| 22 | +set -o nounset |
| 23 | +set -o pipefail |
| 24 | + |
| 25 | +export DOCKER_CLI_EXPERIMENTAL=enabled |
| 26 | + |
| 27 | +if ! docker buildx 2>&1 >/dev/null; then |
| 28 | + echo "buildx not available. Docker 19.03 or higher is required with experimental features enabled" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +# Ensure qemu is in binfmt_misc |
| 33 | +# Docker desktop already has these in versions recent enough to have buildx |
| 34 | +# We only need to do this setup on linux hosts |
| 35 | +if [ "$(uname)" == 'Linux' ]; then |
| 36 | + # NOTE: this is pinned to a digest for a reason! |
| 37 | + # Note2 (@rikatz) - Removing the pin, as apparently it's breaking new alpine builds |
| 38 | + # docker run --rm --privileged multiarch/qemu-user-static@sha256:28ebe2e48220ae8fd5d04bb2c847293b24d7fbfad84f0b970246e0a4efd48ad6 --reset -p yes |
| 39 | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes |
| 40 | +fi |
| 41 | + |
| 42 | +# We can skip setup if the current builder already has multi-arch |
| 43 | +# AND if it isn't the docker driver, which doesn't work |
| 44 | +current_builder="$(docker buildx inspect)" |
| 45 | +# linux/amd64, linux/arm, linux/arm64 |
| 46 | +if ! grep -q "^Driver: docker$" <<<"${current_builder}" && \ |
| 47 | + grep -q "linux/amd64" <<<"${current_builder}" && \ |
| 48 | + grep -q "linux/arm" <<<"${current_builder}" && \ |
| 49 | + grep -q "linux/arm64" <<<"${current_builder}"; then |
| 50 | + exit 0 |
| 51 | +fi |
| 52 | + |
| 53 | +# Ensure qemu is in binfmt_misc |
| 54 | +# Docker desktop already has these in versions recent enough to have buildx |
| 55 | +# We only need to do this setup on linux hosts |
| 56 | +if [ "$(uname)" == 'Linux' ]; then |
| 57 | + # NOTE: this is pinned to a digest for a reason! |
| 58 | + # https://github.com/docker/buildx/issues/542#issuecomment-778835576 |
| 59 | + docker run --rm --privileged tonistiigi/binfmt --uninstall qemu-aarch64 && docker run --rm --privileged tonistiigi/binfmt --install arm64 |
| 60 | + docker run --rm --privileged tonistiigi/binfmt |
| 61 | +fi |
| 62 | + |
| 63 | +# Ensure we use a builder that can leverage it (the default on linux will not) |
| 64 | +docker buildx rm ingress-nginx || true |
| 65 | +docker buildx create --use --name=ingress-nginx |
0 commit comments