-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathinit-buildx.sh
executable file
·71 lines (64 loc) · 2.91 KB
/
init-buildx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# Copyright 2021 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
export DOCKER_CLI_EXPERIMENTAL=enabled
# Expected builder output
#
# Name: k-enhancements-multiarch
# Driver: docker-container
#
# Nodes:
# Name: k-enhancements-multiarch0
# Endpoint: unix:///var/run/docker.sock
# Status: running
# Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
current_builder="$(docker buildx inspect)"
# We can skip setup if the current builder already has multi-arch
# AND if it isn't the "docker" driver, which doesn't work
#
# From https://docs.docker.com/buildx/working-with-buildx/#build-with-buildx:
# "You can run Buildx in different configurations that are exposed through a
# driver concept. Currently, Docker supports a “docker” driver that uses the
# BuildKit library bundled into the docker daemon binary, and a
# “docker-container” driver that automatically launches BuildKit inside a
# Docker container.
#
# The user experience of using Buildx is very similar across drivers.
# However, there are some features that are not currently supported by the
# “docker” driver, because the BuildKit library which is bundled into docker
# daemon uses a different storage component. In contrast, all images built with
# the “docker” driver are automatically added to the “docker images” view by
# default, whereas when using other drivers, the method for outputting an image
# needs to be selected with --output."
if ! grep -q "^Driver: docker$" <<<"${current_builder}" \
&& grep -q "linux/amd64" <<<"${current_builder}" \
&& grep -q "linux/arm" <<<"${current_builder}" \
&& grep -q "linux/arm64" <<<"${current_builder}" \
&& grep -q "linux/ppc64le" <<<"${current_builder}" \
&& grep -q "linux/s390x" <<<"${current_builder}"; then
exit 0
fi
# Ensure qemu is in binfmt_misc
# NOTE: Please always pin this to a digest for predictability/auditability
# Last updated: 08/21/2020
if [ "$(uname)" == 'Linux' ]; then
docker run --rm --privileged multiarch/qemu-user-static@sha256:c772ee1965aa0be9915ee1b018a0dd92ea361b4fa1bcab5bbc033517749b2af4 --reset -p yes
fi
# Ensure we use a builder that can leverage it (the default on linux will not)
docker buildx rm k-enhancements-multiarch || true
docker buildx create --use --name=k-enhancements-multiarch
docker buildx inspect --bootstrap