From d954c682167832d2013010727aa55b21d7c7c012 Mon Sep 17 00:00:00 2001 From: Keepers Date: Mon, 22 Aug 2022 13:22:09 -0600 Subject: [PATCH] optional arm docker image build (#624) adds the `--arm` flag to /corso/build/build-container.sh --- README.md | 2 +- build/build-container.sh | 55 +++++++++++++++++++++++++++++++++++----- build/build.sh | 15 ++++++++++- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ee4d04653..3e2905473 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ TODO - Link to the appropriate page in the published docs. # Building Corso ```sh -# Build a binary. Will be places in bin/ +# Build a binary. Will be placed in bin/ ./build/build.sh # Build a container image diff --git a/build/build-container.sh b/build/build-container.sh index f92105d2a..4a6f9af3c 100755 --- a/build/build-container.sh +++ b/build/build-container.sh @@ -1,6 +1,24 @@ #!/bin/sh -set -ex +set -e + +usage() { + echo " " + echo "-----" + echo "Builds a Corso docker container image." + echo " " + echo "-----" + echo "Flags" + echo " -h|--help Help" + echo " |--arm Set the architecture to arm64 (default: amd64)" + echo " " + echo "-----" + echo "Example Usage:" + echo " ./build/build-container.sh" + echo " ./build/build-container.sh --arm" + echo " " + exit 0 +} SCRIPT_ROOT=$(dirname $(readlink -f $0)) PROJECT_ROOT=$(dirname ${SCRIPT_ROOT}) @@ -8,15 +26,38 @@ PROJECT_ROOT=$(dirname ${SCRIPT_ROOT}) OS=linux ARCH=amd64 +while [ "$#" -gt 0 ] +do + case "$1" in + -h|--help) + usage + exit 0 + ;; + --arm) + ARCH=arm64 + ;; + -*) + echo "Invalid option '$1'. Use -h|--help to see the valid options" >&2 + return 1 + ;; + *) + echo "Invalid option '$1'. Use -h|--help to see the valid options" >&2 + return 1 + ;; + esac + shift +done + IMAGE_TAG=${OS}-${ARCH}-$(git describe --tags --always --dirty) IMAGE_NAME=alcionai/corso:${IMAGE_TAG} -${SCRIPT_ROOT}/build.sh +${SCRIPT_ROOT}/build.sh --arch ${ARCH} echo "building container" -docker buildx build --tag ${IMAGE_NAME} \ - --platform ${OS}/${ARCH} \ - --file ${PROJECT_ROOT}/docker/Dockerfile \ - ${PROJECT_ROOT} - +set -x +docker buildx build --tag ${IMAGE_NAME} \ + --platform ${OS}/${ARCH} \ + --file ${PROJECT_ROOT}/docker/Dockerfile \ + ${PROJECT_ROOT} +set +x echo "container built successfully ${IMAGE_NAME}" diff --git a/build/build.sh b/build/build.sh index f597eed3a..91e2c78b3 100755 --- a/build/build.sh +++ b/build/build.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -ex +set -e SCRIPT_ROOT=$(dirname $(readlink -f $0)) PROJECT_ROOT=$(dirname ${SCRIPT_ROOT}) @@ -13,12 +13,24 @@ CORSO_BUILD_CONTAINER_SRC_DIR=${CORSO_BUILD_CONTAINER_DIR}/src GOOS=linux GOARCH=amd64 +while [ "$#" -gt 0 ] +do + case "$1" in + --arch) + GOARCH=$2 + shift + ;; + esac + shift +done + # temporary directory for caching go build mkdir -p /tmp/.corsobuild/cache # temporary directory for caching go modules (needed for fast cross-platform build) mkdir -p /tmp/.corsobuild/mod echo "building corso" +set -x docker run --rm --mount type=bind,src=${SRC_DIR},dst=${CORSO_BUILD_CONTAINER_DIR} \ --mount type=bind,src=/tmp/.corsobuild/cache,dst=/tmp/.corsobuild/cache \ --mount type=bind,src=/tmp/.corsobuild/mod,dst=/go/pkg/mod \ @@ -32,6 +44,7 @@ docker run --rm --mount type=bind,src=${SRC_DIR},dst=${CORSO_BUILD_CONTAINER_DIR build ${CORSO_BUILD_ARGS} mkdir -p ${PROJECT_ROOT}/bin +set +x echo "creating binary image in bin/corso" mv ${PROJECT_ROOT}/src/corso ${PROJECT_ROOT}/bin/corso