Files
preregister/deploy.sh
bert.hausmans 2603288881 chore: load fnm in deploy script for Node/npm
Export PATH and eval fnm env so npm run build uses the intended Node version on the VPS.

Made-with: Cursor
2026-04-04 13:27:31 +02:00

84 lines
2.4 KiB
Bash

#!/bin/bash
set -e
# ──────────────────────────────────────────
# PreRegister Deploy Script
# Run on VPS: ./deploy.sh [tag]
# Examples:
# ./deploy.sh → deploys latest main
# ./deploy.sh v1.2.0 → deploys specific tag
# ──────────────────────────────────────────
APP_DIR="/home/hausdesign/preregister"
PHP="/usr/local/php84/bin/php"
COMPOSER="/usr/local/bin/composer"
TAG="${1:-}"
# Load fnm (Node version manager)
export PATH="$HOME/.local/share/fnm:$PATH"
eval "$(fnm env)"
echo "══════════════════════════════════════"
echo " PreRegister — Deploy"
echo "══════════════════════════════════════"
cd "$APP_DIR"
# 1. Maintenance mode
echo "→ Enabling maintenance mode..."
$PHP artisan down --retry=30 || true
# 2. Pull latest code
echo "→ Pulling from Gitea..."
git fetch --all --tags
if [ -n "$TAG" ]; then
echo "→ Checking out tag: $TAG"
git checkout "$TAG"
else
echo "→ Checking out latest main"
git checkout main
git pull origin main
fi
# 3. Install PHP dependencies
echo "→ Installing Composer dependencies..."
$PHP $COMPOSER install --no-dev --optimize-autoloader --no-interaction
# 4. Install Node dependencies and build
echo "→ Installing npm packages..."
npm ci --production=false
echo "→ Building frontend assets..."
npm run build
# 5. Run migrations
echo "→ Running migrations..."
$PHP artisan migrate --force
# 6. Clear and rebuild caches
echo "→ Clearing caches..."
$PHP artisan config:cache
$PHP artisan route:cache
$PHP artisan view:cache
$PHP artisan event:cache
# 7. Restart queue (process any pending jobs with new code)
echo "→ Restarting queue workers..."
$PHP artisan queue:restart
# 8. Storage link (idempotent)
$PHP artisan storage:link 2>/dev/null || true
# 9. Disable maintenance mode
echo "→ Going live!"
$PHP artisan up
echo ""
echo "══════════════════════════════════════"
if [ -n "$TAG" ]; then
echo " Deployed: $TAG"
else
echo " Deployed: main (latest)"
fi
echo "══════════════════════════════════════"