Files
light-heart-labs--dreamserver/ods/scripts/validate-compose-stack.sh
T
wehub-resource-sync 9e8f1bbeed
Dashboard / frontend (push) Failing after 0s
Dashboard / api (push) Failing after 0s
Lint PowerShell / powershell-lint (ubuntu-latest) (push) Failing after 1s
Python Lint / Lint Python with Ruff (push) Failing after 1s
ShellCheck / Lint shell scripts (push) Failing after 1s
Matrix Smoke / linux-smoke (push) Failing after 1s
Matrix Smoke / distro: cachyos (push) Failing after 15s
Matrix Smoke / distro: linux-mint-21.3 (push) Failing after 15s
Matrix Smoke / distro: debian-12 (push) Failing after 5m21s
Matrix Smoke / distro: fedora-41 (push) Failing after 4m56s
Matrix Smoke / distro: ubuntu-24.04 (push) Failing after 2m13s
Matrix Smoke / distro: rocky-9 (push) Failing after 10m39s
Matrix Smoke / distro: manjaro (push) Failing after 12m11s
Matrix Smoke / distro: opensuse-tw (push) Failing after 11m53s
Matrix Smoke / distro: archlinux (push) Failing after 20m3s
Matrix Smoke / distro: ubuntu-22.04 (push) Failing after 13m49s
Validate .env Schema / tier-1-env-validation (push) Successful in 52s
Validate .env Schema / tier-2-env-validation (push) Successful in 44s
Validate .env Schema / tier-3-env-validation (push) Successful in 52s
Validate .env Schema / tier-4-env-validation (push) Successful in 51s
Validate Extensions Catalog / Check catalog is up-to-date (push) Failing after 9m47s
Secret Scan / Scan for secrets (push) Failing after 21m4s
Validate Docker Compose / Validate Docker Compose files (push) Has been cancelled
Python Type Check / Type check with mypy (push) Has been cancelled
Validate .env Schema / tier-0-env-validation (push) Has been cancelled
Test Linux / integration-smoke (push) Has been cancelled
Lint PowerShell / powershell-lint (windows-latest) (push) Has been cancelled
Matrix Smoke / macos-smoke (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:33 +08:00

89 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Validate resolved Docker Compose stack for syntax errors
# Usage: validate-compose-stack.sh --compose-flags "-f file1.yml -f file2.yml" [--env-file /path/to/.env]
#
# Returns:
# 0 - Valid compose stack
# 1 - Invalid compose stack (syntax errors, missing files, etc.)
set -euo pipefail
COMPOSE_FLAGS=""
ENV_FILE=""
QUIET=false
while [[ $# -gt 0 ]]; do
case "$1" in
--compose-flags)
COMPOSE_FLAGS="${2:-}"
shift 2
;;
--env-file)
ENV_FILE="${2:-}"
shift 2
;;
--quiet)
QUIET=true
shift
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
done
if [[ -z "$COMPOSE_FLAGS" ]]; then
echo "ERROR: --compose-flags required" >&2
exit 1
fi
# Build env-file flag if provided (allows compose to resolve required variable references)
ENV_FILE_FLAG=""
if [[ -n "$ENV_FILE" && -f "$ENV_FILE" ]]; then
ENV_FILE_FLAG="--env-file $ENV_FILE"
fi
# Check if docker/docker compose is available
if command -v docker &>/dev/null && docker compose version &>/dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
elif command -v docker-compose &>/dev/null; then
DOCKER_COMPOSE_CMD="docker-compose"
else
echo "ERROR: docker compose not found" >&2
exit 1
fi
# Validate compose stack syntax
if ! $QUIET; then
echo "Validating compose stack: $COMPOSE_FLAGS"
fi
# Use docker compose config to validate syntax and merge
# This catches:
# - YAML syntax errors
# - Missing files
# - Invalid service definitions
# - Circular dependencies
# - Invalid environment variable references
validation_output=$(mktemp)
if $DOCKER_COMPOSE_CMD $ENV_FILE_FLAG $COMPOSE_FLAGS config > "$validation_output" 2>&1; then
if ! $QUIET; then
echo "Compose stack validation passed"
# Show summary of services
service_count=$(grep -c "^ [a-z]" "$validation_output" || echo "0")
echo " Services defined: $service_count"
fi
rm -f "$validation_output"
exit 0
else
echo "Compose stack validation FAILED" >&2
echo "" >&2
echo "Errors:" >&2
cat "$validation_output" >&2
echo "" >&2
echo "Compose flags: $COMPOSE_FLAGS" >&2
rm -f "$validation_output"
exit 1
fi