docker-compose-gateway-env-test.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. set -eu
  3. repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
  4. cd "$repo_root"
  5. gateway_variables=$(mktemp "${TMPDIR:-/tmp}/sub2api-gateway-env.XXXXXX")
  6. cleanup() {
  7. rm -f "$gateway_variables"
  8. }
  9. trap cleanup EXIT HUP INT TERM
  10. awk '
  11. /^GATEWAY_[A-Z0-9_]+=/ {
  12. separator = index($0, "=")
  13. print substr($0, 1, separator - 1) "\t" substr($0, separator + 1)
  14. }
  15. ' deploy/.env.example > "$gateway_variables"
  16. for compose_file in \
  17. deploy/docker-compose.yml \
  18. deploy/docker-compose.local.yml \
  19. deploy/docker-compose.standalone.yml \
  20. deploy/docker-compose.dev.yml
  21. do
  22. tab=$(printf '\t')
  23. while IFS="$tab" read -r key value; do
  24. # .env.example intentionally includes high-capacity tuning examples for
  25. # these values. An unconfigured Compose deployment must retain the
  26. # backend defaults instead of silently adopting the examples.
  27. case "$key" in
  28. GATEWAY_MAX_CONNS_PER_HOST) value=1024 ;;
  29. GATEWAY_MAX_IDLE_CONNS) value=2560 ;;
  30. GATEWAY_MAX_IDLE_CONNS_PER_HOST) value=120 ;;
  31. esac
  32. expected=$(printf ' - %s=${%s:-%s}' "$key" "$key" "$value")
  33. expected_count=$(grep -Fxc "$expected" "$compose_file" || true)
  34. key_count=$(grep -Ec "^[[:space:]]*-[[:space:]]*${key}([[:space:]]*=.*)?[[:space:]]*$" "$compose_file" || true)
  35. if [ "$expected_count" -ne 1 ] || [ "$key_count" -ne 1 ]; then
  36. printf '%s must pass %s with the expected fallback exactly once\n' "$compose_file" "$key" >&2
  37. exit 1
  38. fi
  39. done < "$gateway_variables"
  40. done
  41. printf 'docker compose Gateway environment test passed\n'