Something went wrong. Try again.
Something went wrong. Try again.
cavu-games deploy.sh
3.0 kB · 62 lines
Shell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263#!/usr/bin/env bash# Build locally and deploy to Fly (much faster than a remote Rust build).# ./deploy.sh # both apps# ./deploy.sh play|host # one# SKIP_GAMES="rpg-actor-in-space" ./deploy.sh play # leave packs out (play them from a dev node)# Packs whose game.json says "devOnly": true are always left out.# Cross-compiles the binaries for linux/amd64 with cargo-zigbuild (glibc 2.36 = debian bookworm),# builds the wasm client, stages a tiny image context in target/deploy and deploys with --local-only.# Needs: zig, cargo-zigbuild, the x86_64-unknown-linux-gnu target, docker, flyctl.# (Dockerfile at the root still does a full in-Docker build, for CI or remote builders.)set -euo pipefailcd "$(dirname "$0")"which="${1:-both}"
# Private data (e.g. haiku-day/puzzles.json) is gitignored with a committed *.example.json stand-in;# the server falls back to the example, so never ship a pack whose real file is missing.for ex in games/*/*.example.json; do [ -e "$ex" ] || continue slug=$(basename "$(dirname "$ex")") case " ${SKIP_GAMES:-} " in *" $slug "*) continue ;; esac real="${ex%.example.json}.json" [ -f "$real" ] || { echo "deploy: $real is missing (only the example is present); copy in the real data first"; exit 1; }done
./build.sh >/dev/nullcargo zigbuild --release --target x86_64-unknown-linux-gnu.2.36 -p cavu-server -p cavu-host
out=target/deployrm -rf "$out" && mkdir -p "$out/games"cp target/x86_64-unknown-linux-gnu/release/cavu-server target/x86_64-unknown-linux-gnu/release/cavu-host "$out/"cp -R web "$out/web"for g in games/*/; do slug=$(basename "$g") case " ${SKIP_GAMES:-} " in *" $slug "*) echo "skipping $slug"; continue ;; esac # Packs marked "devOnly" in game.json run from a developer's dev node, never the fleet. grep -q '"devOnly": *true' "$g/game.json" 2>/dev/null && { echo "skipping $slug (devOnly)"; continue; } [ -f "$g/game.json" ] && cp -R "${g%/}" "$out/games/"donecp fly.toml fly.host.toml "$out/"# Mozilla's CA bundle (via curl.se) instead of apt-get (which is slow and flaky under emulation).curl -fsSL https://curl.se/ca/cacert.pem -o "$out/ca-certificates.crt"cat > "$out/Dockerfile" <<'DOCKER'FROM debian:bookworm-slimCOPY ca-certificates.crt /etc/ssl/certs/ca-certificates.crtENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crtWORKDIR /appCOPY cavu-server cavu-host /app/COPY web /app/webCOPY games /app/gamesEXPOSE 8080CMD ["/app/cavu-server", "--host", "0.0.0.0", "--port", "8080", "--games", "/app/games", "--web", "/app/web", \ "--data", "/data", "--public-url", "https://play.cavu.games", "--did", "did:web:play.cavu.games", \ "--host-url", "https://cavu.games"]DOCKER
cd "$out"case "$which" in play) fly deploy -c fly.toml --local-only --ha=false ;; host) fly deploy -c fly.host.toml --local-only --ha=false ;; both) fly deploy -c fly.toml --local-only --ha=false && fly deploy -c fly.host.toml --local-only --ha=false ;; *) echo "usage: $0 [play|host|both]"; exit 1 ;;esac