add docker for server demo

This commit is contained in:
arifal
2025-06-26 18:28:26 +07:00
parent c33193d5f0
commit a7f578ca3d
23 changed files with 2420 additions and 431 deletions

34
scripts/build-and-zip.sh Executable file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
# Build and Zip Script for Laravel Vite Project
echo "🚀 Starting build process..."
# Clean previous build
echo "🧹 Cleaning previous build..."
rm -rf public/build
rm -f build.zip
# Run npm build
echo "📦 Building assets with Vite..."
npm run build
# Check if build was successful
if [ $? -eq 0 ]; then
echo "✅ Build completed successfully!"
# Create zip file
echo "📁 Creating build.zip..."
cd public && zip -r ../build.zip build/
cd ..
echo "✅ build.zip created successfully!"
echo "📊 Build folder size:"
du -sh public/build
echo "📊 Zip file size:"
du -sh build.zip
echo "🎉 Process completed! You can now upload build.zip to your server."
else
echo "❌ Build failed! Please check the errors above."
exit 1
fi

226
scripts/deploy-production.sh Executable file
View File

@@ -0,0 +1,226 @@
#!/bin/bash
# Production Deployment Script for Sibedas PBG Web
# This script deploys the application with reverse proxy and SSL support
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
DOMAIN="${DOMAIN:-sibedas.yourdomain.com}"
EMAIL="${EMAIL:-admin@yourdomain.com}"
SSL_TYPE="${SSL_TYPE:-self-signed}"
echo -e "${BLUE}=== Production Deployment for Sibedas PBG Web ===${NC}"
echo -e "Domain: ${GREEN}$DOMAIN${NC}"
echo -e "Email: ${GREEN}$EMAIL${NC}"
echo -e "SSL Type: ${GREEN}$SSL_TYPE${NC}"
echo ""
# Function to check prerequisites
check_prerequisites() {
echo -e "${BLUE}Checking prerequisites...${NC}"
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed${NC}"
exit 1
fi
# Check if Docker Compose is installed
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}Error: Docker Compose is not installed${NC}"
exit 1
fi
# Check if .env file exists
if [ ! -f .env ]; then
echo -e "${RED}Error: .env file not found${NC}"
echo -e "${YELLOW}Please create .env file with required environment variables${NC}"
exit 1
fi
echo -e "${GREEN}Prerequisites check passed!${NC}"
}
# Function to backup existing data
backup_data() {
echo -e "${BLUE}Creating backup of existing data...${NC}"
BACKUP_DIR="backups/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
# Backup database
if docker ps | grep -q sibedas_db; then
echo -e "${YELLOW}Backing up database...${NC}"
docker exec sibedas_db mysqldump -u root -p"${MYSQL_ROOT_PASSWORD:-root}" sibedas > "$BACKUP_DIR/database.sql" || true
fi
# Backup volumes
echo -e "${YELLOW}Backing up volumes...${NC}"
docker run --rm -v sibedas_app_storage:/data -v "$(pwd)/$BACKUP_DIR":/backup alpine tar czf /backup/app_storage.tar.gz -C /data . || true
docker run --rm -v sibedas_dbdata:/data -v "$(pwd)/$BACKUP_DIR":/backup alpine tar czf /backup/dbdata.tar.gz -C /data . || true
echo -e "${GREEN}Backup created in $BACKUP_DIR${NC}"
}
# Function to stop existing containers
stop_containers() {
echo -e "${BLUE}Stopping existing containers...${NC}"
docker-compose down --remove-orphans || true
echo -e "${GREEN}Containers stopped!${NC}"
}
# Function to build and start containers
deploy_containers() {
echo -e "${BLUE}Building and starting containers...${NC}"
# Build images
echo -e "${YELLOW}Building Docker images...${NC}"
docker-compose build --no-cache
# Start containers
echo -e "${YELLOW}Starting containers...${NC}"
docker-compose up -d
# Wait for containers to be healthy
echo -e "${YELLOW}Waiting for containers to be healthy...${NC}"
sleep 30
# Check container status
if ! docker-compose ps | grep -q "Up"; then
echo -e "${RED}Error: Some containers failed to start${NC}"
docker-compose logs
exit 1
fi
echo -e "${GREEN}Containers deployed successfully!${NC}"
}
# Function to setup SSL
setup_ssl() {
echo -e "${BLUE}Setting up SSL certificate...${NC}"
# Wait for nginx proxy to be ready
echo -e "${YELLOW}Waiting for reverse proxy to be ready...${NC}"
sleep 10
# Setup SSL
if [ "$SSL_TYPE" = "letsencrypt" ]; then
echo -e "${YELLOW}Setting up Let's Encrypt certificate...${NC}"
echo -e "${YELLOW}Make sure your domain $DOMAIN points to this server${NC}"
read -p "Press Enter to continue..."
docker exec sibedas_nginx_proxy /usr/local/bin/ssl-setup.sh letsencrypt
else
echo -e "${YELLOW}Setting up self-signed certificate...${NC}"
docker exec sibedas_nginx_proxy /usr/local/bin/ssl-setup.sh self-signed
fi
echo -e "${GREEN}SSL setup completed!${NC}"
}
# Function to run post-deployment tasks
post_deployment() {
echo -e "${BLUE}Running post-deployment tasks...${NC}"
# Clear Laravel caches
echo -e "${YELLOW}Clearing Laravel caches...${NC}"
docker exec sibedas_app php artisan config:clear || true
docker exec sibedas_app php artisan route:clear || true
docker exec sibedas_app php artisan view:clear || true
docker exec sibedas_app php artisan cache:clear || true
# Optimize Laravel
echo -e "${YELLOW}Optimizing Laravel...${NC}"
docker exec sibedas_app php artisan optimize || true
# Check application health
echo -e "${YELLOW}Checking application health...${NC}"
sleep 5
if curl -f -s "http://localhost/health-check" > /dev/null; then
echo -e "${GREEN}Application is healthy!${NC}"
else
echo -e "${YELLOW}Warning: Health check failed, but deployment completed${NC}"
fi
}
# Function to show deployment status
show_status() {
echo -e "${BLUE}=== Deployment Status ===${NC}"
echo -e "${YELLOW}Container Status:${NC}"
docker-compose ps
echo -e "${YELLOW}SSL Certificate Status:${NC}"
docker exec sibedas_nginx_proxy /usr/local/bin/ssl-setup.sh check || true
echo -e "${YELLOW}Application URLs:${NC}"
echo -e " HTTP: ${GREEN}http://$DOMAIN${NC}"
echo -e " HTTPS: ${GREEN}https://$DOMAIN${NC}"
echo -e "${YELLOW}Logs:${NC}"
echo -e " Application: ${GREEN}docker-compose logs app${NC}"
echo -e " Reverse Proxy: ${GREEN}docker-compose logs nginx-proxy${NC}"
echo -e " Database: ${GREEN}docker-compose logs db${NC}"
}
# Function to show usage
show_usage() {
echo "Usage: $0 {deploy|status|backup|ssl}"
echo ""
echo "Commands:"
echo " deploy - Full deployment with SSL setup"
echo " status - Show deployment status"
echo " backup - Create backup of existing data"
echo " ssl - Setup SSL certificate only"
echo ""
echo "Environment variables:"
echo " DOMAIN - Domain name (default: sibedas.yourdomain.com)"
echo " EMAIL - Email address for Let's Encrypt (default: admin@yourdomain.com)"
echo " SSL_TYPE - Type of SSL (letsencrypt or self-signed, default: self-signed)"
echo ""
echo "Examples:"
echo " DOMAIN=myapp.com EMAIL=admin@myapp.com SSL_TYPE=letsencrypt $0 deploy"
echo " $0 status"
echo " $0 ssl"
}
# Main script logic
case "${1:-deploy}" in
"deploy")
check_prerequisites
backup_data
stop_containers
deploy_containers
setup_ssl
post_deployment
show_status
;;
"status")
show_status
;;
"backup")
backup_data
;;
"ssl")
setup_ssl
;;
*)
show_usage
exit 1
;;
esac
echo ""
echo -e "${GREEN}Deployment completed successfully!${NC}"
echo -e "${BLUE}Your application is now accessible at: https://$DOMAIN${NC}"

