#!/usr/bin/env bash # Shared helpers for validating Compose files. Sourced both by steps in # .gitea/workflows/ci.yaml and by deploy-lib.sh on the workstation. # # Two levels of checking, matching how the repo is structured: # # general every committed Compose file, active or not. Pure structure check: # no ${VAR} interpolation, no .env lookup, no bind-mount path # resolution. Disabled stacks deliberately have no .env in the repo # and no values on the CI runner, so a full `config` run would fail on # their `${VAR:?}` guards for reasons that have nothing to do with the # change under review. # # full active stacks only, with interpolation and env-file resolution, so # required variables and referenced files are actually resolved. Needs # the gitignored .env files, so this only runs in the deploy workflow # on the workstation. # # This file is meant to be sourced, not executed. # All committed Compose files, including the ones deploy never starts. compose_files() { git ls-files \ '*compose.yaml' '*compose.yml' } # Prints the flags that turn `docker compose config` into the general check. # Probed rather than hardcoded so an older Compose without --no-env-resolution # still gets the flags it does support. compose_safe_flags() { local help flag help="$(docker compose config --help 2>/dev/null || true)" for flag in --no-interpolate --no-env-resolution --no-path-resolution; do if printf '%s' "$help" | grep -q -- "$flag"; then printf '%s\n' "$flag" fi done } # validate_compose_file [extra docker compose config flags...] validate_compose_file() { local file="$1" shift docker compose -f "$file" config --quiet "$@" }