Add LXC deploy script, Gitea Actions workflow and deploy docs
deploy / deploy (push) Canceled after 0s
deploy / deploy (push) Canceled after 0s
This commit is contained in:
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
# Deploy AI Rendezvous to the LXC host over SSH.
|
||||
#
|
||||
# Works in three ways:
|
||||
# 1. locally: ./scripts/deploy.sh
|
||||
# 2. from Gitea Actions: .gitea/workflows/deploy.yml calls this script
|
||||
# 3. from a webhook: any tiny receiver on the LXC can exec this script
|
||||
#
|
||||
# Configuration via environment (or a gitignored deploy.env next to this file):
|
||||
# SSH_HOST user@lxc-host (required)
|
||||
# SSH_PORT 22
|
||||
# DEPLOY_DIR /opt/ai-rendezvous checkout on the LXC
|
||||
# BRANCH main
|
||||
# DEPLOY_MODE docker | systemd how to run the service
|
||||
# SERVICE_NAME ai-rendezvous systemd unit name (systemd mode)
|
||||
# HEALTH_URL e.g. http://127.0.0.1:3000/health checked after deploy
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
[ -f deploy.env ] && . ./deploy.env
|
||||
|
||||
: "${SSH_HOST:?Set SSH_HOST (user@lxc-host) via env, deploy.env or CI secrets}"
|
||||
SSH_PORT="${SSH_PORT:-22}"
|
||||
DEPLOY_DIR="${DEPLOY_DIR:-/opt/ai-rendezvous}"
|
||||
BRANCH="${BRANCH:-main}"
|
||||
DEPLOY_MODE="${DEPLOY_MODE:-docker}"
|
||||
SERVICE_NAME="${SERVICE_NAME:-ai-rendezvous}"
|
||||
HEALTH_URL="${HEALTH_URL:-}"
|
||||
|
||||
SSH_CMD=(ssh -p "$SSH_PORT" -o StrictHostKeyChecking=accept-new "$SSH_HOST")
|
||||
|
||||
echo "==> Deploying $BRANCH to $SSH_HOST:$DEPLOY_DIR (mode: $DEPLOY_MODE)"
|
||||
|
||||
"${SSH_CMD[@]}" BRANCH="$BRANCH" DEPLOY_DIR="$DEPLOY_DIR" DEPLOY_MODE="$DEPLOY_MODE" \
|
||||
SERVICE_NAME="$SERVICE_NAME" bash -s <<'REMOTE'
|
||||
set -euo pipefail
|
||||
cd "$DEPLOY_DIR"
|
||||
|
||||
echo "--> fetching $BRANCH"
|
||||
umask 022
|
||||
git fetch --prune origin
|
||||
git reset --hard "origin/$BRANCH"
|
||||
|
||||
if [ "$DEPLOY_MODE" = "docker" ]; then
|
||||
echo "--> rebuilding containers"
|
||||
docker compose up -d --build --remove-orphans
|
||||
elif [ "$DEPLOY_MODE" = "systemd" ]; then
|
||||
echo "--> building"
|
||||
npm ci --no-audit --no-fund
|
||||
npm run build
|
||||
echo "--> restarting $SERVICE_NAME"
|
||||
systemctl restart "$SERVICE_NAME"
|
||||
else
|
||||
echo "unknown DEPLOY_MODE: $DEPLOY_MODE" >&2
|
||||
exit 1
|
||||
fi
|
||||
REMOTE
|
||||
|
||||
if [ -n "$HEALTH_URL" ]; then
|
||||
echo "==> Health check $HEALTH_URL"
|
||||
if "${SSH_CMD[@]}" curl -sf --max-time 5 --retry 10 --retry-delay 3 --retry-connrefused "$HEALTH_URL" >/dev/null; then
|
||||
echo "==> healthy"
|
||||
else
|
||||
echo "!! health check FAILED after deploy" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "==> deploy OK"
|
||||
Reference in New Issue
Block a user