#!/bin/bash # validate-compose.sh - Validate all Docker Compose profiles # Used by CI/CD pipelines to ensure Compose configurations are valid set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" COMPOSE_DIR="${REPO_ROOT}/devops/compose" # Default profiles to validate PROFILES=(dev stage prod airgap mirror) echo "=== Docker Compose Validation ===" echo "Compose directory: $COMPOSE_DIR" # Check if compose directory exists if [[ ! -d "$COMPOSE_DIR" ]]; then echo "::warning::Compose directory not found at $COMPOSE_DIR" exit 0 fi # Check for base docker-compose.yml BASE_COMPOSE="$COMPOSE_DIR/docker-compose.yml" if [[ ! -f "$BASE_COMPOSE" ]]; then echo "::warning::Base docker-compose.yml not found at $BASE_COMPOSE" exit 0 fi FAILED=0 for profile in "${PROFILES[@]}"; do OVERLAY="$COMPOSE_DIR/docker-compose.$profile.yml" if [[ -f "$OVERLAY" ]]; then echo "=== Validating docker-compose.$profile.yml ===" if docker compose -f "$BASE_COMPOSE" -f "$OVERLAY" config --quiet 2>&1; then echo "✓ Profile '$profile' is valid" else echo "✗ Profile '$profile' validation failed" FAILED=1 fi else echo "⊘ Skipping profile '$profile' (no overlay file)" fi done if [[ $FAILED -eq 1 ]]; then echo "::error::One or more Compose profiles failed validation" exit 1 fi echo "=== All Compose profiles valid! ==="