33cd $( dirname " ${BASH_SOURCE[0]} " )
44set -euxo pipefail
55
6- CGO_ENABLED=0 go build -ldflags " -s -w" -o ./coder-logstream-kube ../
7- docker build -t coder-logstream-kube:latest .
6+ # Set CI to false if not set
7+ CI=${CI:- false}
8+
9+
10+ # Get current architecture
11+ current=$( go env GOARCH)
12+ # Arhcitectures to build for
13+ archs=(amd64 arm64 arm)
14+
15+ # build for all architectures
16+ for arch in " ${archs[@]} " ; do
17+ echo " Building for $arch "
18+ GOARCH=$arch GOOS=linux CGO_ENABLED=0 go build -ldflags " -s -w" -o ./coder-logstream-kube-$arch ../
19+ done
20+
21+ # We have to use docker buildx to tag multiple images with
22+ # platforms tragically, so we have to create a builder.
23+ BUILDER_NAME=" coder-logstream-kube"
24+ BUILDER_EXISTS=$( docker buildx ls | grep $BUILDER_NAME || true)
25+
26+ # If builder doesn't exist, create it
27+ if [ -z " $BUILDER_EXISTS " ]; then
28+ echo " Creating dockerx builder $BUILDER_NAME ..."
29+ docker buildx create --use --platform=linux/arm64,linux/amd64,linux/arm/v7 --name $BUILDER_NAME
30+ else
31+ echo " Builder $BUILDER_NAME already exists. Using it."
32+ fi
33+
34+ # Ensure the builder is bootstrapped and ready to use
35+ docker buildx inspect --bootstrap & > /dev/null
36+
37+ # Build
38+ if [ " $CI " = " false" ]; then
39+ docker buildx build --platform linux/$current -t coder-logstream-kube --load .
40+ else
41+ VERSION=$( ../scripts/version.sh)
42+ BASE=ghcr.io/coder/coder-logstream-kube
43+ IMAGE=$BASE :$VERSION
44+ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t $IMAGE -t $BASE :latest --push.
45+ fi
0 commit comments