docs: add from-scratch deploy script and env templates
CI / skip-ci-check (pull_request) Successful in 7s
CI / python-lint (pull_request) Has been cancelled
CI / test-backend (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / secret-scanning (pull_request) Has been cancelled
CI / dependency-scan (pull_request) Has been cancelled
CI / sast-scan (pull_request) Has been cancelled
CI / workflow-summary (pull_request) Has been cancelled
CI / lint-and-type-check (pull_request) Has been cancelled

This commit is contained in:
tanyar09
2026-01-28 19:20:35 +00:00
parent bfc07fcde5
commit f224a160e3
5 changed files with 445 additions and 0 deletions
+128
View File
@@ -0,0 +1,128 @@
#!/usr/bin/env bash
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
echo "== PunimTag deploy (from scratch) =="
echo "Project root: ${PROJECT_ROOT}"
echo ""
if [[ "$(id -u)" -eq 0 ]]; then
echo "❌ Do not run as root. Run as a normal user with sudo."
exit 1
fi
command_exists() {
command -v "$1" >/dev/null 2>&1
}
ensure_file_from_example() {
local example_path="$1"
local target_path="$2"
if [[ -f "${target_path}" ]]; then
echo "✅ Found ${target_path}"
return 0
fi
if [[ ! -f "${example_path}" ]]; then
echo "❌ Missing ${example_path}"
exit 1
fi
cp "${example_path}" "${target_path}"
echo "✅ Created ${target_path} from ${example_path}"
}
echo "== 1) Install system dependencies (Ubuntu/Debian) =="
if command_exists apt-get; then
sudo apt-get update
sudo apt-get install -y \
python3 python3-venv python3-pip \
postgresql-client \
redis-server \
nodejs npm
else
echo "❌ This script currently supports Ubuntu/Debian (apt-get)."
echo " Install dependencies manually, then re-run this script."
exit 1
fi
echo ""
echo "== 2) Ensure Redis is running =="
sudo systemctl enable --now redis-server || true
if command_exists redis-cli; then
if ! redis-cli ping >/dev/null 2>&1; then
echo "❌ Redis is not reachable on localhost:6379"
echo " Fix Redis (service, firewall, config) and retry."
exit 1
fi
echo "✅ Redis OK (redis-cli ping)"
else
echo "❌ redis-cli not found after install"
exit 1
fi
echo ""
echo "== 3) Ensure env files exist (copied from *_example) =="
ensure_file_from_example "${PROJECT_ROOT}/.env_example" "${PROJECT_ROOT}/.env"
ensure_file_from_example "${PROJECT_ROOT}/admin-frontend/.env_example" \
"${PROJECT_ROOT}/admin-frontend/.env"
ensure_file_from_example "${PROJECT_ROOT}/viewer-frontend/.env_example" \
"${PROJECT_ROOT}/viewer-frontend/.env"
echo ""
echo "⚠️ IMPORTANT: Edit these files NOW before continuing:"
echo " - ${PROJECT_ROOT}/.env"
echo " - ${PROJECT_ROOT}/admin-frontend/.env"
echo " - ${PROJECT_ROOT}/viewer-frontend/.env"
echo ""
echo "Press Enter once they are updated..."
read -r
echo ""
echo "== 4) Backend Python venv + deps =="
cd "${PROJECT_ROOT}"
python3 -m venv venv
./venv/bin/pip install --upgrade pip
./venv/bin/pip install -r requirements.txt
echo "✅ Backend dependencies installed"
echo ""
echo "== 5) Admin frontend deps =="
cd "${PROJECT_ROOT}/admin-frontend"
npm ci
echo "✅ Admin dependencies installed"
echo ""
echo "== 6) Viewer frontend deps + Prisma clients =="
cd "${PROJECT_ROOT}/viewer-frontend"
npm ci
npm run prisma:generate:all
echo "✅ Viewer dependencies installed and Prisma clients generated"
echo ""
echo "== 7) Auth DB setup scripts (viewer) =="
cd "${PROJECT_ROOT}/viewer-frontend"
npx tsx scripts/setup-auth.ts
npx tsx scripts/fix-admin-user.ts
echo "✅ Auth DB setup done"
echo ""
echo "== 8) Start services (PM2) =="
if ! command_exists pm2; then
echo "Installing PM2..."
sudo npm i -g pm2
fi
cd "${PROJECT_ROOT}"
pm2 start ecosystem.config.js
pm2 save
echo ""
echo "✅ Done."
echo "Admin: http://<server>:3000"
echo "Viewer: http://<server>:3001"
echo "API: http://<server>:8000/docs"