Files
David Santos bd27b446a5
Node tests / test (push) Has been cancelled
feat(tools): deploy-lxc.sh for git pull + npm ci + PM2 reload
- tools/deploy-lxc.sh: ff-only pull, production npm ci, pm2 startOrReload
  ecosystem.config.cjs --update-env; optional --with-ops-check
- package.json: npm run deploy:lxc
- README: commands table + deploy section note

Made-with: Cursor
2026-03-25 03:03:09 +00:00

55 lines
1.5 KiB
Bash

#!/usr/bin/env bash
# LXC / server deploy: git pull, production npm ci, PM2 reload with updated env.
# Run from the app host (e.g. inside the CT), with .env already present.
#
# Usage:
# ./tools/deploy-lxc.sh
# ./tools/deploy-lxc.sh --with-ops-check # runs npm run ops:check after PM2 (needs WP/RSS config)
#
# Requires: git, npm, pm2 on PATH; repo must be a git checkout (for pull + DEPLOY_REVISION in ecosystem).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
WITH_OPS_CHECK=0
for _arg in "$@"; do
if [[ "${_arg}" == "--with-ops-check" ]]; then
WITH_OPS_CHECK=1
fi
done
if ! command -v git >/dev/null 2>&1; then
echo "error: git is required" >&2
exit 1
fi
if ! command -v npm >/dev/null 2>&1; then
echo "error: npm is required" >&2
exit 1
fi
if ! command -v pm2 >/dev/null 2>&1; then
echo "error: pm2 is required (npm i -g pm2)" >&2
exit 1
fi
echo "=== deploy-lxc: git pull (ff-only) ==="
git pull --ff-only
echo ""
echo "=== deploy-lxc: npm ci (production deps) ==="
npm ci --omit=dev
echo ""
echo "=== deploy-lxc: PM2 startOrReload ecosystem (update env) ==="
# startOrReload: creates process on first run; reloads on subsequent deploys so ecosystem env (e.g. DEPLOY_REVISION) refreshes
pm2 startOrReload ecosystem.config.cjs --update-env
if [[ "${WITH_OPS_CHECK}" -eq 1 ]]; then
echo ""
echo "=== deploy-lxc: ops-check ==="
npm run ops:check --silent
fi
echo ""
echo "deploy-lxc: done. Tip: npm run verify:deploy -- \"http://127.0.0.1:3200\""