- Add Go modules with required dependencies (Gin, UUID, JWT, etc.) - Implement main web server with landing page endpoint - Add comprehensive API endpoints for health and status - Include proper error handling and request validation - Set up CORS middleware and security headers
220 lines
6.5 KiB
Bash
Executable File
220 lines
6.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# EMERGENCY PRODUCTION DEPLOYMENT SCRIPT
|
|
# Run this to launch YDN in 24 hours
|
|
|
|
set -euo pipefail
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
|
|
log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
|
|
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
|
|
|
# Configuration check
|
|
check_environment() {
|
|
log_info "Checking environment configuration..."
|
|
|
|
required_vars=(
|
|
"DOMAIN" "DB_PASSWORD" "JWT_SECRET" "STRIPE_SECRET_KEY"
|
|
"OVH_APPLICATION_KEY" "OVH_APPLICATION_SECRET" "OVH_CONSUMER_KEY"
|
|
"SMTP_HOST" "SMTP_USER" "SMTP_PASSWORD"
|
|
)
|
|
|
|
missing_vars=()
|
|
for var in "${required_vars[@]}"; do
|
|
if [ -z "${!var:-}" ]; then
|
|
missing_vars+=("$var")
|
|
fi
|
|
done
|
|
|
|
if [ ${#missing_vars[@]} -ne 0 ]; then
|
|
log_error "Missing required environment variables:"
|
|
printf ' %s\n' "${missing_vars[@]}"
|
|
log_info "Please set these in your .env file or environment"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "Environment configuration OK"
|
|
}
|
|
|
|
# SSL Certificate Setup
|
|
setup_ssl() {
|
|
log_info "Setting up SSL certificates..."
|
|
|
|
if [ ! -d "./ssl" ]; then
|
|
mkdir -p ./ssl
|
|
fi
|
|
|
|
# Generate self-signed certificate for immediate deployment
|
|
# Replace with Let's Encrypt later
|
|
if [ ! -f "./ssl/fullchain.pem" ] || [ ! -f "./ssl/privkey.pem" ]; then
|
|
log_warning "Generating self-signed certificate (replace with production cert ASAP)"
|
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
|
|
-keyout ./ssl/privkey.pem \
|
|
-out ./ssl/fullchain.pem \
|
|
-subj "/C=US/ST=State/L=City/O=YourDreamNameHere/CN=${DOMAIN}"
|
|
fi
|
|
|
|
log_success "SSL certificates ready"
|
|
}
|
|
|
|
# Deploy application
|
|
deploy_application() {
|
|
log_info "Deploying application..."
|
|
|
|
# Build and start services
|
|
docker-compose -f docker-compose.prod.yml down
|
|
docker-compose -f docker-compose.prod.yml build --no-cache
|
|
docker-compose -f docker-compose.prod.yml up -d
|
|
|
|
log_success "Application deployed"
|
|
}
|
|
|
|
# Health checks
|
|
health_check() {
|
|
log_info "Performing health checks..."
|
|
|
|
# Wait for services to start
|
|
sleep 30
|
|
|
|
# Check application health
|
|
max_attempts=30
|
|
attempt=0
|
|
|
|
while [ $attempt -lt $max_attempts ]; do
|
|
if curl -f -s http://localhost/health > /dev/null 2>&1; then
|
|
log_success "Application health check passed"
|
|
break
|
|
fi
|
|
|
|
attempt=$((attempt + 1))
|
|
if [ $attempt -eq $max_attempts ]; then
|
|
log_error "Application health check failed"
|
|
docker-compose -f docker-compose.prod.yml logs --tail=50 ydn-app
|
|
exit 1
|
|
fi
|
|
|
|
sleep 5
|
|
done
|
|
|
|
# Check database connection
|
|
if docker-compose -f docker-compose.prod.yml exec -T ydn-db pg_isready -U "${DB_USER}" -d "${DB_NAME}" > /dev/null 2>&1; then
|
|
log_success "Database health check passed"
|
|
else
|
|
log_error "Database health check failed"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "All health checks passed"
|
|
}
|
|
|
|
# Create admin user
|
|
create_admin() {
|
|
log_info "Creating admin user..."
|
|
|
|
# Wait for application to be ready
|
|
sleep 10
|
|
|
|
# Create admin user via API
|
|
curl -X POST http://localhost/api/v1/register \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"email": "admin@'${DOMAIN}'",
|
|
"first_name": "Admin",
|
|
"last_name": "User",
|
|
"password": "admin123456!"
|
|
}' || log_warning "Failed to create admin user (create manually)"
|
|
|
|
log_success "Admin user creation attempted"
|
|
}
|
|
|
|
# Show deployment summary
|
|
show_summary() {
|
|
log_success "🎉 DEPLOYMENT COMPLETE!"
|
|
echo
|
|
echo "YourDreamNameHere is now running at: https://${DOMAIN}"
|
|
echo "Dolibarr ERP: https://${DOMAIN}/dolibarr"
|
|
echo "API Documentation: https://${DOMAIN}/swagger/index.html"
|
|
echo
|
|
echo "Admin User: admin@${DOMAIN}"
|
|
echo "Admin Password: admin123456!"
|
|
echo
|
|
echo "IMPORTANT SECURITY NOTES:"
|
|
echo "1. Change admin password immediately"
|
|
echo "2. Replace self-signed SSL certificate with Let's Encrypt"
|
|
echo "3. Configure proper OVH payment processing"
|
|
echo "4. Set up monitoring and alerting"
|
|
echo "5. Configure backup offloading"
|
|
echo
|
|
echo "Useful commands:"
|
|
echo " View logs: docker-compose -f docker-compose.prod.yml logs -f"
|
|
echo " Stop app: docker-compose -f docker-compose.prod.yml down"
|
|
echo " Update app: docker-compose -f docker-compose.prod.yml pull && docker-compose -f docker-compose.prod.yml up -d"
|
|
}
|
|
|
|
# Main execution
|
|
main() {
|
|
log_info "Starting emergency production deployment..."
|
|
|
|
# Load environment variables
|
|
if [ -f ".env.prod" ]; then
|
|
set -a
|
|
source .env.prod
|
|
set +a
|
|
else
|
|
log_warning ".env.prod file not found, using environment variables"
|
|
fi
|
|
|
|
# Default values
|
|
export DOMAIN="${DOMAIN:-yourdreamnamehere.com}"
|
|
export DB_USER="${DB_USER:-ydn_user}"
|
|
export DB_NAME="${DB_NAME:-ydn_db}"
|
|
export DOCKER_REGISTRY="${DOCKER_REGISTRY:-ydn-app}"
|
|
export VERSION="${VERSION:-latest}"
|
|
|
|
# Execute deployment steps
|
|
check_environment
|
|
setup_ssl
|
|
deploy_application
|
|
health_check
|
|
create_admin
|
|
show_summary
|
|
|
|
log_success "Deployment completed successfully! 🚀"
|
|
}
|
|
|
|
# Help
|
|
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
|
|
echo "Emergency Production Deployment Script"
|
|
echo
|
|
echo "Usage: $0"
|
|
echo
|
|
echo "Required Environment Variables:"
|
|
echo " DOMAIN Your domain name"
|
|
echo " DB_PASSWORD Database password"
|
|
echo " JWT_SECRET JWT secret key"
|
|
echo " STRIPE_SECRET_KEY Stripe secret key"
|
|
echo " OVH_APPLICATION_KEY OVH API key"
|
|
echo " OVH_APPLICATION_SECRET OVH API secret"
|
|
echo " OVH_CONSUMER_KEY OVH consumer key"
|
|
echo " SMTP_HOST SMTP server"
|
|
echo " SMTP_USER SMTP username"
|
|
echo " SMTP_PASSWORD SMTP password"
|
|
echo
|
|
echo "Optional Environment Variables:"
|
|
echo " DB_USER Database user (default: ydn_user)"
|
|
echo " DB_NAME Database name (default: ydn_db)"
|
|
echo " VERSION Application version (default: latest)"
|
|
echo
|
|
exit 0
|
|
fi
|
|
|
|
# Run main function
|
|
main "$@" |