fixing docker-compose and cleanup
This commit is contained in:
Executable
+184
@@ -0,0 +1,184 @@
|
||||
#!/bin/bash
|
||||
# ===================================================================
|
||||
# Docker Build Script with Centralized Version Management
|
||||
# Automatically sources versions from docker/versions.toml via environment files
|
||||
# ===================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Script directory and project root
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
DOCKER_DIR="$PROJECT_ROOT/docker"
|
||||
BUILD_ARGS_DIR="$DOCKER_DIR/build-args"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_info() {
|
||||
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"
|
||||
}
|
||||
|
||||
# Function to load environment files
|
||||
load_env_files() {
|
||||
print_info "Loading centralized Docker version environment files..."
|
||||
|
||||
# Load global environment variables
|
||||
if [[ -f "$BUILD_ARGS_DIR/global.env" ]]; then
|
||||
export $(grep -v '^#' "$BUILD_ARGS_DIR/global.env" | xargs)
|
||||
print_info "✓ Loaded global.env"
|
||||
else
|
||||
print_error "Global environment file not found: $BUILD_ARGS_DIR/global.env"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load category-specific environment variables
|
||||
for env_file in services.env clients.env infrastructure.env; do
|
||||
if [[ -f "$BUILD_ARGS_DIR/$env_file" ]]; then
|
||||
export $(grep -v '^#' "$BUILD_ARGS_DIR/$env_file" | xargs)
|
||||
print_info "✓ Loaded $env_file"
|
||||
else
|
||||
print_warning "Optional environment file not found: $BUILD_ARGS_DIR/$env_file"
|
||||
fi
|
||||
done
|
||||
|
||||
# Set BUILD_DATE if not already set
|
||||
export BUILD_DATE=${BUILD_DATE:-$(date -u +'%Y-%m-%dT%H:%M:%SZ')}
|
||||
|
||||
# Map to Docker Compose environment variables
|
||||
export DOCKER_GRADLE_VERSION="${GRADLE_VERSION}"
|
||||
export DOCKER_JAVA_VERSION="${JAVA_VERSION}"
|
||||
export DOCKER_NODE_VERSION="${NODE_VERSION}"
|
||||
export DOCKER_NGINX_VERSION="${NGINX_VERSION}"
|
||||
export DOCKER_APP_VERSION="${VERSION}"
|
||||
export DOCKER_SPRING_PROFILES_DEFAULT="${SPRING_PROFILES_ACTIVE:-default}"
|
||||
export DOCKER_SPRING_PROFILES_DOCKER="docker"
|
||||
|
||||
print_success "All environment files loaded successfully!"
|
||||
}
|
||||
|
||||
# Function to show current versions
|
||||
show_versions() {
|
||||
print_info "Current centralized Docker versions:"
|
||||
echo " Gradle Version: ${DOCKER_GRADLE_VERSION:-not set}"
|
||||
echo " Java Version: ${DOCKER_JAVA_VERSION:-not set}"
|
||||
echo " Node Version: ${DOCKER_NODE_VERSION:-not set}"
|
||||
echo " Nginx Version: ${DOCKER_NGINX_VERSION:-not set}"
|
||||
echo " App Version: ${DOCKER_APP_VERSION:-not set}"
|
||||
echo " Build Date: ${BUILD_DATE:-not set}"
|
||||
echo " Spring Profile (Default): ${DOCKER_SPRING_PROFILES_DEFAULT:-not set}"
|
||||
echo " Spring Profile (Docker): ${DOCKER_SPRING_PROFILES_DOCKER:-not set}"
|
||||
}
|
||||
|
||||
# Function to build specific category
|
||||
build_category() {
|
||||
local category=$1
|
||||
local compose_file=""
|
||||
|
||||
case $category in
|
||||
"infrastructure")
|
||||
compose_file="docker-compose.yml"
|
||||
;;
|
||||
"services")
|
||||
compose_file="docker-compose.yml -f docker-compose.services.yml"
|
||||
;;
|
||||
"clients")
|
||||
compose_file="docker-compose.yml -f docker-compose.clients.yml"
|
||||
;;
|
||||
"all")
|
||||
compose_file="docker-compose.yml -f docker-compose.services.yml -f docker-compose.clients.yml"
|
||||
;;
|
||||
*)
|
||||
print_error "Invalid category: $category"
|
||||
print_info "Valid categories: infrastructure, services, clients, all"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
print_info "Building $category with centralized versions..."
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
if docker-compose -f $compose_file build; then
|
||||
print_success "$category built successfully!"
|
||||
else
|
||||
print_error "Failed to build $category"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Help function
|
||||
show_help() {
|
||||
echo "Docker Build Script with Centralized Version Management"
|
||||
echo ""
|
||||
echo "Usage: $0 [OPTIONS] [CATEGORY]"
|
||||
echo ""
|
||||
echo "Categories:"
|
||||
echo " infrastructure Build infrastructure services (API Gateway)"
|
||||
echo " services Build application services (ping-service, etc.)"
|
||||
echo " clients Build client applications (web-app, desktop-app)"
|
||||
echo " all Build everything"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -v, --versions Show current versions"
|
||||
echo " -h, --help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 services # Build all services"
|
||||
echo " $0 clients # Build client applications"
|
||||
echo " $0 all # Build everything"
|
||||
echo " $0 --versions # Show current versions"
|
||||
echo ""
|
||||
echo "The script automatically loads versions from:"
|
||||
echo " - docker/build-args/global.env"
|
||||
echo " - docker/build-args/services.env"
|
||||
echo " - docker/build-args/clients.env"
|
||||
echo " - docker/build-args/infrastructure.env"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
# Parse command line arguments
|
||||
case $1 in
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
-v|--versions)
|
||||
load_env_files
|
||||
show_versions
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
print_error "No category specified"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
# Load environment and build
|
||||
load_env_files
|
||||
show_versions
|
||||
echo ""
|
||||
build_category "$1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function with all arguments
|
||||
main "$@"
|
||||
Executable
+299
@@ -0,0 +1,299 @@
|
||||
#!/bin/bash
|
||||
# ===================================================================
|
||||
# Docker Versions Update Utility
|
||||
# Updates central docker/versions.toml and syncs to environment files
|
||||
# ===================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Script directory and project root
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
DOCKER_DIR="$PROJECT_ROOT/docker"
|
||||
VERSIONS_TOML="$DOCKER_DIR/versions.toml"
|
||||
BUILD_ARGS_DIR="$DOCKER_DIR/build-args"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_info() {
|
||||
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"
|
||||
}
|
||||
|
||||
# Function to extract version from TOML file
|
||||
get_version() {
|
||||
local key=$1
|
||||
grep "^$key = " "$VERSIONS_TOML" | sed 's/.*= "\(.*\)"/\1/' || echo ""
|
||||
}
|
||||
|
||||
# Function to update version in TOML file
|
||||
update_version() {
|
||||
local key=$1
|
||||
local new_value=$2
|
||||
|
||||
if grep -q "^$key = " "$VERSIONS_TOML"; then
|
||||
# Update existing key
|
||||
sed -i.bak "s/^$key = .*/$key = \"$new_value\"/" "$VERSIONS_TOML"
|
||||
print_success "Updated $key to $new_value"
|
||||
else
|
||||
print_error "Key $key not found in $VERSIONS_TOML"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to sync TOML to environment files
|
||||
sync_to_env_files() {
|
||||
print_info "Syncing versions.toml to environment files..."
|
||||
|
||||
# Get current versions from TOML
|
||||
local gradle_version=$(get_version "gradle")
|
||||
local java_version=$(get_version "java")
|
||||
local node_version=$(get_version "node")
|
||||
local nginx_version=$(get_version "nginx")
|
||||
local app_version=$(get_version "app-version")
|
||||
local spring_default=$(get_version "spring-profiles-default")
|
||||
local spring_docker=$(get_version "spring-profiles-docker")
|
||||
local alpine_version=$(get_version "alpine")
|
||||
|
||||
# Update global.env
|
||||
cat > "$BUILD_ARGS_DIR/global.env" << EOF
|
||||
# ===================================================================
|
||||
# Global Docker Build Arguments - Used by all categories
|
||||
# Source: docker/versions.toml
|
||||
# Last updated: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
|
||||
# ===================================================================
|
||||
|
||||
# --- Build Tools ---
|
||||
GRADLE_VERSION=$gradle_version
|
||||
JAVA_VERSION=$java_version
|
||||
|
||||
# --- Build Metadata ---
|
||||
BUILD_DATE=\$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||
VERSION=$app_version
|
||||
|
||||
# --- Common Base Images ---
|
||||
ALPINE_VERSION=$alpine_version
|
||||
ECLIPSE_TEMURIN_JDK_VERSION=$java_version-jdk-alpine
|
||||
ECLIPSE_TEMURIN_JRE_VERSION=$java_version-jre-alpine
|
||||
EOF
|
||||
print_success "Updated global.env"
|
||||
|
||||
# Update clients.env
|
||||
cat > "$BUILD_ARGS_DIR/clients.env" << EOF
|
||||
# ===================================================================
|
||||
# Clients Docker Build Arguments - dockerfiles/clients/*
|
||||
# Source: docker/versions.toml [categories.clients]
|
||||
# Last updated: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
|
||||
# ===================================================================
|
||||
|
||||
# --- Include Global Arguments ---
|
||||
# Source global.env for GRADLE_VERSION, JAVA_VERSION, BUILD_DATE, VERSION
|
||||
|
||||
# --- Client-Specific Build Tools ---
|
||||
NODE_VERSION=$node_version
|
||||
NGINX_VERSION=$nginx_version
|
||||
|
||||
# --- Client Build Configuration ---
|
||||
CLIENT_PATH=client
|
||||
CLIENT_MODULE=client
|
||||
CLIENT_NAME=meldestelle-client
|
||||
|
||||
# --- Web Application Specific ---
|
||||
WEB_APP_PORT=4000
|
||||
WEB_APP_BUILD_TARGET=wasmJsBrowserDistribution
|
||||
|
||||
# --- Desktop Application Specific ---
|
||||
DESKTOP_APP_VNC_PORT=5901
|
||||
DESKTOP_APP_NOVNC_PORT=6080
|
||||
DESKTOP_APP_BUILD_TARGET=composeDesktop
|
||||
|
||||
# --- Client Environment ---
|
||||
NODE_ENV=production
|
||||
APP_TITLE=Meldestelle
|
||||
APP_VERSION=$app_version
|
||||
|
||||
# --- Development Configuration ---
|
||||
WEBPACK_DEV_SERVER_HOST=0.0.0.0
|
||||
WEBPACK_DEV_SERVER_PORT=4000
|
||||
EOF
|
||||
print_success "Updated clients.env"
|
||||
|
||||
# Update services.env
|
||||
cat > "$BUILD_ARGS_DIR/services.env" << EOF
|
||||
# ===================================================================
|
||||
# Services Docker Build Arguments - dockerfiles/services/*
|
||||
# Source: docker/versions.toml [categories.services]
|
||||
# Last updated: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
|
||||
# ===================================================================
|
||||
|
||||
# --- Include Global Arguments ---
|
||||
# Source global.env for GRADLE_VERSION, JAVA_VERSION, BUILD_DATE, VERSION
|
||||
|
||||
# --- Spring Boot Services Configuration ---
|
||||
SPRING_PROFILES_ACTIVE=$spring_docker
|
||||
|
||||
# --- Service-Specific Arguments ---
|
||||
SERVICE_PATH=.
|
||||
SERVICE_NAME=spring-boot-service
|
||||
SERVICE_PORT=8080
|
||||
|
||||
# --- Service Port Mapping (matches gradle.properties) ---
|
||||
PING_SERVICE_PORT=8082
|
||||
MEMBERS_SERVICE_PORT=8083
|
||||
HORSES_SERVICE_PORT=8084
|
||||
EVENTS_SERVICE_PORT=8085
|
||||
MASTERDATA_SERVICE_PORT=8086
|
||||
|
||||
# --- Services List (for automation scripts) ---
|
||||
# ping-service, members-service, horses-service, events-service, masterdata-service
|
||||
EOF
|
||||
print_success "Updated services.env"
|
||||
|
||||
# Update infrastructure.env
|
||||
cat > "$BUILD_ARGS_DIR/infrastructure.env" << EOF
|
||||
# ===================================================================
|
||||
# Infrastructure Docker Build Arguments - dockerfiles/infrastructure/*
|
||||
# Source: docker/versions.toml [categories.infrastructure]
|
||||
# Last updated: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
|
||||
# ===================================================================
|
||||
|
||||
# --- Include Global Arguments ---
|
||||
# Source global.env for GRADLE_VERSION, JAVA_VERSION, BUILD_DATE, VERSION
|
||||
|
||||
# --- Infrastructure Services Configuration ---
|
||||
SPRING_PROFILES_ACTIVE=$spring_default
|
||||
|
||||
# --- Infrastructure Service Ports (matches gradle.properties) ---
|
||||
GATEWAY_PORT=8081
|
||||
AUTH_SERVER_PORT=8087
|
||||
MONITORING_SERVER_PORT=8088
|
||||
|
||||
# --- API Gateway Specific ---
|
||||
GATEWAY_SERVICE_PATH=infrastructure/gateway
|
||||
GATEWAY_SERVICE_NAME=api-gateway
|
||||
|
||||
# --- Auth Server Specific ---
|
||||
AUTH_SERVER_PATH=infrastructure/auth/auth-server
|
||||
AUTH_SERVER_SERVICE_NAME=auth-server
|
||||
|
||||
# --- Monitoring Server Specific ---
|
||||
MONITORING_SERVER_PATH=infrastructure/monitoring/monitoring-server
|
||||
MONITORING_SERVER_SERVICE_NAME=monitoring-server
|
||||
|
||||
# --- Infrastructure Dependencies ---
|
||||
CONSUL_ENABLED=true
|
||||
CONSUL_HOST=consul
|
||||
CONSUL_PORT=8500
|
||||
|
||||
# --- Database Configuration for Infrastructure Services ---
|
||||
DB_HOST=postgres
|
||||
DB_PORT=5432
|
||||
DB_NAME=meldestelle
|
||||
EOF
|
||||
print_success "Updated infrastructure.env"
|
||||
|
||||
print_success "All environment files synced successfully!"
|
||||
}
|
||||
|
||||
# Function to show current versions
|
||||
show_current_versions() {
|
||||
print_info "Current Docker versions:"
|
||||
echo " Gradle: $(get_version "gradle")"
|
||||
echo " Java: $(get_version "java")"
|
||||
echo " Node.js: $(get_version "node")"
|
||||
echo " Nginx: $(get_version "nginx")"
|
||||
echo " Alpine: $(get_version "alpine")"
|
||||
echo " App Version: $(get_version "app-version")"
|
||||
echo " Spring Profile (Default): $(get_version "spring-profiles-default")"
|
||||
echo " Spring Profile (Docker): $(get_version "spring-profiles-docker")"
|
||||
}
|
||||
|
||||
# Function to show help
|
||||
show_help() {
|
||||
echo "Docker Versions Update Utility"
|
||||
echo ""
|
||||
echo "Usage: $0 [COMMAND] [OPTIONS]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " show Show current versions"
|
||||
echo " sync Sync versions.toml to environment files"
|
||||
echo " update <key> <version> Update specific version"
|
||||
echo ""
|
||||
echo "Available keys for update:"
|
||||
echo " gradle Gradle version"
|
||||
echo " java Java version"
|
||||
echo " node Node.js version"
|
||||
echo " nginx Nginx version"
|
||||
echo " alpine Alpine Linux version"
|
||||
echo " app-version Application version"
|
||||
echo " spring-profiles-default Default Spring profile"
|
||||
echo " spring-profiles-docker Docker Spring profile"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 show # Show current versions"
|
||||
echo " $0 update gradle 9.1.0 # Update Gradle to 9.1.0"
|
||||
echo " $0 update java 22 # Update Java to version 22"
|
||||
echo " $0 sync # Sync versions to environment files"
|
||||
echo ""
|
||||
echo "After updating versions, run 'sync' to update environment files"
|
||||
echo "or use scripts/docker-build.sh to build with new versions."
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
# Check if versions.toml exists
|
||||
if [[ ! -f "$VERSIONS_TOML" ]]; then
|
||||
print_error "Versions file not found: $VERSIONS_TOML"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"show")
|
||||
show_current_versions
|
||||
;;
|
||||
"sync")
|
||||
sync_to_env_files
|
||||
;;
|
||||
"update")
|
||||
if [[ $# -lt 3 ]]; then
|
||||
print_error "Usage: $0 update <key> <version>"
|
||||
exit 1
|
||||
fi
|
||||
update_version "$2" "$3"
|
||||
sync_to_env_files
|
||||
;;
|
||||
"-h"|"--help"|"help")
|
||||
show_help
|
||||
;;
|
||||
"")
|
||||
print_error "No command specified"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown command: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function with all arguments
|
||||
main "$@"
|
||||
Executable
+420
@@ -0,0 +1,420 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =============================================================================
|
||||
# Full System Integration Test Script
|
||||
# =============================================================================
|
||||
# Comprehensive testing of all Meldestelle services including infrastructure,
|
||||
# application services, client applications, and inter-service connectivity.
|
||||
# =============================================================================
|
||||
|
||||
# Load common utilities
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=../utils/common.sh
|
||||
source "$SCRIPT_DIR/../utils/common.sh" || {
|
||||
echo "Error: Could not load common utilities"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Configuration
|
||||
# =============================================================================
|
||||
|
||||
readonly COMPOSE_FILES="-f docker-compose.yml -f docker-compose.services.yml -f docker-compose.clients.yml"
|
||||
readonly TIMEOUT_SECONDS=300
|
||||
readonly HEALTH_CHECK_INTERVAL=10
|
||||
readonly MAX_RETRIES=30
|
||||
|
||||
# Project root and Docker configuration
|
||||
readonly PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
readonly DOCKER_DIR="$PROJECT_ROOT/docker"
|
||||
readonly BUILD_ARGS_DIR="$DOCKER_DIR/build-args"
|
||||
|
||||
# Service endpoints (from common configuration)
|
||||
readonly SERVICES_CONFIG=(
|
||||
"postgres:5432:PostgreSQL:pg_isready -U meldestelle"
|
||||
"redis:6379:Redis:redis-cli ping"
|
||||
"consul:8500:Consul:http://localhost:8500/v1/status/leader"
|
||||
"api-gateway:8081:API Gateway:http://localhost:8081/actuator/health"
|
||||
"ping-service:8082:Ping Service:http://localhost:8082/actuator/health"
|
||||
)
|
||||
|
||||
# Integration with central Docker version management
|
||||
load_docker_versions() {
|
||||
if [[ -f "$BUILD_ARGS_DIR/global.env" ]]; then
|
||||
source "$BUILD_ARGS_DIR/global.env"
|
||||
log_info "Loaded centralized Docker versions"
|
||||
else
|
||||
log_warning "Centralized Docker versions not found, using defaults"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to wait for service health check using common utilities
|
||||
wait_for_service_with_retry() {
|
||||
local service_name=$1
|
||||
local health_check=$2
|
||||
local max_attempts=${3:-$MAX_RETRIES}
|
||||
|
||||
log_info "Waiting for $service_name to become healthy..."
|
||||
|
||||
if retry_with_backoff "$max_attempts" "$health_check" "Waiting for $service_name"; then
|
||||
log_success "$service_name is healthy"
|
||||
return 0
|
||||
else
|
||||
log_error "$service_name failed to become healthy after $max_attempts attempts"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# HTTP health check function
|
||||
http_health_check() {
|
||||
local url=$1
|
||||
curl -f -s -L --max-time 5 "$url" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# PostgreSQL health check function
|
||||
postgres_health_check() {
|
||||
docker exec meldestelle-postgres pg_isready -U meldestelle -d meldestelle > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# Redis health check function
|
||||
redis_health_check() {
|
||||
docker exec meldestelle-redis redis-cli ping > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to check service logs for errors
|
||||
check_service_logs() {
|
||||
local service_name=$1
|
||||
local container_name=$2
|
||||
|
||||
log_info "Checking $service_name logs for errors..."
|
||||
|
||||
# Get last 50 lines of logs
|
||||
local logs=$(docker logs --tail 50 "$container_name" 2>&1 || echo "")
|
||||
|
||||
# Check for common error patterns
|
||||
if echo "$logs" | grep -qi "error\|exception\|failed\|fatal"; then
|
||||
log_warning "$service_name has error messages in logs:"
|
||||
echo "$logs" | grep -i "error\|exception\|failed\|fatal" | tail -5
|
||||
else
|
||||
log_success "$service_name logs look clean"
|
||||
fi
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Enhanced Test Categories and Selective Execution
|
||||
# =============================================================================
|
||||
|
||||
# Function to test infrastructure services only
|
||||
test_infrastructure_services() {
|
||||
log_section "Testing Infrastructure Services"
|
||||
|
||||
# Load Docker versions
|
||||
load_docker_versions
|
||||
|
||||
# Start infrastructure services only
|
||||
log_info "Starting infrastructure services..."
|
||||
cd "$PROJECT_ROOT"
|
||||
docker compose -f docker-compose.yml up -d
|
||||
|
||||
# Wait for initialization
|
||||
log_info "Waiting 30 seconds for infrastructure services to initialize..."
|
||||
sleep 30
|
||||
|
||||
# Test PostgreSQL
|
||||
log_info "Testing PostgreSQL connection..."
|
||||
wait_for_service_with_retry "PostgreSQL" postgres_health_check || return 1
|
||||
|
||||
# Test Redis
|
||||
log_info "Testing Redis connection..."
|
||||
wait_for_service_with_retry "Redis" redis_health_check || return 1
|
||||
|
||||
# Test Consul
|
||||
log_info "Testing Consul..."
|
||||
wait_for_service_with_retry "Consul" "http_health_check http://localhost:8500/v1/status/leader" || return 1
|
||||
|
||||
# Test Prometheus
|
||||
log_info "Testing Prometheus..."
|
||||
wait_for_service_with_retry "Prometheus" "http_health_check http://localhost:9090/-/healthy" || return 1
|
||||
|
||||
# Test Grafana
|
||||
log_info "Testing Grafana..."
|
||||
wait_for_service_with_retry "Grafana" "http_health_check http://localhost:3000/api/health" || return 1
|
||||
|
||||
# Test Keycloak
|
||||
log_info "Testing Keycloak..."
|
||||
wait_for_service_with_retry "Keycloak" "http_health_check http://localhost:8180/" || return 1
|
||||
|
||||
log_success "All infrastructure services are healthy!"
|
||||
}
|
||||
|
||||
# Function to test application services
|
||||
test_application_services() {
|
||||
log_section "Testing Application Services"
|
||||
|
||||
# Start application services
|
||||
log_info "Starting application services..."
|
||||
cd "$PROJECT_ROOT"
|
||||
docker compose $COMPOSE_FILES up -d
|
||||
|
||||
# Wait for initialization
|
||||
log_info "Waiting 45 seconds for application services to initialize..."
|
||||
sleep 45
|
||||
|
||||
# Test API Gateway
|
||||
log_info "Testing API Gateway..."
|
||||
wait_for_service_with_retry "API Gateway" "http_health_check http://localhost:8081/actuator/health" || return 1
|
||||
|
||||
# Test Ping Service
|
||||
log_info "Testing Ping Service..."
|
||||
wait_for_service_with_retry "Ping Service" "http_health_check http://localhost:8082/actuator/health" || return 1
|
||||
|
||||
log_success "All application services are healthy!"
|
||||
}
|
||||
|
||||
# Function to test client applications
|
||||
test_client_applications() {
|
||||
log_section "Testing Client Applications"
|
||||
|
||||
# Start client applications
|
||||
log_info "Starting client applications..."
|
||||
cd "$PROJECT_ROOT"
|
||||
docker compose -f docker-compose.yml -f docker-compose.clients.yml up -d
|
||||
|
||||
# Wait for initialization
|
||||
log_info "Waiting 60 seconds for client applications to initialize..."
|
||||
sleep 60
|
||||
|
||||
# Test Web Application
|
||||
log_info "Testing Web Application..."
|
||||
wait_for_service_with_retry "Web App" "http_health_check http://localhost:4000/health" || return 1
|
||||
|
||||
# Test Desktop Application (VNC interface)
|
||||
log_info "Testing Desktop Application VNC interface..."
|
||||
wait_for_service_with_retry "Desktop App" "http_health_check http://localhost:6080/" || return 1
|
||||
|
||||
log_success "All client applications are healthy!"
|
||||
}
|
||||
|
||||
# Function to test network connectivity
|
||||
test_network_connectivity() {
|
||||
log_section "Testing Network Connectivity"
|
||||
|
||||
# Test service-to-service connectivity
|
||||
log_info "Testing service-to-service connectivity..."
|
||||
|
||||
# Test API Gateway can reach backend services
|
||||
if docker exec meldestelle-api-gateway curl -f -s --max-time 5 http://ping-service:8082/actuator/health > /dev/null 2>&1; then
|
||||
log_success "API Gateway can reach Ping Service"
|
||||
else
|
||||
log_error "API Gateway cannot reach Ping Service"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Test application service can reach infrastructure
|
||||
if docker exec meldestelle-ping-service curl -f -s --max-time 5 http://consul:8500/v1/status/leader > /dev/null 2>&1; then
|
||||
log_success "Application services can reach Consul"
|
||||
else
|
||||
log_error "Application services cannot reach Consul"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_success "Network connectivity tests passed!"
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Enhanced Reporting and Monitoring
|
||||
# =============================================================================
|
||||
|
||||
# Function to generate integration report
|
||||
generate_integration_report() {
|
||||
log_section "Integration Test Report"
|
||||
|
||||
# Service status matrix
|
||||
log_info "Service Status Matrix:"
|
||||
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" --filter "name=meldestelle"
|
||||
|
||||
# Performance metrics
|
||||
log_info "Performance Metrics:"
|
||||
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" $(docker ps -q --filter "name=meldestelle") 2>/dev/null || true
|
||||
|
||||
# Resource usage summary
|
||||
local containers=$(docker ps --filter "name=meldestelle" --format "{{.Names}}" | wc -l)
|
||||
log_info "Total running containers: $containers"
|
||||
|
||||
# Test summary
|
||||
print_test_summary
|
||||
}
|
||||
|
||||
# Enhanced cleanup function using common utilities
|
||||
cleanup() {
|
||||
log_section "Cleaning up test environment"
|
||||
|
||||
log_info "Stopping and removing all test containers..."
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Use the same files to tear down the environment
|
||||
docker compose $COMPOSE_FILES down --remove-orphans -v 2>/dev/null || true
|
||||
|
||||
# Remove network if it exists
|
||||
docker network rm meldestelle-network >/dev/null 2>&1 || true
|
||||
|
||||
log_success "Cleanup completed"
|
||||
}
|
||||
|
||||
# Function to run full system integration test
|
||||
run_full_integration_test() {
|
||||
log_section "Full System Integration Test"
|
||||
|
||||
# Load Docker versions
|
||||
load_docker_versions
|
||||
|
||||
# Start ALL services using all compose files
|
||||
log_info "Starting full environment with all services..."
|
||||
cd "$PROJECT_ROOT"
|
||||
docker compose $COMPOSE_FILES up -d
|
||||
|
||||
# Give services time to initialize
|
||||
log_info "Waiting 60 seconds for all services to initialize..."
|
||||
sleep 60
|
||||
|
||||
# Run comprehensive tests
|
||||
test_infrastructure_services || return 1
|
||||
test_application_services || return 1
|
||||
test_client_applications || return 1
|
||||
test_network_connectivity || return 1
|
||||
|
||||
# Generate comprehensive report
|
||||
generate_integration_report
|
||||
|
||||
log_success "Full system integration test completed successfully!"
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Command Line Interface and Help System
|
||||
# =============================================================================
|
||||
|
||||
# Function to show help
|
||||
show_help() {
|
||||
cat << EOF
|
||||
Full System Integration Test Script
|
||||
|
||||
USAGE:
|
||||
$0 [OPTIONS] [CATEGORY]
|
||||
|
||||
CATEGORIES:
|
||||
infrastructure Test infrastructure services only (PostgreSQL, Redis, Consul, etc.)
|
||||
services Test application services (API Gateway, Ping Service, etc.)
|
||||
clients Test client applications (Web App, Desktop App)
|
||||
network Test inter-service network connectivity
|
||||
all Run full system integration test (default)
|
||||
cleanup Clean up test environment only
|
||||
|
||||
OPTIONS:
|
||||
-h, --help Show this help message
|
||||
-v, --verbose Enable verbose logging
|
||||
--no-cleanup Skip cleanup on exit
|
||||
--cleanup-only Only run cleanup and exit
|
||||
|
||||
EXAMPLES:
|
||||
$0 # Run full integration test
|
||||
$0 infrastructure # Test infrastructure services only
|
||||
$0 services # Test application services only
|
||||
$0 clients # Test client applications only
|
||||
$0 network # Test network connectivity only
|
||||
$0 cleanup # Clean up test environment
|
||||
$0 --help # Show this help
|
||||
|
||||
ENVIRONMENT VARIABLES:
|
||||
CLEANUP_SERVICES=false Skip cleanup on exit
|
||||
REMOVE_CONTAINERS=true Remove containers during cleanup
|
||||
MAX_RETRIES=30 Maximum retry attempts for health checks
|
||||
HEALTH_CHECK_INTERVAL=10 Seconds between health check attempts
|
||||
|
||||
The script automatically loads versions from the centralized Docker version
|
||||
management system and integrates with the common utilities for consistent
|
||||
logging, error handling, and cleanup procedures.
|
||||
EOF
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Main Execution Function
|
||||
# =============================================================================
|
||||
|
||||
# Main execution function with enhanced argument parsing
|
||||
main() {
|
||||
local category="${1:-all}"
|
||||
local cleanup_on_exit=true
|
||||
|
||||
# Parse options
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
-v|--verbose)
|
||||
set -x
|
||||
shift
|
||||
;;
|
||||
--no-cleanup)
|
||||
cleanup_on_exit=false
|
||||
shift
|
||||
;;
|
||||
--cleanup-only)
|
||||
cleanup
|
||||
exit 0
|
||||
;;
|
||||
-*)
|
||||
log_error "Unknown option: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
category="$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Set cleanup trap if requested
|
||||
if [[ "$cleanup_on_exit" == "true" ]]; then
|
||||
trap cleanup EXIT
|
||||
fi
|
||||
|
||||
# Execute based on category
|
||||
log_section "Meldestelle Integration Test Suite"
|
||||
log_info "Category: $category"
|
||||
log_info "Cleanup on exit: $cleanup_on_exit"
|
||||
|
||||
case "$category" in
|
||||
"infrastructure")
|
||||
test_infrastructure_services || exit 1
|
||||
;;
|
||||
"services")
|
||||
test_application_services || exit 1
|
||||
;;
|
||||
"clients")
|
||||
test_client_applications || exit 1
|
||||
;;
|
||||
"network")
|
||||
test_network_connectivity || exit 1
|
||||
;;
|
||||
"all")
|
||||
run_full_integration_test || exit 1
|
||||
;;
|
||||
"cleanup")
|
||||
cleanup
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown category: $category"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
log_success "Integration test completed successfully!"
|
||||
}
|
||||
|
||||
# Execute main function with all arguments
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user