View File

@@ -0,0 +1,257 @@
#!/bin/bash
echo "🗃️ Import Database from sibedas.sql"
echo "===================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if sibedas.sql exists
check_sql_file() {
if [[ ! -f "../sibedas.sql" ]]; then
print_error "sibedas.sql file not found!"
print_error "Please make sure sibedas.sql is in the project root directory."
exit 1
fi
print_success "Found sibedas.sql file"
}
# Import for local development
import_local() {
print_status "Importing database for LOCAL DEVELOPMENT..."
# Stop containers if running
print_status "Stopping containers..."
docker-compose -f ../docker-compose.local.yml down
# Remove existing database volume to force fresh import
print_warning "Removing old database volume for fresh import..."
docker volume rm sibedas-pbg-web_sibedas_dbdata_local 2>/dev/null || true
# Start database container first
print_status "Starting database container..."
docker-compose -f ../docker-compose.local.yml up -d db
# Wait for database to be ready
print_status "Waiting for database to be ready..."
sleep 20
# Verify sibedas.sql was imported automatically
print_status "Verifying database import..."
if docker-compose -f ../docker-compose.local.yml exec -T db mysql -uroot -proot -e "USE sibedas; SELECT COUNT(*) FROM users;" 2>/dev/null; then
print_success "✅ Database imported successfully from sibedas.sql!"
# Show table summary
print_status "Database tables summary:"
docker-compose -f ../docker-compose.local.yml exec -T db mysql -uroot -proot -e "
USE sibedas;
SELECT 'users' as table_name, COUNT(*) as count FROM users
UNION SELECT 'advertisements', COUNT(*) FROM advertisements
UNION SELECT 'business_or_industries', COUNT(*) FROM business_or_industries
UNION SELECT 'customers', COUNT(*) FROM customers
UNION SELECT 'cache', COUNT(*) FROM cache
UNION SELECT 'sessions', COUNT(*) FROM sessions
UNION SELECT 'jobs', COUNT(*) FROM jobs;"
else
print_error "❌ Database import failed or data not found!"
exit 1
fi
# Start all containers
print_status "Starting all containers..."
docker-compose -f ../docker-compose.local.yml up -d
# Wait for app to be ready
sleep 15
# Clear caches to ensure fresh start
print_status "Clearing application caches..."
docker-compose -f ../docker-compose.local.yml exec -T app php artisan config:clear
docker-compose -f ../docker-compose.local.yml exec -T app php artisan cache:clear
docker-compose -f ../docker-compose.local.yml exec -T app php artisan view:clear
print_success "✅ Local development setup completed with sibedas.sql data!"
print_status "Access your application at: http://localhost:8000"
}
# Import for production
import_production() {
print_status "Importing database for PRODUCTION..."
# Check if .env exists
if [[ ! -f "../.env" ]]; then
print_error ".env file not found! Please configure production environment first."
exit 1
fi
# Load environment variables
source ../.env
# Stop containers if running
print_status "Stopping containers..."
docker-compose -f ../docker-compose.yml down
# Remove existing database volume to force fresh import
print_warning "Removing old database volume for fresh import..."
docker volume rm sibedas-pbg-web_sibedas_dbdata 2>/dev/null || true
# Start database container first
print_status "Starting database container..."
docker-compose -f ../docker-compose.yml up -d db
# Wait for database to be ready
print_status "Waiting for database to be ready..."
sleep 30
# Verify sibedas.sql was imported automatically
print_status "Verifying database import..."
if docker-compose -f ../docker-compose.yml exec -T db mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "USE ${DB_DATABASE}; SELECT COUNT(*) FROM users;" 2>/dev/null; then
print_success "✅ Database imported successfully from sibedas.sql!"
# Show table summary
print_status "Database tables summary:"
docker-compose -f ../docker-compose.yml exec -T db mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "
USE ${DB_DATABASE};
SELECT 'users' as table_name, COUNT(*) as count FROM users
UNION SELECT 'advertisements', COUNT(*) FROM advertisements
UNION SELECT 'business_or_industries', COUNT(*) FROM business_or_industries
UNION SELECT 'customers', COUNT(*) FROM customers
UNION SELECT 'cache', COUNT(*) FROM cache
UNION SELECT 'sessions', COUNT(*) FROM sessions
UNION SELECT 'jobs', COUNT(*) FROM jobs;"
else
print_error "❌ Database import failed or data not found!"
exit 1
fi
# Start all containers
print_status "Starting all containers..."
docker-compose -f ../docker-compose.yml up -d
# Wait for app to be ready
sleep 30
# Generate app key if needed
if [[ -z "$APP_KEY" ]] || [[ "$APP_KEY" == "" ]]; then
print_status "Generating application key..."
docker-compose -f ../docker-compose.yml exec -T app php artisan key:generate --force
fi
# Optimize application
print_status "Optimizing application..."
docker-compose -f ../docker-compose.yml exec -T app php artisan config:cache
docker-compose -f ../docker-compose.yml exec -T app php artisan route:cache
docker-compose -f ../docker-compose.yml exec -T app php artisan view:cache
# Create storage link
print_status "Creating storage link..."
docker-compose -f ../docker-compose.yml exec -T app php artisan storage:link
print_success "✅ Production setup completed with sibedas.sql data!"
print_status "Access your application at: ${APP_URL}"
}
# Manual import to running container
manual_import() {
print_status "Manual import to running container..."
# Check which containers are running
if docker-compose -f ../docker-compose.local.yml ps | grep -q "sibedas_db_local"; then
print_status "Found local development database container"
print_status "Importing sibedas.sql..."
docker-compose -f ../docker-compose.local.yml exec -T db mysql -uroot -proot sibedas < ../sibedas.sql
print_success "✅ Import completed for local development!"
# Clear app caches
docker-compose -f ../docker-compose.local.yml exec -T app php artisan cache:clear 2>/dev/null || true
elif docker-compose -f ../docker-compose.yml ps | grep -q "sibedas_db"; then
print_status "Found production database container"
source ../.env 2>/dev/null || true
print_status "Importing sibedas.sql..."
docker-compose -f ../docker-compose.yml exec -T db mysql -uroot -p${MYSQL_ROOT_PASSWORD:-root} ${DB_DATABASE:-sibedas} < ../sibedas.sql
print_success "✅ Import completed for production!"
# Clear app caches
docker-compose -f ../docker-compose.yml exec -T app php artisan cache:clear 2>/dev/null || true
else
print_error "❌ No database container found running!"
print_error "Please start containers first:"
print_error " Local: docker-compose -f ../docker-compose.local.yml up -d"
print_error " Production: docker-compose -f ../docker-compose.yml up -d"
exit 1
fi
}
# Main execution
main() {
check_sql_file
echo ""
echo "🗃️ Choose import method:"
echo "1) 🔄 Fresh import for LOCAL development (recommended)"
echo "2) 🔄 Fresh import for PRODUCTION"
echo "3) 📥 Manual import to running container"
echo "4) ❌ Cancel"
echo ""
read -p "Enter your choice (1-4): " choice
case $choice in
1)
import_local
;;
2)
import_production
;;
3)
manual_import
;;
4)
print_status "Cancelled"
exit 0
;;
*)
print_error "Invalid choice"
exit 1
;;
esac
echo ""
print_success "🎉 Database import completed!"
echo ""
print_status "📋 Imported data includes:"
echo " ✅ All application tables with existing data"
echo " ✅ Cache table (for CACHE_DRIVER=database)"
echo " ✅ Sessions table (for SESSION_DRIVER=database)"
echo " ✅ Jobs & failed_jobs tables (for QUEUE_CONNECTION=database)"
echo ""
print_status "🚀 Your application is ready to use with all data!"
}
# Run main function
main "$@"

