From 5e6605f22f74cf1db3f8e1d07088835a8b37b0d3 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 14 Nov 2025 13:37:55 +0000 Subject: [PATCH] Fix deployment script to properly rebuild Docker containers and add missing scripts --- deploy-onprem.sh | 73 +++++++++++++++++++++++++++++++++++++ deploy/ssh/deploy-remote.sh | 45 ++++++++++++++++++++--- validate-deployment.sh | 45 +++++++++++++++++++++++ 3 files changed, 157 insertions(+), 6 deletions(-) create mode 100755 deploy-onprem.sh create mode 100755 validate-deployment.sh diff --git a/deploy-onprem.sh b/deploy-onprem.sh new file mode 100755 index 0000000..a0d832f --- /dev/null +++ b/deploy-onprem.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# Calejo Control Adapter - On-premises Deployment Script +# For local development and testing deployments + +set -e + +echo "🚀 Calejo Control Adapter - On-premises Deployment" +echo "==================================================" +echo "" + +# Check if Docker is available +if ! command -v docker &> /dev/null; then + echo "❌ Docker is not installed. Please install Docker first." + exit 1 +fi + +# Check if Docker Compose is available +if ! command -v docker-compose &> /dev/null; then + echo "❌ Docker Compose is not installed. Please install Docker Compose first." + exit 1 +fi + +echo "✅ Docker and Docker Compose are available" + +# Build and start services +echo "" +echo "🔨 Building and starting services..." + +# Stop existing services if running +echo "Stopping existing services..." +docker-compose down 2>/dev/null || true + +# Build services +echo "Building Docker images..." +docker-compose build --no-cache + +# Start services +echo "Starting services..." +docker-compose up -d + +# Wait for services to be ready +echo "" +echo "⏳ Waiting for services to start..." +for i in {1..30}; do + if curl -s http://localhost:8080/health > /dev/null; then + echo "✅ Services started successfully" + break + fi + echo " Waiting... (attempt $i/30)" + sleep 2 + + if [[ $i -eq 30 ]]; then + echo "❌ Services failed to start within 60 seconds" + docker-compose logs + exit 1 + fi +done + +echo "" +echo "🎉 Deployment completed successfully!" +echo "" +echo "🔗 Access URLs:" +echo " Dashboard: http://localhost:8080/dashboard" +echo " REST API: http://localhost:8080" +echo " Health Check: http://localhost:8080/health" +echo "" +echo "🔧 Management Commands:" +echo " View logs: docker-compose logs -f" +echo " Stop services: docker-compose down" +echo " Restart: docker-compose restart" +echo "" +echo "==================================================" \ No newline at end of file diff --git a/deploy/ssh/deploy-remote.sh b/deploy/ssh/deploy-remote.sh index 1f4acf2..f8a24f7 100755 --- a/deploy/ssh/deploy-remote.sh +++ b/deploy/ssh/deploy-remote.sh @@ -319,7 +319,20 @@ setup_remote_configuration() { # Set permissions on scripts execute_remote "chmod +x $TARGET_DIR/scripts/*.sh" "Setting script permissions" - execute_remote "chmod +x $TARGET_DIR/deploy-onprem.sh" "Setting deployment script permissions" + + # Set permissions on deployment script if it exists + if [[ "$DRY_RUN" == "true" ]]; then + # In dry-run mode, just show what would happen + execute_remote "cd $TARGET_DIR && test -f deploy-onprem.sh" "Checking for deploy-onprem.sh" + execute_remote "chmod +x $TARGET_DIR/deploy-onprem.sh" "Setting deployment script permissions" + else + # In actual deployment mode, check if file exists first + if execute_remote "cd $TARGET_DIR && test -f deploy-onprem.sh" "Checking for deploy-onprem.sh" 2>/dev/null; then + execute_remote "chmod +x $TARGET_DIR/deploy-onprem.sh" "Setting deployment script permissions" + else + print_warning "deploy-onprem.sh not found, skipping permissions" + fi + fi print_success "Remote configuration setup completed" } @@ -328,16 +341,36 @@ setup_remote_configuration() { build_and_start_services() { print_status "Building and starting services..." - # Build services - execute_remote "cd $TARGET_DIR && sudo docker-compose build" "Building Docker images" + # Stop existing services first to ensure clean rebuild + print_status "Stopping existing services..." + execute_remote "cd $TARGET_DIR && sudo docker-compose down" "Stopping existing services" || { + print_warning "Failed to stop some services, continuing with build..." + } + + # Build services with no-cache to ensure fresh build + print_status "Building Docker images (with --no-cache to ensure fresh build)..." + execute_remote "cd $TARGET_DIR && sudo docker-compose build --no-cache" "Building Docker images" || { + print_error "Docker build failed" + return 1 + } # Start services - use environment-specific compose file if available + print_status "Starting services..." if [[ "$ENVIRONMENT" == "production" ]] && execute_remote "cd $TARGET_DIR && test -f docker-compose.production.yml" "Checking for production compose file" 2>/dev/null; then - execute_remote "cd $TARGET_DIR && sudo docker-compose -f docker-compose.production.yml up -d" "Starting services with production configuration" + execute_remote "cd $TARGET_DIR && sudo docker-compose -f docker-compose.production.yml up -d" "Starting services with production configuration" || { + print_error "Failed to start services with production configuration" + return 1 + } elif [[ "$ENVIRONMENT" == "test" ]] && execute_remote "cd $TARGET_DIR && test -f docker-compose.test.yml" "Checking for test compose file" 2>/dev/null; then - execute_remote "cd $TARGET_DIR && sudo docker-compose -f docker-compose.test.yml up -d" "Starting services with test configuration" + execute_remote "cd $TARGET_DIR && sudo docker-compose -f docker-compose.test.yml up -d" "Starting services with test configuration" || { + print_error "Failed to start services with test configuration" + return 1 + } else - execute_remote "cd $TARGET_DIR && sudo docker-compose up -d" "Starting services" + execute_remote "cd $TARGET_DIR && sudo docker-compose up -d" "Starting services" || { + print_error "Failed to start services" + return 1 + } fi # Wait for services to be ready diff --git a/validate-deployment.sh b/validate-deployment.sh new file mode 100755 index 0000000..30a5b32 --- /dev/null +++ b/validate-deployment.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Calejo Control Adapter - Deployment Validation Script +# Validates that the deployment was successful + +set -e + +echo "🔍 Validating deployment..." + +# Check if services are running +if ! docker-compose ps | grep -q "Up"; then + echo "❌ Some services are not running" + docker-compose ps + exit 1 +fi + +echo "✅ All services are running" + +# Test health endpoint +if ! curl -s -f http://localhost:8080/health > /dev/null; then + echo "❌ Health endpoint is not accessible" + exit 1 +fi + +echo "✅ Health endpoint is accessible" + +# Test dashboard endpoint +if ! curl -s -f http://localhost:8080/dashboard > /dev/null; then + echo "❌ Dashboard endpoint is not accessible" + exit 1 +fi + +echo "✅ Dashboard endpoint is accessible" + +# Test API endpoint +if ! curl -s -f http://localhost:8080/api/v1/status > /dev/null; then + echo "❌ API endpoint is not accessible" + exit 1 +fi + +echo "✅ API endpoint is accessible" + +echo "" +echo "🎉 Deployment validation passed!" +exit 0 \ No newline at end of file