From 7c027564c1c1111976965b86fac6d8faafe3a772 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Mon, 24 Oct 2022 21:50:28 +0530 Subject: [PATCH] Prevent from trying to build darwin images (#1279) ## Description Defaults to linux for image platform. Errors out when explicitly provided darwin as container image platform. ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [x] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * fixes https://github.com/alcionai/corso/issues/1265 ## Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- build/build.sh | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/build/build.sh b/build/build.sh index 9f1237882..b9d6685cf 100755 --- a/build/build.sh +++ b/build/build.sh @@ -16,26 +16,21 @@ i386) GOARCH="386" ;; esac case "$(uname)" in Linux) GOOS="linux" ;; -Darwin) GOOS="darwin" ;; # TODO: verify this +Darwin) GOOS="darwin" ;; *) echo "Unknown OS" && exit 0 ;; esac PLATFORMS="$GOOS/$GOARCH" # default platform TAG="alcionai/corso" # default image tag -usage() { - echo "Usage: $(basename $0) [--platforms ...] [--tag ...]" - echo "" - echo "OPTIONS" - echo " -p|--platforms Platforms to build for (default: $PLATFORMS)" - echo " Specify multiple platforms using ',' (eg: linux/amd64,darwin/arm)" - echo " -t|--tag Tag for container image (default: $TAG)" -} - MODE="binary" case "$1" in binary) MODE="binary" && shift ;; -image) MODE="image" && shift ;; +image) + MODE="image" + shift + GOOS="linux" # darwin container images are not a thing + ;; -h | --help) usage && exit 0 ;; *) usage && exit 1 ;; esac @@ -49,6 +44,15 @@ while [ "$#" -gt 0 ]; do shift done +usage() { + echo "Usage: $(basename $0) binary | image [--platforms ...] [--tag ...]" + echo "" + echo "OPTIONS" + echo " -p | --platforms Platforms to build for (default: $PLATFORMS)" + echo " Specify multiple platforms using ',' (eg: linux/amd64,darwin/arm)" + echo " -t | --tag Tag for container image (default: $TAG)" +} + if [ "$MODE" == "binary" ]; then mkdir -p ${CORSO_BUILD_CACHE} # prep env for platform in ${PLATFORMS/,/ }; do @@ -66,14 +70,18 @@ if [ "$MODE" == "binary" ]; then golang:${GOVER} \ go build -o corso -ldflags "${CORSO_BUILD_LDFLAGS}" - OUTFILE="corso" - [ "$GOOS" == "windows" ] && OUTFILE="corso.exe" + OUTFILE="corso" + [ "$GOOS" == "windows" ] && OUTFILE="corso.exe" mkdir -p "${ROOT}/bin/${GOOS}-${GOARCH}" mv "${ROOT}/src/corso" "${ROOT}/bin/${GOOS}-${GOARCH}/${OUTFILE}" echo Corso $platform binary available in "${ROOT}/bin/${GOOS}-${GOARCH}/${OUTFILE}" done else + for platform in ${PLATFORMS/,/ }; do + echo "$platform" | grep -Eq "^darwin" && + echo Cannot create darwin images "($platform)" && exit 1 + done echo Building "$TAG" image for "$PLATFORMS" docker buildx build --tag ${TAG} \ --platform ${PLATFORMS} \