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