add deploy script, fix production paths, use port 3006
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
113
deploy.sh
Executable file
113
deploy.sh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# celebrate-esc deploy script — idempotent, can be re-run safely
|
||||
# Target: Uberspace 8 (serve.uber.space)
|
||||
|
||||
HOST="serve"
|
||||
SERVICE_DIR="services/celebrate-esc"
|
||||
STATIC_DIR="/var/www/virtual/serve/html/celebrate-esc"
|
||||
DB_NAME="celebrate_esc"
|
||||
PORT=3006
|
||||
|
||||
echo "=== celebrate-esc deploy ==="
|
||||
|
||||
# ── 1. Create database if needed ─────────────────────────────────────
|
||||
echo "→ ensuring database exists..."
|
||||
ssh "$HOST" "createdb -h localhost -p 5433 $DB_NAME 2>/dev/null || true"
|
||||
|
||||
# ── 2. Build client locally ──────────────────────────────────────────
|
||||
echo "→ building client..."
|
||||
cd packages/client
|
||||
VITE_BASE="/celebrate-esc/" bun run build
|
||||
cd ../..
|
||||
|
||||
# ── 3. Sync server code ─────────────────────────────────────────────
|
||||
echo "→ syncing server to $HOST:~/$SERVICE_DIR/..."
|
||||
ssh "$HOST" "mkdir -p ~/$SERVICE_DIR"
|
||||
rsync -az --delete \
|
||||
--exclude='node_modules' \
|
||||
--exclude='.env' \
|
||||
packages/server/ "$HOST:~/$SERVICE_DIR/server/"
|
||||
rsync -az --delete \
|
||||
--exclude='node_modules' \
|
||||
packages/shared/ "$HOST:~/$SERVICE_DIR/shared/"
|
||||
|
||||
# Copy root workspace files needed for bun install
|
||||
scp package.json "$HOST:~/$SERVICE_DIR/"
|
||||
scp tsconfig.json "$HOST:~/$SERVICE_DIR/"
|
||||
scp bun.lock "$HOST:~/$SERVICE_DIR/"
|
||||
|
||||
# ── 4. Install server dependencies on remote ─────────────────────────
|
||||
echo "→ installing server dependencies..."
|
||||
ssh "$HOST" "cd ~/$SERVICE_DIR && cat > package.json << 'PKGJSON'
|
||||
{
|
||||
\"name\": \"celebrate-esc\",
|
||||
\"private\": true,
|
||||
\"workspaces\": [
|
||||
\"shared\",
|
||||
\"server\"
|
||||
]
|
||||
}
|
||||
PKGJSON
|
||||
bun install --frozen-lockfile 2>/dev/null || bun install"
|
||||
|
||||
# ── 5. Create .env on remote if missing ──────────────────────────────
|
||||
echo "→ ensuring .env exists..."
|
||||
ssh "$HOST" "test -f ~/$SERVICE_DIR/.env || cat > ~/$SERVICE_DIR/.env << 'ENVFILE'
|
||||
DATABASE_URL=postgresql://localhost:5433/$DB_NAME
|
||||
PORT=$PORT
|
||||
ENVFILE"
|
||||
|
||||
# ── 6. Run migrations ────────────────────────────────────────────────
|
||||
echo "→ running database migrations..."
|
||||
ssh "$HOST" "cd ~/$SERVICE_DIR/server && DATABASE_URL=postgresql://localhost:5433/$DB_NAME bun drizzle-kit migrate"
|
||||
|
||||
# ── 7. Deploy static client files ────────────────────────────────────
|
||||
echo "→ deploying client static files..."
|
||||
ssh "$HOST" "mkdir -p $STATIC_DIR"
|
||||
rsync -az --delete packages/client/dist/ "$HOST:$STATIC_DIR/"
|
||||
|
||||
# Create .htaccess for SPA routing
|
||||
ssh "$HOST" "cat > $STATIC_DIR/.htaccess << 'HTACCESS'
|
||||
RewriteEngine On
|
||||
RewriteBase /celebrate-esc/
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule . index.html [L]
|
||||
HTACCESS"
|
||||
|
||||
# ── 8. Create systemd service ────────────────────────────────────────
|
||||
echo "→ setting up systemd service..."
|
||||
ssh "$HOST" "cat > ~/.config/systemd/user/celebrate-esc.service << 'UNIT'
|
||||
[Unit]
|
||||
Description=celebrate-esc API server
|
||||
After=postgresql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=%h/services/celebrate-esc/server
|
||||
ExecStart=/home/serve/.local/share/mise/installs/bun/1.3.0/bin/bun run --env-file=../.env src/index.ts
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
UNIT
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable celebrate-esc.service
|
||||
systemctl --user restart celebrate-esc.service"
|
||||
|
||||
# ── 9. Set up web backend routing ────────────────────────────────────
|
||||
echo "→ configuring web backend routing..."
|
||||
ssh "$HOST" "uberspace web backend set /celebrate-esc/api --http --port $PORT --remove-prefix 2>/dev/null || true"
|
||||
|
||||
# ── 10. Verify ────────────────────────────────────────────────────────
|
||||
echo "→ verifying deployment..."
|
||||
sleep 2
|
||||
ssh "$HOST" "systemctl --user status celebrate-esc.service --no-pager | head -5"
|
||||
echo ""
|
||||
echo "=== deploy complete ==="
|
||||
echo "Frontend: https://serve.uber.space/celebrate-esc/"
|
||||
echo "API: https://serve.uber.space/celebrate-esc/api/health"
|
||||
Reference in New Issue
Block a user