Files
PTSRaiAgent/infra/deploy/deploy.sh
T

25 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy origin/dev to the shared server (ssh alias `vobot`, dir /srv/ptsr). Run from a clean checkout:
# infra/deploy/deploy.sh [git-ref] default: origin/dev
# Keeps /srv/ptsr/.env (secrets live only on the server) and the Postgres volume.
set -euo pipefail
REF=${1:-origin/dev}
HOST=${DEPLOY_HOST:-vobot}
DIR=/srv/ptsr
git fetch -q origin
SHA=$(git rev-parse --short "$REF")
echo "deploy $REF ($SHA) -> $HOST:$DIR"
git archive --format=tar "$REF" | ssh "$HOST" "rm -rf $DIR/app.new && mkdir -p $DIR/app.new && tar -x -C $DIR/app.new"
ssh "$HOST" bash -s <<SH
set -euo pipefail
cd $DIR
cp .env app.new/.env
rm -rf app.old; [ -d app ] && mv app app.old; mv app.new app
cd app
echo "$SHA" > REVISION
docker run --rm -v "\$PWD/web:/w" -w /w node:20-alpine sh -c "npm ci --no-audit --no-fund >/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
for i in \$(seq 1 40); do curl -sf 127.0.0.1:8010/health >/dev/null && break; sleep 3; done
curl -sf 127.0.0.1:8010/health && echo " api ok"
SH