Files
cirux/deploy.sh
T

100 lines
4.0 KiB
Bash

#!/bin/bash
set -e
# ─── EnFlow VPS Deploy Script ────────────────────────────────────────────────
# Usage: ./deploy.sh [domain] [email]
# Example: ./deploy.sh cirux.silvioalzate.shop silvio@example.com
DOMAIN=${1:-cirux.silvioalzate.shop}
EMAIL=${2:-help@silvioalzate.shop}
APP_DIR=$(pwd)
echo "🚀 EnFlow Deploy Script"
echo " Domain: $DOMAIN"
echo " Email: $EMAIL"
echo ""
# ─── Prerequisites Check ─────────────────────────────────────────────────────
echo "📋 Checking prerequisites..."
if ! command -v docker &> /dev/null; then
echo "❌ Docker not found. Installing..."
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
fi
if ! command -v docker-compose &> /dev/null; then
echo "❌ Docker Compose not found. Installing..."
sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
# ─── SSL Certificates ──────────────────────────────────────────────────────
echo "🔐 Setting up SSL certificates..."
mkdir -p certbot/conf certbot/www
if [ ! -d "certbot/conf/live/$DOMAIN" ]; then
echo " Obtaining initial certificate for $DOMAIN..."
# Start nginx temporarily for certbot challenge
docker-compose up -d nginx
sleep 5
# Get certificate
docker-compose run --rm certbot certonly \
--webroot \
--webroot-path=/var/www/certbot \
--email "$EMAIL" \
--agree-tos \
--no-eff-email \
-d "$DOMAIN"
# Stop temporary nginx
docker-compose down
fi
# ─── Update nginx.conf domain ────────────────────────────────────────────────
echo "📝 Updating nginx configuration..."
sed -i "s/cirux.silvioalzate.shop/$DOMAIN/g" nginx.conf
# ─── Environment Variables ─────────────────────────────────────────────────
echo "🔧 Checking environment variables..."
if [ ! -f ".env.local" ]; then
echo "⚠️ .env.local not found! Creating from example..."
cp .env.local.example .env.local
echo "❌ IMPORTANT: Edit .env.local with your real credentials before continuing!"
exit 1
fi
# ─── Build & Deploy ────────────────────────────────────────────────────────
echo "🏗️ Building Docker images..."
docker-compose down 2>/dev/null || true
docker-compose build --no-cache
echo "🚀 Starting services..."
docker-compose up -d
# ─── Verify Deployment ─────────────────────────────────────────────────────
echo "✅ Verifying deployment..."
sleep 10
if curl -sf http://localhost:3020/api/health > /dev/null 2>&1; then
echo "✅ App is responding on port 3020"
else
echo "⚠️ App health check failed. Check logs: docker-compose logs cirux-app"
fi
echo ""
echo "─────────────────────────────────────────"
echo "🎉 Deployment Complete!"
echo ""
echo " App: https://$DOMAIN"
echo " Logs: docker-compose logs -f cirux-app"
echo " Restart: docker-compose restart cirux-app"
echo " Update: git pull && ./deploy.sh"
echo ""
echo " SSL cert will auto-renew via certbot."
echo "─────────────────────────────────────────"