244 lines
5.9 KiB
Bash
244 lines
5.9 KiB
Bash
#!/bin/bash
|
|
|
|
# UAMILS Management Portal Deployment Script
|
|
# Complete setup for management.dev.uggla.uamils.com
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
DOMAIN="${DOMAIN:-dev.uggla.uamils.com}"
|
|
|
|
log() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
|
|
}
|
|
|
|
check_prerequisites() {
|
|
log "Checking prerequisites..."
|
|
|
|
# Check if running as root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
log "ERROR: This script must be run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
# Check docker
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
log "ERROR: Docker is not installed"
|
|
exit 1
|
|
fi
|
|
|
|
# Check docker-compose
|
|
if ! command -v docker-compose >/dev/null 2>&1; then
|
|
log "ERROR: Docker Compose is not installed"
|
|
exit 1
|
|
fi
|
|
|
|
# Check nginx
|
|
if ! command -v nginx >/dev/null 2>&1; then
|
|
log "ERROR: Nginx is not installed"
|
|
exit 1
|
|
fi
|
|
|
|
log "✅ Prerequisites check passed"
|
|
}
|
|
|
|
setup_ssl() {
|
|
log "Setting up SSL certificates..."
|
|
|
|
cd "$PROJECT_ROOT/ssl"
|
|
|
|
# Ensure certificates exist
|
|
if [[ ! -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ]]; then
|
|
log "Getting SSL certificates..."
|
|
./certbot-manager.sh renew
|
|
else
|
|
log "SSL certificates already exist"
|
|
fi
|
|
|
|
log "✅ SSL certificates ready"
|
|
}
|
|
|
|
build_containers() {
|
|
log "Building Docker containers..."
|
|
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# Build all containers including management
|
|
docker-compose build backend frontend management
|
|
|
|
log "✅ Docker containers built"
|
|
}
|
|
|
|
start_services() {
|
|
log "Starting services..."
|
|
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# Start database and cache first
|
|
docker-compose up -d postgres redis
|
|
|
|
# Wait for database to be ready
|
|
log "Waiting for database to be ready..."
|
|
sleep 10
|
|
|
|
# Start application services
|
|
docker-compose up -d backend frontend management
|
|
|
|
log "✅ Services started"
|
|
}
|
|
|
|
configure_nginx() {
|
|
log "Configuring nginx..."
|
|
|
|
cd "$PROJECT_ROOT/ssl"
|
|
|
|
# Run nginx SSL setup
|
|
./nginx-ssl-setup.sh setup
|
|
|
|
log "✅ Nginx configured"
|
|
}
|
|
|
|
verify_deployment() {
|
|
log "Verifying deployment..."
|
|
|
|
# Check container health
|
|
cd "$PROJECT_ROOT"
|
|
|
|
log "Checking container status..."
|
|
docker-compose ps
|
|
|
|
# Test endpoints
|
|
log "Testing endpoints..."
|
|
|
|
# Main site
|
|
if curl -sSf "https://$DOMAIN/api/health" >/dev/null 2>&1; then
|
|
log "✅ Main site API accessible"
|
|
else
|
|
log "⚠️ Main site API not responding"
|
|
fi
|
|
|
|
# Management portal
|
|
if curl -sSf "https://management.$DOMAIN" >/dev/null 2>&1; then
|
|
log "✅ Management portal accessible"
|
|
else
|
|
log "⚠️ Management portal not responding"
|
|
fi
|
|
|
|
log "✅ Deployment verification complete"
|
|
}
|
|
|
|
show_results() {
|
|
log "Deployment Complete! 🎉"
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "UAMILS Management Portal Deployment"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "🌐 Main Application:"
|
|
echo " https://$DOMAIN"
|
|
echo ""
|
|
echo "🛠️ Management Portal:"
|
|
echo " https://management.$DOMAIN"
|
|
echo ""
|
|
echo "🔐 Multi-tenant Sites:"
|
|
echo " https://tenant1.$DOMAIN"
|
|
echo " https://tenant2.$DOMAIN"
|
|
echo ""
|
|
echo "🔗 API Endpoints:"
|
|
echo " https://$DOMAIN/api/health"
|
|
echo " https://$DOMAIN/api/"
|
|
echo ""
|
|
echo "📊 Docker Services:"
|
|
echo " - Backend API (port 3002)"
|
|
echo " - Frontend App (port 3001)"
|
|
echo " - Management Portal (port 3003)"
|
|
echo " - PostgreSQL Database (port 5433)"
|
|
echo " - Redis Cache (port 6380)"
|
|
echo ""
|
|
echo "🔒 Security Features:"
|
|
echo " ✅ SSL/TLS Encryption"
|
|
echo " ✅ Auto-renewal SSL Certificates"
|
|
echo " ✅ Security Headers"
|
|
echo " ✅ Admin-only Management Access"
|
|
echo ""
|
|
echo "📝 Management Portal Features:"
|
|
echo " - System Dashboard"
|
|
echo " - Tenant Management"
|
|
echo " - User Administration"
|
|
echo " - System Monitoring"
|
|
echo ""
|
|
echo "🔄 Management Commands:"
|
|
echo " cd $PROJECT_ROOT/management && ./build.sh [command]"
|
|
echo " cd $PROJECT_ROOT/ssl && ./nginx-ssl-setup.sh [command]"
|
|
echo " cd $PROJECT_ROOT && docker-compose [command]"
|
|
echo ""
|
|
echo "=========================================="
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
log "Starting UAMILS Management Portal deployment"
|
|
|
|
check_prerequisites
|
|
setup_ssl
|
|
build_containers
|
|
start_services
|
|
configure_nginx
|
|
verify_deployment
|
|
show_results
|
|
}
|
|
|
|
# Handle command line arguments
|
|
case "${1:-deploy}" in
|
|
"deploy")
|
|
main
|
|
;;
|
|
"ssl")
|
|
setup_ssl
|
|
configure_nginx
|
|
;;
|
|
"build")
|
|
build_containers
|
|
;;
|
|
"start")
|
|
start_services
|
|
;;
|
|
"stop")
|
|
cd "$PROJECT_ROOT"
|
|
docker-compose down
|
|
;;
|
|
"restart")
|
|
cd "$PROJECT_ROOT"
|
|
docker-compose restart
|
|
;;
|
|
"logs")
|
|
cd "$PROJECT_ROOT"
|
|
docker-compose logs -f
|
|
;;
|
|
"status")
|
|
cd "$PROJECT_ROOT"
|
|
docker-compose ps
|
|
;;
|
|
*)
|
|
echo "UAMILS Management Portal Deployment"
|
|
echo "==================================="
|
|
echo ""
|
|
echo "Usage: $0 [command]"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " deploy Full deployment (default)"
|
|
echo " ssl Setup SSL and nginx only"
|
|
echo " build Build Docker containers"
|
|
echo " start Start services"
|
|
echo " stop Stop all services"
|
|
echo " restart Restart all services"
|
|
echo " logs Show service logs"
|
|
echo " status Show service status"
|
|
echo ""
|
|
echo "Environment variables:"
|
|
echo " DOMAIN Domain name (default: dev.uggla.uamils.com)"
|
|
echo ""
|
|
;;
|
|
esac
|