Files
AI_template/scripts/deploy.sh
olekhondera 425227c6b8 feat: add Woodpecker CI + Gitea deployment templates
- .woodpecker.yml: full pipeline template (install → lint-fix → lint → test → deploy)
- scripts/setup-project.sh: one-command VPS setup (user, dir, deploy, sudoers, systemd, nginx)
- scripts/deploy.sh: deploy script template (rsync + npm ci + systemctl + health check)
- scripts/ci-lint-fix.sh: ESLint auto-fix with [CI SKIP] commit-back
- docs/ci-cd.md: complete CI/CD documentation and troubleshooting
- .env.example: added WOODPECKER_TOKEN
- DOCS.md: added CI/CD section

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 23:24:41 +02:00

62 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# deploy.sh — Deploy project from CI workspace to target directory.
#
# Works for both manual and Woodpecker CI deployment.
#
# Usage:
# Manual: sudo bash scripts/deploy.sh
# CI: sudo /usr/local/bin/deploy-<project-name> /path/to/workspace
#
# CI setup (one-time, as root on VPS):
# cp scripts/deploy.sh /usr/local/bin/deploy-<project-name>
# chmod 755 /usr/local/bin/deploy-<project-name>
# chown root:root /usr/local/bin/deploy-<project-name>
# --- Configure these for your project ---
INSTALL_DIR="/opt/<project-name>"
SERVICE_USER="<project-user>"
SERVICE_NAME="<project-name>"
HEALTH_URL="http://localhost:3000/api/health"
# -----------------------------------------
SOURCE_DIR="${1:-.}"
echo "=== Deploy ==="
if [[ $EUID -ne 0 ]]; then
echo "Error: must be root (sudo)"; exit 1
fi
if [[ ! -d "${INSTALL_DIR}" ]]; then
echo "Error: ${INSTALL_DIR} not found"; exit 1
fi
echo "[1/3] Syncing files..."
rsync -a --delete \
--exclude='node_modules' \
--exclude='.env' \
--exclude='.git' \
--exclude='.idea' \
"${SOURCE_DIR}/" "${INSTALL_DIR}/"
chown -R "${SERVICE_USER}:${SERVICE_USER}" "${INSTALL_DIR}"
echo "[2/3] Installing dependencies..."
sudo -u "${SERVICE_USER}" HOME="${INSTALL_DIR}" bash -c "cd ${INSTALL_DIR} && npm ci --omit=dev"
echo "[3/3] Restarting service..."
systemctl daemon-reload
systemctl restart "${SERVICE_NAME}"
sleep 2
if systemctl is-active --quiet "${SERVICE_NAME}"; then
echo "Service running"
else
echo "Error: service failed to start"; exit 1
fi
curl -sf "${HEALTH_URL}" || { echo "FAIL: health check"; exit 1; }
echo "=== Deploy complete ==="