anvilsign in

collin/anvil

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
13set -euo pipefail
14
15IMAGE="${ANVIL_IMAGE:-anvil:latest}"
16REMOTE="${ANVIL_REMOTE:-hagrid}"
17TARGET="x86_64-unknown-linux-musl"
18
19cd "$(dirname "$0")/.."
20
21# macOS terminals default to a 256 open-file soft limit; zig's linker opens
22# every rlib at once and dies with ProcessFdQuotaExceeded. Raise it for this
23# process (children inherit it).
24ulimit -n 4096 2>/dev/null || true
25
26echo "==> cross-compiling anvild for $TARGET (native, via zig)"
27cargo zigbuild --release --target "$TARGET" --bin anvild
28
29echo "==> staging binary at deploy/anvild"
30cp "target/$TARGET/release/anvild" deploy/anvild
31
32echo "==> building $IMAGE (just COPYs the binary — fast)"
33docker build --platform linux/amd64 -t "$IMAGE" .
34
35echo "==> shipping $IMAGE to $REMOTE"
36# ANVIL_SSH_OPTS lets deploy.sh point us at its multiplexed master connection.
37# shellcheck disable=SC2086
38docker save "$IMAGE" | gzip | ssh ${ANVIL_SSH_OPTS:-} "$REMOTE" 'docker load'
39
40rm -f deploy/anvild
41echo "==> done. On $REMOTE, run ./deploy/run.sh to (re)start the container."