| 1 | #!/usr/bin/env bash |
| 2 | # Cross-compile anvil natively on the build host (Mac) and ship the image to |
| 3 | # hagrid. NOT run on the VPS — it never compiles anything. |
| 4 | # |
| 5 | # Uses cargo-zigbuild to cross-compile a fully static x86_64-musl binary at |
| 6 | # native speed (no QEMU), stages it at deploy/anvild, builds a thin image that |
| 7 | # just COPYs it in, and pipes the image to hagrid via docker load. |
| 8 | # |
| 9 | # Prereqs (one-time): |
| 10 | # brew install zig |
| 11 | # cargo install cargo-zigbuild |
| 12 | # rustup target add x86_64-unknown-linux-musl |
| 13 | set -euo pipefail |
| 14 | |
| 15 | IMAGE="${ANVIL_IMAGE:-anvil:latest}" |
| 16 | REMOTE="${ANVIL_REMOTE:-hagrid}" |
| 17 | TARGET="x86_64-unknown-linux-musl" |
| 18 | |
| 19 | cd "$(dirname "$0")/.." |
| 20 | |
| 21 | echo "==> cross-compiling anvild for $TARGET (native, via zig)" |
| 22 | cargo zigbuild --release --target "$TARGET" --bin anvild |
| 23 | |
| 24 | echo "==> staging binary at deploy/anvild" |
| 25 | cp "target/$TARGET/release/anvild" deploy/anvild |
| 26 | |
| 27 | echo "==> building $IMAGE (just COPYs the binary — fast)" |
| 28 | docker build --platform linux/amd64 -t "$IMAGE" . |
| 29 | |
| 30 | echo "==> shipping $IMAGE to $REMOTE" |
| 31 | docker save "$IMAGE" | gzip | ssh "$REMOTE" 'docker load' |
| 32 | |
| 33 | rm -f deploy/anvild |
| 34 | echo "==> done. On $REMOTE, run ./deploy/run.sh to (re)start the container." |