sandbox-agent/docker/release/build.sh
Nathan Flurry de139a7601 fix: bake version into binary at build time
Instead of hacking around the version in the Node.js wrapper script,
properly pass the version at build time via SANDBOX_AGENT_VERSION env var.

Changes:
- build.rs: Generate version.rs with VERSION constant from env var
- main.rs: Use generated version constant for clap --version
- Dockerfiles: Accept SANDBOX_AGENT_VERSION as build arg
- build.sh: Pass version as second argument to Docker builds
- release.yaml: Pass version to build script during CI
- Remove version hack from sdks/cli/bin/sandbox-agent wrapper

The version is now baked into the binary during the release build,
ensuring --version reports the correct npm package version.
2026-01-30 15:33:33 -08:00

62 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
TARGET=${1:-x86_64-unknown-linux-musl}
VERSION=${2:-}
# Build arguments for Docker
BUILD_ARGS=""
if [ -n "$VERSION" ]; then
BUILD_ARGS="--build-arg SANDBOX_AGENT_VERSION=$VERSION"
echo "Building with version: $VERSION"
fi
case $TARGET in
x86_64-unknown-linux-musl)
echo "Building for Linux x86_64 musl"
DOCKERFILE="linux-x86_64.Dockerfile"
TARGET_STAGE="x86_64-builder"
BINARY="sandbox-agent-$TARGET"
;;
x86_64-pc-windows-gnu)
echo "Building for Windows x86_64"
DOCKERFILE="windows.Dockerfile"
TARGET_STAGE=""
BINARY="sandbox-agent-$TARGET.exe"
;;
x86_64-apple-darwin)
echo "Building for macOS x86_64"
DOCKERFILE="macos-x86_64.Dockerfile"
TARGET_STAGE="x86_64-builder"
BINARY="sandbox-agent-$TARGET"
;;
aarch64-apple-darwin)
echo "Building for macOS aarch64"
DOCKERFILE="macos-aarch64.Dockerfile"
TARGET_STAGE="aarch64-builder"
BINARY="sandbox-agent-$TARGET"
;;
*)
echo "Unsupported target: $TARGET"
exit 1
;;
esac
DOCKER_BUILDKIT=1
if [ -n "$TARGET_STAGE" ]; then
docker build --target "$TARGET_STAGE" $BUILD_ARGS -f "docker/release/$DOCKERFILE" -t "sandbox-agent-builder-$TARGET" .
else
docker build $BUILD_ARGS -f "docker/release/$DOCKERFILE" -t "sandbox-agent-builder-$TARGET" .
fi
CONTAINER_ID=$(docker create "sandbox-agent-builder-$TARGET")
mkdir -p dist
docker cp "$CONTAINER_ID:/artifacts/$BINARY" "dist/"
docker rm "$CONTAINER_ID"
if [[ "$BINARY" != *.exe ]]; then
chmod +x "dist/$BINARY"
fi
echo "Binary saved to: dist/$BINARY"