#!/usr/bin/env bash # Puts this repo's committed HEAD into the Astra container on an OCI server (the "Option A" copy that sits next to the # browser runner): builds the image there, saves the running app's state, swaps the container, checks its health. # deploy/oci/update-app.sh ubuntu@server ~/.ssh/key https://astra-.sslip.io # The container's settings live on the server in /etc/astra/app.env (root only, never in the repo). Its data lives in # /home/ubuntu/astra-data on the server's own disk, so a restart loses nothing. Refuses while a test run is active, and # keeps the previous image tag so a bad release is undone with one docker run. The container's own log is capped # (5 x 10 MB), so the disk the data lives on is not filled by it. set -euo pipefail HOST=${1:?ssh target, e.g. ubuntu@server} KEY=${2:?ssh private key file} URL=${3:?the app address, e.g. https://astra-1-2-3-4.sslip.io} REV=$(git rev-parse --short=12 HEAD) git diff --quiet HEAD || { echo "uncommitted changes: commit first" >&2; exit 1; } SSH=(ssh -i "$KEY" -o BatchMode=yes "$HOST") PKG=$(mktemp -t astra-app.XXXXXX.tgz) trap 'rm -f "$PKG"' EXIT git archive --format=tar.gz -o "$PKG" HEAD scp -q -i "$KEY" -o BatchMode=yes "$PKG" "$HOST:astra-app.tgz" "${SSH[@]}" bash -s -- "$REV" <<'REMOTE' set -euo pipefail REV=$1 rm -rf ~/astra-app && mkdir ~/astra-app && tar -xzf ~/astra-app.tgz -C ~/astra-app && rm -f ~/astra-app.tgz cd ~/astra-app && sudo docker build -q -t "astra:$REV" . >/dev/null # the running app: refuse while a run is active (it would be cut off); its own state is saved when it is stopped below if sudo docker ps --format '{{.Names}}' | grep -qx astra; then # a run executing its browsers keeps the runner on this server busy if curl -s --max-time 10 http://127.0.0.1:${RUNNER_PORT:-8899}/healthz | grep -q '"busy": true'; then echo "a test run is using the browser runner: try again when it ends" >&2; exit 2 fi PREV=$(sudo docker inspect -f '{{.Config.Image}}' astra) echo "previous image: $PREV (to roll back: docker rm -f astra and run that tag)" fi sudo sed -i "s/^FPT_COMMIT=.*/FPT_COMMIT=$REV/" /etc/astra/app.env sudo grep -q '^FPT_COMMIT=' /etc/astra/app.env || echo "FPT_COMMIT=$REV" | sudo tee -a /etc/astra/app.env >/dev/null # stop (SIGTERM, not rm -f's SIGKILL) so the app makes its last state save, and give it time: a run stops at its next step first sudo docker stop -t 60 astra >/dev/null 2>&1 || true sudo docker rm -f astra >/dev/null 2>&1 || true sudo docker run -d --name astra --restart unless-stopped -p 127.0.0.1:8800:8800 --env-file /etc/astra/app.env \ --log-driver json-file --log-opt max-size=10m --log-opt max-file=5 \ -v /home/ubuntu/astra-data:/data "astra:$REV" >/dev/null for i in $(seq 1 60); do [ "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8800/api/health)" = 200 ] && break; sleep 3 done curl -s -o /dev/null -w "app health: %{http_code}\n" http://127.0.0.1:8800/api/health sudo docker image prune -f >/dev/null # older app images: the running one and the one before it (the rollback) are kept. Each is 2.6 GB and fifteen of them filled # the server's disk mid-build (seen 2026-11-22: "no space left on device") KEEP=" astra:$REV ${PREV:-} " sudo docker images astra --format '{{.Repository}}:{{.Tag}}' | while read -r img; do case "$KEEP" in *" $img "*) ;; *) sudo docker rmi "$img" >/dev/null 2>&1 || true ;; esac done REMOTE echo "from outside: $(curl -s -o /dev/null -w '%{http_code} in %{time_total}s' --max-time 30 "$URL/api/health")" echo "Astra on OCI now on $REV; sync the runner to the same commit: deploy/runner/sync.sh"