diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-20 23:09:31 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-20 23:09:31 +0200 |
| commit | 19e4d8dcc9c9e76a8c90855cccb4c4553b35389e (patch) | |
| tree | d014fd0baebc2e269ee6e2f3def2c657aaee3659 /scripts | |
| parent | fe40173f32b14e012044b39f0f63c2613787e725 (diff) | |
| download | bokf-0.1.54.tar.gz bokf-0.1.54.zip | |
deploy: cross-compile static aarch64 for the Alpine imagev0.1.54
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/deploy.sh | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/scripts/deploy.sh b/scripts/deploy.sh index ad5350c..b625ac5 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -3,10 +3,12 @@ # # scripts/deploy.sh [--dev] [tag] # -# Normal mode builds an image and recreates the container, building natively on -# the host when the target architecture differs. --dev (same architecture only) -# skips the image: it copies the fresh binaries into the running container and -# reloads the daemon with SIGHUP, which re-execs them in place. +# Normal mode cross-compiles the static aarch64 backend binaries on this +# machine and assembles the image on the host when the architectures differ +# (otherwise it builds and ships the image locally). --dev skips the image: it +# copies fresh binaries into the running container and reloads the daemon with +# SIGHUP, which re-execs them in place; the binaries are cross-compiled when +# the host runs a different architecture. # # BOKF_HOST (user@host) and BOKF_REMOTE_DIR are read from the environment or # from .env in the repository root. The host needs only Docker and Compose. @@ -61,6 +63,21 @@ wait_healthy() { return 1 } +cross_build() { + echo "deploy: cross-compiling static $host_arch binaries on this machine" + rm -rf .prebuilt + mkdir -p .prebuilt + docker build -q -f deploy/Dockerfile.cross -t bokf-cross deploy/ >/dev/null + docker run --rm -e "VERSION=$TAG" -v "$PWD":/src:ro \ + -v "$PWD/.prebuilt":/out bokf-cross + if command -v file >/dev/null 2>&1 && + ! file .prebuilt/bokfd | grep -q aarch64; then + echo "deploy: cross-build produced no arm64 binary" >&2 + rm -rf .prebuilt + exit 1 + fi +} + echo "deploy: gate: build + tests" make -j"$(nproc)" make test @@ -73,7 +90,7 @@ case "$BOKF_BUILD" in if [ "$(uname -m)" = "$host_arch" ]; then BOKF_BUILD=local else - echo "deploy: host is $host_arch, building the image on the host" + echo "deploy: host is $host_arch, cross-compiling here" BOKF_BUILD=remote fi ;; @@ -86,20 +103,30 @@ case "$BOKF_BUILD" in ;; esac -if [ "$DEV" = 1 ] && [ "$BOKF_BUILD" = local ]; then +if [ "$DEV" = 1 ]; then if ! remote "test -f '$BOKF_REMOTE_DIR/var/db/bokfd.db'"; then echo "deploy: no database on $BOKF_HOST; run a normal deploy first" >&2 exit 1 fi - echo "deploy: dev: copying the locally built binaries into the running container" + if [ "$BOKF_BUILD" = local ]; then + prebin="build" + echo "deploy: dev: using the locally built binaries" + else + cross_build + prebin=".prebuilt" + fi + echo "deploy: dev: copying the binaries into the running container" remote "mkdir -p /tmp/bokf-dev" - scp -q build/bokfd build/bokfctl "$BOKF_HOST:/tmp/bokf-dev/" + scp -q "$prebin/bokfd" "$prebin/bokfctl" "$BOKF_HOST:/tmp/bokf-dev/" remote "cd '$BOKF_REMOTE_DIR' cid=\$(docker compose ps -q bokfd) test -n \"\$cid\" || { echo 'deploy: bokfd is not running' >&2; exit 1; } docker cp /tmp/bokf-dev/bokfd \"\$cid:/usr/local/bin/bokfd\" docker cp /tmp/bokf-dev/bokfctl \"\$cid:/usr/local/bin/bokfctl\" docker kill --signal=HUP \"\$cid\"" + if [ "$prebin" = ".prebuilt" ]; then + rm -rf .prebuilt + fi ver="" for _ in $(seq 1 15); do ver="$(remote "cd '$BOKF_REMOTE_DIR' && docker exec \$(docker compose ps -q bokfd) bokfctl meta 2>/dev/null" | @@ -116,23 +143,20 @@ if [ "$DEV" = 1 ] && [ "$BOKF_BUILD" = local ]; then exit 1 fi -if [ "$DEV" = 1 ]; then - echo "deploy: dev: host is $host_arch, hot reload needs a matching" \ - "architecture; doing a full deploy" >&2 -fi - if [ "$BOKF_BUILD" = local ]; then echo "deploy: building image bokf:$TAG locally" docker build --build-arg "VERSION=$TAG" -t "bokf:$TAG" . echo "deploy: shipping image to $BOKF_HOST" docker save "bokf:$TAG" | gzip | "${SSH[@]}" 'gunzip | docker load' else - echo "deploy: assembling image bokf:$TAG natively on $BOKF_HOST" + cross_build + echo "deploy: assembling image bokf:$TAG on $BOKF_HOST" tar -cf - \ --exclude=./.git --exclude=./build --exclude=./var --exclude=./.env \ --exclude='./*.se' --exclude='./*.db' --exclude='./*.db-wal' \ --exclude='./*.db-shm' --exclude=./docs . | "${SSH[@]}" "docker build --build-arg 'VERSION=$TAG' -t 'bokf:$TAG' -" + rm -rf .prebuilt fi remote "mkdir -p '$BOKF_REMOTE_DIR'" |
