From f61e45e36dd6203455ad61f8422d436232132109 Mon Sep 17 00:00:00 2001 From: Enrique Llorente Date: Tue, 24 Jan 2023 16:22:30 +0100 Subject: [PATCH] Revert "docker: Remove buildx init/install (#1134)" This reverts commit 4bb0cd080f2dfa1276cfc61164dbda124d53e951. Signed-off-by: Enrique Llorente --- hack/build-push-container.docker.sh | 2 ++ hack/init-buildx.sh | 41 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 hack/init-buildx.sh diff --git a/hack/build-push-container.docker.sh b/hack/build-push-container.docker.sh index c5dd8c1f0..c483870af 100755 --- a/hack/build-push-container.docker.sh +++ b/hack/build-push-container.docker.sh @@ -7,6 +7,8 @@ if [ "$SKIP_IMAGE_BUILD" == "true" ]; then exit 0 fi +hack/init-buildx.sh + ARCHS=${ARCHS:-$(go env GOARCH)} PLATFORM="" diff --git a/hack/init-buildx.sh b/hack/init-buildx.sh new file mode 100755 index 000000000..e277a75e1 --- /dev/null +++ b/hack/init-buildx.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# Copyright 2020 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 -o nounset -o pipefail + +export DOCKER_CLI_EXPERIMENTAL=enabled + +# If there is no buildx let's install it +if ! docker buildx > /dev/null 2>&1; then + mkdir -p ~/.docker/cli-plugins + curl -L https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64 --output ~/.docker/cli-plugins/docker-buildx + chmod a+x ~/.docker/cli-plugins/docker-buildx +fi + + +# We can skip setup if the current builder already has multi-arch +# AND if it isn't the docker driver, which doesn't work +current_builder="$(docker buildx inspect)" +# linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6 +if ! grep -q "^Driver: docker$" <<<"${current_builder}" && \ + grep -q "linux/amd64" <<<"${current_builder}" && \ + grep -q "linux/arm64" <<<"${current_builder}"; then + exit 0 +fi + + +if ! docker buildx ls | grep -q kubernetes-nmstate-builder; then + docker buildx create --driver-opt network=host --use --name=kubernetes-nmstate-builder +fi