hack: install buildx in util

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
v0.9
Akihiro Suda 2020-11-26 14:27:55 +09:00
parent 97b0904bcd
commit 201ba2b0e3
No known key found for this signature in database
GPG Key ID: 49524C6F9F638F1A
3 changed files with 76 additions and 2 deletions

19
hack/bootstrap-buildx Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eu -o pipefail
if [ "$#" -ne 1 ]; then
echo >&2 "usage: $0 <name>"
exit 1
fi
NAME="$1"
echo "Bootstrapping buildx builder \"${NAME}\""
topdir="$(realpath "$(dirname "$0")/..")"
cd "${topdir}"
buildx="./bin/buildx"
if ! "${buildx}" inspect "${NAME}" >/dev/null 2>&1; then
set -x
"${buildx}" create --driver docker-container --name "${NAME}"
fi
set -x
"${buildx}" inspect --bootstrap "${NAME}"

48
hack/install-buildx Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -eu -o pipefail
topdir="$(realpath $(dirname "$0")/..)"
cd "${topdir}"
VERSION="v0.5.1"
BINDIR="$(pwd)/bin"
DEST="${BINDIR}/buildx"
os=""
case "$(uname)" in
Linux)
os="linux"
;;
Darwin)
os="darwin"
;;
*)
echo >&2 "unknown OS"
exit 1
;;
esac
arch="$(uname -m)"
case "${arch}" in
x86_64)
arch="amd64"
;;
aarch64)
arch="arm64"
;;
armv7l)
arch="arm-v7"
;;
armv6l)
arch="arm-v6"
;;
esac
url="https://github.com/docker/buildx/releases/download/${VERSION}/buildx-${VERSION}.${os}-${arch}"
echo "Installing buildx ${VERSION} as ${DEST}"
set -x
mkdir -p "${BINDIR}"
rm -f "${DEST}.download"
curl -f -L -o "${DEST}.download" "${url}"
chmod +x "${DEST}.download"
mv "${DEST}.download" "${DEST}"

View File

@ -29,8 +29,15 @@ buildxCmd() {
set -x
buildx "$@" $progressFlag
else
echo >&2 "ERROR: Please install buildx"
exit 1
topdir="$(realpath $(dirname "$0")/..)"
if [ ! -x "${topdir}/bin/buildx" ]; then
set -x
"${topdir}/hack/install-buildx"
fi
set -x
bootstrapName="moby-buildkit"
"${topdir}/hack/bootstrap-buildx" "${bootstrapName}"
BUILDX_BUILDER="${bootstrapName}" "${topdir}/bin/buildx" "$@" $progressFlag
fi
}