Skip to content

Commit

Permalink
build: setup docker buildx
Browse files Browse the repository at this point in the history
Signed-off-by: Morlay <morlay.null@gmail.com>
  • Loading branch information
morlay committed Jul 2, 2020
1 parent 00b6e96 commit 0df8ce6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/travis/setup-docker-buildx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

DOCKER_BUILDX_VERSION=v0.4.1
LOCAL_OS=$(uname -s | tr '[A-Z]' '[a-z]')

case $(uname -m) in
x86_64)
LOCAL_ARCH=amd64
;;
aarch64)
LOCAL_ARCH=arm64
;;
*)
echo "unsupported architecture"
exit 1
;;
esac

if [[ ! -f ~/.docker/cli-plugins/docker-buildx ]]; then
DOCKER_BUILDX_DOWNLOAD_URL=https://github.com/docker/buildx/releases/download/${DOCKER_BUILDX_VERSION}/buildx-${DOCKER_BUILDX_VERSION}.${LOCAL_OS}-${LOCAL_ARCH}
mkdir -p ~/.docker/cli-plugins
echo "downloading from ${DOCKER_BUILDX_DOWNLOAD_URL}"
curl -sL --output ~/.docker/cli-plugins/docker-buildx "${DOCKER_BUILDX_DOWNLOAD_URL}"
chmod +x ~/.docker/cli-plugins/docker-buildx
fi

# checkout buildx available
docker buildx version

# enabled qemu if needed
if [[ ! $(docker buildx inspect default | grep Platforms) == *arm64* ]]; then
docker run --rm --privileged multiarch/qemu-user-static --reset -p
fi

# setup builder if need
if [[ ! $(docker buildx inspect builder) == *"Name"* ]]; then
docker buildx create --use --name=builder --platform=linux/amd64,linux/arm64 --driver-opt=image=moby/buildkit:master,network=host
fi

0 comments on commit 0df8ce6

Please sign in to comment.