-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild_crossplatform.sh
executable file
·45 lines (35 loc) · 1.14 KB
/
build_crossplatform.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
set -e
# Build docker image for linux/amd64 and linux/arm64 platforms
# For MacOS requires:
# brew install filosottile/musl-cross/musl-cross
IMAGE=bloxroute/bxgateway-go-release-candidate:${1:-latest}
PLATFORM=${2:-linux/amd64}
CUR_PLATFORM="$(go env GOOS)/$(go env GOARCH)"
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
export GOOS
export GOARCH
if [[ $PLATFORM == "$CUR_PLATFORM" ]]; then
echo "Building for local platform"
elif [[ $GOARCH == "arm64" ]]; then
ARCH="aarch64"
export CC="${ARCH}-${GOOS}-musl-gcc"
export CXX="${ARCH}-${GOOS}-musl-g++"
export CGO_ENABLED="1"
elif [[ $GOARCH == "amd64" ]]; then
ARCH="x86_64"
export CC="${ARCH}-${GOOS}-musl-gcc"
export CXX="${ARCH}-${GOOS}-musl-g++"
export CGO_ENABLED="1"
else
echo "Error: Unsupported ${GOARCH} architecture"
exit 1
fi
make gateway
# extract tag and keep in file (can't be done in docker). Used by Makefile
tag=$(git describe --tags --always --dirty --match=v2* 2> /dev/null)
echo "$tag" > .gittag
echo "Building container... $IMAGE"
docker build . -f Dockerfile.localbin --rm=true --platform "$PLATFORM" -t "$IMAGE"
rm .gittag