188
scripts/setup-local.sh Executable file
View File

@@ -0,0 +1,188 @@
#!/bin/bash
# Local Development Setup Script for Sibedas PBG Web
# This script sets up the local development environment
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}=== Local Development Setup untuk Sibedas PBG Web ===${NC}"
echo ""
# Function to check prerequisites
check_prerequisites() {
echo -e "${BLUE}Checking prerequisites...${NC}"
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed${NC}"
exit 1
fi
# Check if Docker Compose is installed
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}Error: Docker Compose is not installed${NC}"
exit 1
fi
# Check if .env file exists
if [ ! -f .env ]; then
echo -e "${YELLOW}Warning: .env file not found${NC}"
echo -e "${YELLOW}Creating from example...${NC}"
if [ -f env.production.example ]; then
cp env.production.example .env
else
echo -e "${RED}Error: No environment example file found${NC}"
exit 1
fi
fi
echo -e "${GREEN}Prerequisites check passed!${NC}"
}
# Function to setup environment for local development
setup_environment() {
echo -e "${BLUE}Setting up environment for local development...${NC}"
# Update .env for local development
sed -i 's/APP_ENV=production/APP_ENV=local/g' .env
sed -i 's/APP_DEBUG=false/APP_DEBUG=true/g' .env
sed -i 's/APP_URL=https:\/\/sibedas.yourdomain.com/APP_URL=http:\/\/localhost:8000/g' .env
sed -i 's/VITE_APP_URL=https:\/\/sibedas.yourdomain.com/VITE_APP_URL=http:\/\/localhost:8000/g' .env
# Update database settings for local
sed -i 's/DB_USERNAME=sibedas_user/DB_USERNAME=root/g' .env
sed -i 's/DB_PASSWORD=your_secure_database_password/DB_PASSWORD=root/g' .env
sed -i 's/MYSQL_ROOT_PASSWORD=your_secure_root_password/MYSQL_ROOT_PASSWORD=root/g' .env
echo -e "${GREEN}Environment configured for local development!${NC}"
}
# Function to start local containers
start_containers() {
echo -e "${BLUE}Starting local development containers...${NC}"
# Stop any existing containers
docker-compose -f docker-compose.local.yml down --remove-orphans || true
# Build and start containers
docker-compose -f docker-compose.local.yml up -d --build
# Wait for containers to be ready
echo -e "${YELLOW}Waiting for containers to be ready...${NC}"
sleep 30
# Check container status
if docker-compose -f docker-compose.local.yml ps | grep -q "Up"; then
echo -e "${GREEN}Containers started successfully!${NC}"
else
echo -e "${RED}Error: Some containers failed to start${NC}"
docker-compose -f docker-compose.local.yml logs
exit 1
fi
}
# Function to setup database
setup_database() {
echo -e "${BLUE}Setting up database...${NC}"
# Wait for database to be ready
echo -e "${YELLOW}Waiting for database to be ready...${NC}"
sleep 10
# Check if database import was successful
if docker exec sibedas_db_local mysql -uroot -proot sibedas -e "SHOW TABLES LIKE 'users';" 2>/dev/null | grep -q "users"; then
echo -e "${GREEN}Database imported successfully from sibedas.sql!${NC}"
else
echo -e "${YELLOW}Warning: Database import verification failed${NC}"
echo -e "${YELLOW}You may need to manually import the database${NC}"
fi
}
# Function to run post-setup tasks
post_setup() {
echo -e "${BLUE}Running post-setup tasks...${NC}"
# Clear Laravel caches
echo -e "${YELLOW}Clearing Laravel caches...${NC}"
docker exec sibedas_app_local php artisan config:clear || true
docker exec sibedas_app_local php artisan route:clear || true
docker exec sibedas_app_local php artisan view:clear || true
docker exec sibedas_app_local php artisan cache:clear || true
# Optimize Laravel
echo -e "${YELLOW}Optimizing Laravel...${NC}"
docker exec sibedas_app_local php artisan optimize:clear || true
# Create storage link
echo -e "${YELLOW}Creating storage link...${NC}"
docker exec sibedas_app_local php artisan storage:link || true
echo -e "${GREEN}Post-setup tasks completed!${NC}"
}
# Function to show status
show_status() {
echo -e "${BLUE}=== Local Development Status ===${NC}"
echo -e "${YELLOW}Container Status:${NC}"
docker-compose -f docker-compose.local.yml ps
echo -e "${YELLOW}Application URLs:${NC}"
echo -e " Main App: ${GREEN}http://localhost:8000${NC}"
echo -e " Vite Dev: ${GREEN}http://localhost:5173${NC}"
echo -e "${YELLOW}Useful Commands:${NC}"
echo -e " View logs: ${GREEN}docker-compose -f docker-compose.local.yml logs -f [service]${NC}"
echo -e " Execute commands: ${GREEN}docker-compose -f docker-compose.local.yml exec app php artisan [command]${NC}"
echo -e " Stop services: ${GREEN}docker-compose -f docker-compose.local.yml down${NC}"
echo -e " Restart services: ${GREEN}docker-compose -f docker-compose.local.yml restart${NC}"
}
# Function to show usage
show_usage() {
echo "Usage: $0 {setup|status|help}"
echo ""
echo "Commands:"
echo " setup - Setup local development environment (default)"
echo " status - Show current status"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " $0 setup"
echo " $0 status"
}
# Main script logic
case "${1:-setup}" in
"setup")
check_prerequisites
setup_environment
start_containers
setup_database
post_setup
show_status
;;
"status")
show_status
;;
"help"|"-h"|"--help")
show_usage
;;
*)
echo -e "${RED}Unknown command: $1${NC}"
echo ""
show_usage
exit 1
;;
esac
echo ""
echo -e "${GREEN}Local development setup completed successfully!${NC}"
echo -e "${BLUE}You can now access your application at: http://localhost:8000${NC}"

