diff --git a/ROADMAP.md b/ROADMAP.md index d78decd..506738b 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -67,7 +67,7 @@ Living plan for product quality, auth/email reliability, and automation. ## Later -- [ ] Proper DEV deploy (`next start` + CI image) instead of long-lived `next dev` +- [x] Proper DEV deploy (`next start` + CI image) instead of long-lived `next dev` — `scripts/deploy-viewer.sh`, `ecosystem.config.js.example` uses `next start -p 3001` - [ ] Ansible/app_setup path aligned with `/opt/punimtag/viewer-frontend/.env` (not `/srv/app`) - [ ] OpenAPI-driven contract suite (playkit / consumer) - [ ] Multi-browser matrix (firefox/webkit) diff --git a/ecosystem.config.js.example b/ecosystem.config.js.example index 90a0eef..27de305 100644 --- a/ecosystem.config.js.example +++ b/ecosystem.config.js.example @@ -60,12 +60,15 @@ module.exports = { }, { name: 'punimtag-viewer', - script: 'npm', - args: 'run start:3001', + // Production: run `npm run build` in viewer-frontend before `pm2 start`. + // Do not use `next dev` on long-lived hosts (slow, wrong behavior vs prod). + script: './scripts/with-sharp-libpath.sh', + args: 'next start -p 3001', cwd: '/opt/punimtag/viewer-frontend', // CHANGE: Update to your deployment directory - interpreter: 'node', + interpreter: 'bash', env: { PORT: '3001', + NODE_ENV: 'production', }, error_file: '/home/appuser/.pm2/logs/punimtag-viewer-error.log', // CHANGE: Update user home directory out_file: '/home/appuser/.pm2/logs/punimtag-viewer-out.log', // CHANGE: Update user home directory diff --git a/scripts/deploy-viewer.sh b/scripts/deploy-viewer.sh new file mode 100755 index 0000000..8a532af --- /dev/null +++ b/scripts/deploy-viewer.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Build viewer for production and restart PM2 process. +# Usage: ./scripts/deploy-viewer.sh [--skip-install] +set -euo pipefail + +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +VIEWER="$ROOT/viewer-frontend" +SKIP_INSTALL=0 +for arg in "$@"; do + case "$arg" in + --skip-install) SKIP_INSTALL=1 ;; + esac +done + +cd "$VIEWER" +if [[ "$SKIP_INSTALL" -eq 0 ]]; then + npm ci --prefer-offline +fi +npm run build + +cd "$ROOT" +if pm2 describe punimtag-viewer >/dev/null 2>&1; then + pm2 restart punimtag-viewer --update-env +else + pm2 start ecosystem.config.js --only punimtag-viewer +fi + +echo "Viewer deployed (next start). Logs: pm2 logs punimtag-viewer --lines 30"