telegrambot/scripts/deploy-on-vps.sh
alisaza a541075765
Some checks failed
CI / Typecheck and test (push) Failing after 1m36s
Deploy / Typecheck and test (push) Failing after 35s
Deploy / Deploy to VPS (push) Has been skipped
Add Gitea Actions CI/CD and production deploy scripts.
Wire typecheck/test on PR/push and SSH deploy to the foreign VPS on main.
2026-09-13 14:39:59 +03:30

44 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deploy telegram relay on the VPS (idempotent).
# Expects app files already present in APP_DIR (CI rsync or prior clone).
set -euo pipefail
APP_DIR="${APP_DIR:-/opt/ghabilee-telegram-relay}"
cd "$APP_DIR"
install -m 0644 deploy/docker-compose.production.yml "$APP_DIR/docker-compose.yml"
if [ ! -f "$APP_DIR/.env" ]; then
echo "Missing $APP_DIR/.env — copy from .env.example and fill secrets before serving traffic." >&2
cp .env.example "$APP_DIR/.env"
chmod 600 "$APP_DIR/.env"
echo "Created placeholder .env; edit it, then re-run deploy." >&2
exit 2
fi
docker compose -f "$APP_DIR/docker-compose.yml" build --pull
docker compose -f "$APP_DIR/docker-compose.yml" up -d --remove-orphans
install -m 0644 deploy/nginx/telegram-relay.conf /etc/nginx/sites-available/telegram-relay
ln -sfn /etc/nginx/sites-available/telegram-relay /etc/nginx/sites-enabled/telegram-relay
nginx -t
systemctl reload nginx
for attempt in $(seq 1 30); do
health="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' ghabilee-telegram-relay 2>/dev/null || echo missing)"
echo "health ${attempt}/30: ${health}"
if [ "$health" = "healthy" ] || [ "$health" = "running" ]; then
curl -sf "http://127.0.0.1:3100/health" >/dev/null
echo "Deploy OK"
exit 0
fi
case "$health" in
unhealthy|exited|dead|missing) exit 1 ;;
esac
sleep 2
done
echo "Timed out waiting for healthy container" >&2
exit 1