129
scripts/setup-reverse-proxy.sh Executable file
View File

@@ -0,0 +1,129 @@
#!/bin/bash
# Reverse Proxy Setup Script for Sibedas PBG Web
# Wrapper script untuk setup reverse proxy dan SSL
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}=== Reverse Proxy Setup untuk Sibedas PBG Web ===${NC}"
echo ""
# Function to show usage
show_usage() {
echo "Usage: $0 {setup|ssl|status|help}"
echo ""
echo "Commands:"
echo " setup - Setup reverse proxy dan SSL (default)"
echo " ssl - Setup SSL certificate only"
echo " status - Show current status"
echo " help - Show this help message"
echo ""
echo "Environment variables:"
echo " DOMAIN - Domain name (default: sibedas.yourdomain.com)"
echo " EMAIL - Email address for Let's Encrypt (default: admin@yourdomain.com)"
echo " SSL_TYPE - Type of SSL (letsencrypt or self-signed, default: self-signed)"
echo ""
echo "Examples:"
echo " $0 setup"
echo " DOMAIN=myapp.com EMAIL=admin@myapp.com SSL_TYPE=letsencrypt $0 setup"
echo " $0 ssl"
echo " $0 status"
}
# Function to check prerequisites
check_prerequisites() {
echo -e "${BLUE}Checking prerequisites...${NC}"
# Check if .env exists
if [ ! -f .env ]; then
echo -e "${RED}Error: .env file not found${NC}"
echo -e "${YELLOW}Please create .env file with required environment variables${NC}"
exit 1
fi
# Check if scripts directory exists
if [ ! -d scripts ]; then
echo -e "${RED}Error: scripts directory not found${NC}"
exit 1
fi
echo -e "${GREEN}Prerequisites check passed!${NC}"
}
# Function to setup reverse proxy
setup_reverse_proxy() {
echo -e "${BLUE}Setting up reverse proxy...${NC}"
# Run deployment script
./scripts/deploy-production.sh deploy
echo -e "${GREEN}Reverse proxy setup completed!${NC}"
}
# Function to setup SSL only
setup_ssl() {
echo -e "${BLUE}Setting up SSL certificate...${NC}"
# Run SSL setup script
./scripts/setup-ssl.sh setup
echo -e "${GREEN}SSL setup completed!${NC}"
}
# Function to show status
show_status() {
echo -e "${BLUE}=== Current Status ===${NC}"
# Check if containers are running
if command -v docker-compose &> /dev/null; then
echo -e "${YELLOW}Container Status:${NC}"
docker-compose ps 2>/dev/null || echo "Docker Compose not available"
fi
# Check SSL certificate
if [ -f scripts/setup-ssl.sh ]; then
echo -e "${YELLOW}SSL Certificate Status:${NC}"
./scripts/setup-ssl.sh check 2>/dev/null || echo "SSL check failed"
fi
# Show environment info
if [ -f .env ]; then
echo -e "${YELLOW}Environment Variables:${NC}"
grep -E "^(DOMAIN|EMAIL|SSL_TYPE|APP_URL)=" .env 2>/dev/null || echo "No environment variables found"
fi
}
# Main script logic
case "${1:-setup}" in
"setup")
check_prerequisites
setup_reverse_proxy
;;
"ssl")
check_prerequisites
setup_ssl
;;
"status")
show_status
;;
"help"|"-h"|"--help")
show_usage
;;
*)
echo -e "${RED}Unknown command: $1${NC}"
echo ""
show_usage
exit 1
;;
esac
echo ""
echo -e "${GREEN}Setup completed successfully!${NC}"
echo -e "${BLUE}For more information, see: docs/README-Reverse-Proxy-SSL.md${NC}"

