Files
ohmj2/deploy/deploy.sh
2026-02-27 12:25:57 +01:00

67 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# OHMJ Deployment Script
set -e
cd /home/jbnadal/sources/jb/ohmj/ohmj2
echo "=== OHMJ Deploy Script ==="
# Create temp directory for deploy
DEPLOY_DIR="_deploy_temp"
rm -rf $DEPLOY_DIR
mkdir -p $DEPLOY_DIR
# 1. Copy source files
echo "[1/8] Copying source files..."
cp -r api $DEPLOY_DIR/
cp -r partitions $DEPLOY_DIR/
cp -r deploy $DEPLOY_DIR/
# 2. Generate JWT_SECRET
echo "[2/8] Generating JWT_SECRET..."
JWT_SECRET=$(openssl rand -base64 32)
echo "JWT_SECRET=$JWT_SECRET" > $DEPLOY_DIR/api/.env
echo "SCORES_PATH=/data/scores/" >> $DEPLOY_DIR/api/.env
# 3. Set production API URL in frontend .env
echo "[3/8] Setting production API URL..."
echo "VITE_API_URL=https://ohmj-api.c.nadal-fr.com" > $DEPLOY_DIR/partitions/.env
# 4. Clean and build frontend
echo "[4/8] Cleaning and building frontend..."
cd $DEPLOY_DIR/partitions
rm -rf build
npm run build
# Copy .mjs to .js for correct MIME type
cp build/pdf.worker.min.mjs build/pdf.worker.min.js 2>/dev/null || echo "pdf.worker.min.mjs not found"
cd ../..
# 5. Copy built frontend as 'frontend' directory (not symlink, for zip compatibility)
echo "[5/8] Copying built frontend..."
cp -r $DEPLOY_DIR/partitions/build $DEPLOY_DIR/frontend
# 6. Copy nginx config to frontend
echo "[6/8] Adding nginx config..."
cp partitions/nginx.conf $DEPLOY_DIR/frontend/nginx.conf 2>/dev/null || echo "nginx.conf not found"
# 7. Create zip (without tests.php and legacy)
echo "[7/8] Creating zip..."
cd $DEPLOY_DIR
zip -r ../_builds/deploy_ohmj.zip api frontend -x "*.DS_Store" "node_modules/*" ".svelte-kit/*" "api/tests.php"
# 8. Cleanup
echo "[8/8] Cleaning up..."
cd ..
rm -rf $DEPLOY_DIR
echo "=== Done! ==="
echo "Zip created: _builds/deploy_ohmj.zip"
echo ""
echo "To deploy:"
echo " 1. Upload zip to server"
echo " 2. Extract to /var/www/"
echo " 3. Configure web server"