#!/usr/bin/env bash # Deploy a git ref to the shared server (dir /srv/ptsr). Used by hand and by CD (.gitea/workflows/deploy.yml). # infra/deploy/deploy.sh [git-ref] default: origin/dev # Env: DEPLOY_HOST (ssh host/alias, default `vobot`), DEPLOY_SSH_OPTS (extra ssh/scp options). # Keeps /srv/ptsr/.env (secrets live only on the server) and the Postgres volume. # The host drops some ssh connections (rate limiting) — every remote step is retried. set -euo pipefail REF=${1:-origin/dev} HOST=${DEPLOY_HOST:-vobot} OPTS=${DEPLOY_SSH_OPTS:-} DIR=/srv/ptsr git fetch -q origin 2>/dev/null || true SHA=$(git rev-parse --short "$REF") TGZ=$(mktemp --suffix=.tgz) trap 'rm -f "$TGZ"' EXIT git archive --format=tar.gz -o "$TGZ" "$REF" retry() { local n=0; until "$@"; do n=$((n + 1)); [ $n -ge 5 ] && return 1; echo "retry $n: $1" >&2; sleep $((n * 10)); done; } echo "deploy $REF ($SHA) -> $HOST:$DIR" # shellcheck disable=SC2086 retry scp -q $OPTS "$TGZ" "$HOST:$DIR/release.tgz" # shellcheck disable=SC2086 retry ssh $OPTS "$HOST" "bash -s" </dev/null && npm run build >/dev/null" docker compose -p ptsr -f docker-compose.yml -f infra/deploy/docker-compose.server.yml up -d --build /dev/null && break; sleep 3; done curl -sf 127.0.0.1:8010/health >/dev/null && echo "$SHA" > REVISION && echo "api ok @ $SHA" SH