fabro/bin/dev/docker-build.sh
Bryan Helmkamp 7c80d9be9c
fix(docker): build fabro-cli inside rust:1-bookworm for local image
The host cargo build on macOS produced a Mach-O binary that the
Linux runtime image refused with "Exec format error". Run the
compile in rust:1-bookworm so the output matches the target
platform, and cache the registry plus target dir in named volumes
for incremental rebuilds. Also gitignore docker-context/ since it
is regenerated on every build.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 00:19:46 -04:00

41 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build a local fabro Docker image from the current working tree.
#
# The release workflow uses prebuilt release tarballs. For local iteration we
# compile inside rust:1-bookworm so the binary is a Linux ELF that matches the
# runtime image, regardless of host OS. Cargo registry and target dir are
# cached in named volumes so subsequent runs are incremental.
set -euo pipefail
cd "$(dirname "$0")/../.."
case "$(uname -m)" in
x86_64|amd64) arch=amd64 ;;
aarch64|arm64) arch=arm64 ;;
*)
echo "unsupported host arch: $(uname -m)" >&2
exit 1
;;
esac
echo "Building fabro-cli inside rust:1-bookworm (target arch: linux/$arch)..."
docker run --rm \
-v "$PWD:/src" \
-v fabro-docker-cargo-registry:/usr/local/cargo/registry \
-v fabro-docker-cargo-target:/target \
-w /src \
-e CARGO_TARGET_DIR=/target \
rust:1-bookworm \
cargo build --release -p fabro-cli
echo "Extracting binary from builder cache..."
mkdir -p "docker-context/$arch"
docker run --rm \
-v fabro-docker-cargo-target:/target \
-v "$PWD/docker-context/$arch:/out" \
rust:1-bookworm \
cp /target/release/fabro /out/fabro
echo "Building Docker image..."
docker build -t fabro .