132 lines
4.6 KiB
Bash
Executable file
132 lines
4.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Oliver Metadata Tool - Idempotent Deployment Script
|
|
# Usage: Run from /opt/solventum-image-metadata or the repo root directory
|
|
#
|
|
# This script handles:
|
|
# - Pre-flight checks for required tools
|
|
# - Pulling latest code from origin/main
|
|
# - Building Docker containers (with cache)
|
|
# - Stopping/starting containers
|
|
# - Health check verification
|
|
|
|
set -euo pipefail
|
|
|
|
#=============================================================================
|
|
# Configuration
|
|
#=============================================================================
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_DIR="$SCRIPT_DIR"
|
|
COMPOSE_FILE="$REPO_DIR/docker-compose.yml"
|
|
CONTAINER_NAME="oliver-metadata-tool"
|
|
HEALTH_CHECK_URL="http://localhost:5001/login"
|
|
HEALTH_CHECK_TIMEOUT=60
|
|
|
|
#=============================================================================
|
|
# Colors for output
|
|
#=============================================================================
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
#=============================================================================
|
|
# Helper functions
|
|
#=============================================================================
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
log_success() { echo -e "${GREEN}[OK]${NC} $1"; }
|
|
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
|
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
|
|
|
check_command() {
|
|
if ! command -v "$1" &> /dev/null; then
|
|
log_error "$1 is not installed"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
#=============================================================================
|
|
# Pre-flight checks
|
|
#=============================================================================
|
|
log_info "Running pre-flight checks..."
|
|
check_command docker
|
|
check_command curl
|
|
|
|
# Check for docker-compose (either standalone or docker compose plugin)
|
|
if command -v docker-compose &> /dev/null; then
|
|
DOCKER_COMPOSE="docker-compose"
|
|
elif docker compose version &> /dev/null 2>&1; then
|
|
DOCKER_COMPOSE="docker compose"
|
|
else
|
|
log_error "docker-compose is not installed (neither standalone nor plugin)"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "All required commands available (using: $DOCKER_COMPOSE)"
|
|
|
|
#=============================================================================
|
|
# Check .env file
|
|
#=============================================================================
|
|
if [ ! -f "$REPO_DIR/.env" ]; then
|
|
log_warn ".env file not found - create it with OPENAI_API_KEY for AI features"
|
|
else
|
|
log_success ".env file found"
|
|
fi
|
|
|
|
#=============================================================================
|
|
# Build Docker containers
|
|
#=============================================================================
|
|
log_info "Building Docker containers (using cache)..."
|
|
$DOCKER_COMPOSE -f "$COMPOSE_FILE" build
|
|
log_success "Docker build complete"
|
|
|
|
#=============================================================================
|
|
# Stop existing containers
|
|
#=============================================================================
|
|
log_info "Stopping existing containers..."
|
|
$DOCKER_COMPOSE -f "$COMPOSE_FILE" down || true
|
|
log_success "Containers stopped"
|
|
|
|
#=============================================================================
|
|
# Start containers
|
|
#=============================================================================
|
|
log_info "Starting containers..."
|
|
$DOCKER_COMPOSE -f "$COMPOSE_FILE" up -d
|
|
log_success "Containers started"
|
|
|
|
#=============================================================================
|
|
# Health check
|
|
#=============================================================================
|
|
log_info "Waiting for health check (timeout: ${HEALTH_CHECK_TIMEOUT}s)..."
|
|
elapsed=0
|
|
while [ $elapsed -lt $HEALTH_CHECK_TIMEOUT ]; do
|
|
if curl -sf "$HEALTH_CHECK_URL" > /dev/null 2>&1; then
|
|
log_success "Health check passed"
|
|
break
|
|
fi
|
|
sleep 2
|
|
elapsed=$((elapsed + 2))
|
|
echo -n "."
|
|
done
|
|
echo ""
|
|
|
|
if [ $elapsed -ge $HEALTH_CHECK_TIMEOUT ]; then
|
|
log_error "Health check failed after ${HEALTH_CHECK_TIMEOUT}s"
|
|
log_info "Container logs:"
|
|
$DOCKER_COMPOSE -f "$COMPOSE_FILE" logs --tail=50
|
|
exit 1
|
|
fi
|
|
|
|
#=============================================================================
|
|
# Display status
|
|
#=============================================================================
|
|
echo ""
|
|
log_info "=========================================="
|
|
log_success "Deployment complete!"
|
|
log_info "=========================================="
|
|
echo ""
|
|
$DOCKER_COMPOSE -f "$COMPOSE_FILE" ps
|
|
echo ""
|
|
log_info "Application running at: http://localhost:5001"
|
|
log_info "Configure Apache reverse proxy to forward to port 5001"
|
|
log_info "Login via Microsoft SSO (Azure AD)"
|