145
scripts/setup-ssl.sh Executable file
View File

@@ -0,0 +1,145 @@
#!/bin/bash
# SSL Setup Script for Sibedas PBG Web
# This script sets up SSL certificates for the reverse proxy
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
DOMAIN="${DOMAIN:-sibedas.yourdomain.com}"
EMAIL="${EMAIL:-admin@yourdomain.com}"
SSL_TYPE="${SSL_TYPE:-self-signed}"
echo -e "${BLUE}=== SSL Setup for Sibedas PBG Web ===${NC}"
echo -e "Domain: ${GREEN}$DOMAIN${NC}"
echo -e "Email: ${GREEN}$EMAIL${NC}"
echo -e "SSL Type: ${GREEN}$SSL_TYPE${NC}"
echo ""
# Function to check if Docker is running
check_docker() {
if ! docker info > /dev/null 2>&1; then
echo -e "${RED}Error: Docker is not running${NC}"
exit 1
fi
}
# Function to check if containers are running
check_containers() {
if ! docker ps | grep -q sibedas_nginx_proxy; then
echo -e "${YELLOW}Warning: Reverse proxy container is not running${NC}"
echo -e "${YELLOW}Starting containers first...${NC}"
docker-compose up -d
sleep 10
fi
}
# Function to setup self-signed certificate
setup_self_signed() {
echo -e "${BLUE}Setting up self-signed SSL certificate...${NC}"
docker exec sibedas_nginx_proxy /usr/local/bin/ssl-setup.sh self-signed
echo -e "${GREEN}Self-signed certificate setup completed!${NC}"
echo -e "${YELLOW}Note: Self-signed certificates will show security warnings in browsers${NC}"
}
# Function to setup Let's Encrypt certificate
setup_letsencrypt() {
echo -e "${BLUE}Setting up Let's Encrypt SSL certificate...${NC}"
# Check if domain is accessible
echo -e "${YELLOW}Important: Make sure your domain $DOMAIN points to this server${NC}"
echo -e "${YELLOW}and ports 80 and 443 are accessible from the internet${NC}"
read -p "Press Enter to continue..."
docker exec sibedas_nginx_proxy /usr/local/bin/ssl-setup.sh letsencrypt
echo -e "${GREEN}Let's Encrypt certificate setup completed!${NC}"
}
# Function to check certificate status
check_certificate() {
echo -e "${BLUE}Checking certificate status...${NC}"
docker exec sibedas_nginx_proxy /usr/local/bin/ssl-setup.sh check
}
# Function to renew certificate
renew_certificate() {
echo -e "${BLUE}Renewing SSL certificate...${NC}"
docker exec sibedas_nginx_proxy /usr/local/bin/ssl-setup.sh renew
echo -e "${GREEN}Certificate renewal completed!${NC}"
}
# Function to show usage
show_usage() {
echo "Usage: $0 {setup|check|renew|self-signed|letsencrypt}"
echo ""
echo "Commands:"
echo " setup - Setup SSL certificate (default: self-signed)"
echo " check - Check certificate status"
echo " renew - Renew Let's Encrypt certificate"
echo " self-signed - Setup self-signed certificate"
echo " letsencrypt - Setup Let's Encrypt certificate"
echo ""
echo "Environment variables:"
echo " DOMAIN - Domain name (default: sibedas.yourdomain.com)"
echo " EMAIL - Email address for Let's Encrypt (default: admin@yourdomain.com)"
echo " SSL_TYPE - Type of SSL (letsencrypt or self-signed, default: self-signed)"
echo ""
echo "Examples:"
echo " DOMAIN=myapp.com EMAIL=admin@myapp.com $0 letsencrypt"
echo " $0 self-signed"
echo " $0 check"
}
# Main script logic
case "${1:-setup}" in
"setup")
check_docker
check_containers
if [ "$SSL_TYPE" = "letsencrypt" ]; then
setup_letsencrypt
else
setup_self_signed
fi
;;
"check")
check_docker
check_containers
check_certificate
;;
"renew")
check_docker
check_containers
renew_certificate
;;
"self-signed")
check_docker
check_containers
setup_self_signed
;;
"letsencrypt")
check_docker
check_containers
setup_letsencrypt
;;
*)
show_usage
exit 1
;;
esac
echo ""
echo -e "${GREEN}SSL setup completed successfully!${NC}"
echo -e "${BLUE}You can now access your application at: https://$DOMAIN${NC}"