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

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [x] 💻 CI/Deployment
- [ ] 🐹 Trivial/Minor

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* fixes https://github.com/alcionai/corso/issues/1265

## Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2022-10-24 21:50:28 +05:30 committed by GitHub
parent a2bde432e7
commit 7c027564c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,26 +16,21 @@ i386) GOARCH="386" ;;
esac esac
case "$(uname)" in case "$(uname)" in
Linux) GOOS="linux" ;; Linux) GOOS="linux" ;;
Darwin) GOOS="darwin" ;; # TODO: verify this Darwin) GOOS="darwin" ;;
*) echo "Unknown OS" && exit 0 ;; *) echo "Unknown OS" && exit 0 ;;
esac esac
PLATFORMS="$GOOS/$GOARCH" # default platform PLATFORMS="$GOOS/$GOARCH" # default platform
TAG="alcionai/corso" # default image tag TAG="alcionai/corso" # default image tag
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)"
}
MODE="binary" MODE="binary"
case "$1" in case "$1" in
binary) MODE="binary" && shift ;; 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 ;; -h | --help) usage && exit 0 ;;
*) usage && exit 1 ;; *) usage && exit 1 ;;
esac esac
@ -49,6 +44,15 @@ while [ "$#" -gt 0 ]; do
shift shift
done 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 if [ "$MODE" == "binary" ]; then
mkdir -p ${CORSO_BUILD_CACHE} # prep env mkdir -p ${CORSO_BUILD_CACHE} # prep env
for platform in ${PLATFORMS/,/ }; do for platform in ${PLATFORMS/,/ }; do
@ -66,14 +70,18 @@ if [ "$MODE" == "binary" ]; then
golang:${GOVER} \ golang:${GOVER} \
go build -o corso -ldflags "${CORSO_BUILD_LDFLAGS}" go build -o corso -ldflags "${CORSO_BUILD_LDFLAGS}"
OUTFILE="corso" OUTFILE="corso"
[ "$GOOS" == "windows" ] && OUTFILE="corso.exe" [ "$GOOS" == "windows" ] && OUTFILE="corso.exe"
mkdir -p "${ROOT}/bin/${GOOS}-${GOARCH}" mkdir -p "${ROOT}/bin/${GOOS}-${GOARCH}"
mv "${ROOT}/src/corso" "${ROOT}/bin/${GOOS}-${GOARCH}/${OUTFILE}" mv "${ROOT}/src/corso" "${ROOT}/bin/${GOOS}-${GOARCH}/${OUTFILE}"
echo Corso $platform binary available in "${ROOT}/bin/${GOOS}-${GOARCH}/${OUTFILE}" echo Corso $platform binary available in "${ROOT}/bin/${GOOS}-${GOARCH}/${OUTFILE}"
done done
else 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" echo Building "$TAG" image for "$PLATFORMS"
docker buildx build --tag ${TAG} \ docker buildx build --tag ${TAG} \
--platform ${PLATFORMS} \ --platform ${PLATFORMS} \