#!/bin/bash # CKB Application Deployment Script # This script sets up SSL certificate and deploys the CKB application set -e echo "=== CKB Application Deployment Script ===" echo "Domain: bengkel.digitaloasis.xyz" echo "Port: 8082" echo "" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if running as root if [[ $EUID -eq 0 ]]; then print_error "This script should not be run as root" exit 1 fi # Check if we're in the correct directory if [ ! -f "docker-compose.prod.yml" ]; then print_error "Please run this script from the CKB application directory (/var/www/ckb)" exit 1 fi print_status "Starting CKB application deployment..." # Step 1: Stop existing containers print_status "Stopping existing containers..." docker-compose -f docker-compose.prod.yml down # Step 2: Build and start containers print_status "Building and starting containers..." docker-compose -f docker-compose.prod.yml up -d --build # Step 3: Wait for containers to be ready print_status "Waiting for containers to be ready..." sleep 10 # Step 4: Check if containers are running print_status "Checking container status..." if docker ps | grep -q "ckb-laravel-app"; then print_status "CKB Laravel app is running" else print_error "CKB Laravel app is not running" exit 1 fi if docker ps | grep -q "ckb-nginx-proxy"; then print_status "CKB Nginx proxy is running" else print_error "CKB Nginx proxy is not running" exit 1 fi # Step 5: Check if port 8082 is accessible print_status "Checking if port 8082 is accessible..." if curl -s -o /dev/null -w "%{http_code}" http://localhost:8082 | grep -q "200\|301\|302"; then print_status "Port 8082 is accessible" else print_warning "Port 8082 might not be accessible yet, waiting..." sleep 5 if curl -s -o /dev/null -w "%{http_code}" http://localhost:8082 | grep -q "200\|301\|302"; then print_status "Port 8082 is now accessible" else print_error "Port 8082 is not accessible" print_status "Checking container logs..." docker-compose -f docker-compose.prod.yml logs ckb-nginx-proxy exit 1 fi fi print_status "CKB application deployment completed successfully!" echo "" print_status "Next steps:" echo "1. Configure Nginx reverse proxy on the main server:" echo " sudo cp nginx-ckb-reverse-proxy.conf /etc/nginx/sites-available/bengkel.digitaloasis.xyz" echo " sudo ln -s /etc/nginx/sites-available/bengkel.digitaloasis.xyz /etc/nginx/sites-enabled/" echo "" echo "2. Generate SSL certificate:" echo " sudo certbot certonly --webroot --webroot-path=/var/www/html --email admin@digitaloasis.xyz --agree-tos --no-eff-email -d bengkel.digitaloasis.xyz -d www.bengkel.digitaloasis.xyz" echo "" echo "3. Test and reload Nginx:" echo " sudo nginx -t" echo " sudo systemctl reload nginx" echo "" print_status "Application will be accessible at: https://bengkel.digitaloasis.xyz"