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