mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
Follow-up to d002796a5. The formula `infinito_nexus_${INFINITO_DISTRO}` is
now defined in exactly one place — `scripts/meta/env/defaults.sh:18`,
exported outside the load-once guard so it tracks INFINITO_DISTRO across
matrix iterations (caller re-sources defaults.sh after distro changes).
Every other site reads INFINITO_CONTAINER strictly from env; nothing
re-derives the formula, no lazy/colon-dash fallbacks, no per-call defaults.
Production code aligned:
- cli/deploy/development/common.py: add resolve_container() (strict env
reader, raises SystemExit on unset). make_compose() calls it as an
early-fail guard so a missing defaults.sh source surfaces here instead
of as a confusing compose.yml interpolation error later.
- cli/deploy/development/deploy.py: stop re-deriving from compose.distro;
use resolve_container().
- compose.yml: container_name reads ${INFINITO_CONTAINER:?...} strictly,
so callers that bypass defaults.sh fail fast with a clear hint.
- scripts/meta/resolve/image/local.sh: drop ${INFINITO_DISTRO:-debian}
fallback; require INFINITO_DISTRO via :? error.
- scripts/tests/deploy/ci/dedicated.sh: drop local _container fallback.
- scripts/tests/deploy/local/deploy/fresh-kept-app.sh: drop redundant
${INFINITO_DISTRO:-debian} reassignment after sourcing env/all.sh
(defaults.sh already defaults the value).
- scripts/tests/deploy/local/deploy/fresh-purged-app.sh: drop
target_container fallback; INFINITO_CONTAINER is already in env.
- scripts/tests/deploy/local/exec/container.sh: drop the lazy
${INFINITO_CONTAINER:=infinito_nexus_...} default; defaults.sh source
in env/all.sh already guarantees the value.
- scripts/tests/dns.sh: source defaults.sh so callers only need to set
INFINITO_DISTRO (the implicit dependency was previously a footgun).
- scripts/system/tls/trust/{wsl2,linux}.sh: same — source defaults.sh,
drop the ${INFINITO_CONTAINER:-infinito_nexus_debian} fallback in
linux.sh.
- .github/workflows/test-dns.yml: drop redundant
INFINITO_CONTAINER: infinito_nexus_${{ matrix.distro }} from per-step
env blocks (3 sites). The env now flows from INFINITO_DISTRO via the
defaults.sh sourced inside the scripts.
- tests/unit/cli/deploy/development/test_matrix_deploy.py: replace the
module-level os.environ.setdefault('INFINITO_CONTAINER', 'infinito_nexus_arch')
shim — which itself encoded the formula — with a module-level patch of
resolve_container that returns an opaque test-fixture string. Drop the
now-unused distro="arch" field from the _args() Namespace fixture
(deploy.handler stopped consuming it after the --distro arg removal).
Documentation aligned:
- docs/contributing/environment/variables.md: rewrite the INFINITO_CONTAINER
row to spell out the SPOT contract — set automatically by defaults.sh,
never re-derived elsewhere, callers re-source defaults.sh after
changing INFINITO_DISTRO mid-process.
- docs/contributing/artefact/files/compose.yml.md: replace the
INFINITO_DISTRO row (which described the now-removed
`infinito_nexus_${INFINITO_DISTRO:-debian}` interpolation) with an
INFINITO_CONTAINER row noting the strict ${INFINITO_CONTAINER:?...} read.
Verified:
- Formula derivation: 1 production hit (the SPOT in defaults.sh:18).
- INFINITO_CONTAINER fallback patterns (:-/:=): 0.
- --distro CLI arg refs: 0 (one comment explaining the removal).
- make test green: 1553 unit + 168 integration tests, no skipped suites.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
168 lines
5.2 KiB
Bash
Executable File
168 lines
5.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ------------------------------------------------------------
|
|
# Load environment (Single Source of Truth)
|
|
# ------------------------------------------------------------
|
|
ENV_FILE="${ENV_FILE:-env.ci}"
|
|
|
|
if [ ! -f "${ENV_FILE}" ]; then
|
|
echo "ERROR: env file not found: ${ENV_FILE}"
|
|
exit 1
|
|
fi
|
|
|
|
# Export all variables from env file
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "${ENV_FILE}"
|
|
set +a
|
|
|
|
# Source project defaults so INFINITO_CONTAINER auto-derives from
|
|
# INFINITO_DISTRO (single SPOT in scripts/meta/env/defaults.sh) — callers
|
|
# only need to set INFINITO_DISTRO.
|
|
# shellcheck source=scripts/meta/env/defaults.sh
|
|
source scripts/meta/env/defaults.sh
|
|
|
|
# ------------------------------------------------------------
|
|
# Required variables (fail hard if missing)
|
|
# ------------------------------------------------------------
|
|
: "${DNS_IP:?Missing DNS_IP in env file}"
|
|
: "${DOMAIN:?Missing DOMAIN in env file}"
|
|
: "${IP4:?Missing IP4 in env file}"
|
|
: "${INFINITO_CONTAINER:?Missing INFINITO_CONTAINER env (e.g. infinito_nexus_arch)}"
|
|
|
|
SUBDOMAIN="foo.${DOMAIN}"
|
|
IP4_EXPECTED="${IP4}"
|
|
|
|
# ------------------------------------------------------------
|
|
# Output helpers
|
|
# ------------------------------------------------------------
|
|
section() {
|
|
echo
|
|
echo "------------------------------------------------------------"
|
|
echo "$1"
|
|
echo "------------------------------------------------------------"
|
|
}
|
|
|
|
ok() { echo "OK: $*"; }
|
|
warn() { echo "WARN: $*"; }
|
|
fail() {
|
|
echo "FAIL: $*"
|
|
exit 1
|
|
}
|
|
|
|
# ------------------------------------------------------------
|
|
# Banner
|
|
# ------------------------------------------------------------
|
|
echo "============================================================"
|
|
echo " DNS TEST SUITE"
|
|
echo "============================================================"
|
|
echo "ENV_FILE = ${ENV_FILE}"
|
|
echo "DNS_IP = ${DNS_IP}"
|
|
echo "DOMAIN = ${DOMAIN}"
|
|
echo "SUBDOMAIN = ${SUBDOMAIN}"
|
|
echo "EXPECT IP = ${IP4_EXPECTED}"
|
|
echo "INFINITO = ${INFINITO_CONTAINER}"
|
|
echo
|
|
|
|
# ------------------------------------------------------------
|
|
# Host -> CoreDNS direct
|
|
# ------------------------------------------------------------
|
|
section "Host -> CoreDNS (direct queries)"
|
|
|
|
if command -v dig >/dev/null 2>&1; then
|
|
a1="$(dig @"${DNS_IP}" "${DOMAIN}" A +short | head -n1 || true)"
|
|
a2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" A +short | head -n1 || true)"
|
|
|
|
if [ "${a1}" = "${IP4_EXPECTED}" ]; then
|
|
ok "${DOMAIN} A -> ${a1}"
|
|
else
|
|
fail "${DOMAIN} A failed (got '${a1}')"
|
|
fi
|
|
|
|
if [ "${a2}" = "${IP4_EXPECTED}" ]; then
|
|
ok "${SUBDOMAIN} A -> ${a2}"
|
|
else
|
|
fail "${SUBDOMAIN} A failed (got '${a2}')"
|
|
fi
|
|
else
|
|
warn "dig not found on host — skipping host direct DNS tests"
|
|
fi
|
|
|
|
# ------------------------------------------------------------
|
|
# Host -> CoreDNS AAAA sanity check (must NOT return SERVFAIL)
|
|
# ------------------------------------------------------------
|
|
section "Host -> CoreDNS (AAAA sanity check)"
|
|
|
|
if command -v dig >/dev/null 2>&1; then
|
|
aaaa1="$(dig @"${DNS_IP}" "${DOMAIN}" AAAA +comments +noall +answer || true)"
|
|
aaaa2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" AAAA +comments +noall +answer || true)"
|
|
|
|
echo "AAAA ${DOMAIN}:"
|
|
echo "${aaaa1:-<empty>}"
|
|
echo
|
|
|
|
echo "AAAA ${SUBDOMAIN}:"
|
|
echo "${aaaa2:-<empty>}"
|
|
echo
|
|
|
|
# dig exits 0 even on NXDOMAIN, so we check for SERVFAIL explicitly
|
|
status1="$(dig @"${DNS_IP}" "${DOMAIN}" AAAA +comments 2>&1 | grep -i status || true)"
|
|
status2="$(dig @"${DNS_IP}" "${SUBDOMAIN}" AAAA +comments 2>&1 | grep -i status || true)"
|
|
|
|
echo "${status1}"
|
|
echo "${status2}"
|
|
|
|
echo "${status1}" | grep -qi "SERVFAIL" && fail "AAAA lookup returned SERVFAIL for ${DOMAIN}"
|
|
echo "${status2}" | grep -qi "SERVFAIL" && fail "AAAA lookup returned SERVFAIL for ${SUBDOMAIN}"
|
|
|
|
ok "AAAA sanity check passed (no SERVFAIL)"
|
|
else
|
|
warn "dig not found on host — skipping AAAA sanity test"
|
|
fi
|
|
|
|
# ------------------------------------------------------------
|
|
# CoreDNS container
|
|
# ------------------------------------------------------------
|
|
section "CoreDNS container status"
|
|
|
|
if docker ps --filter name=infinito-coredns --format '{{.Names}}' | grep -q infinito-coredns; then
|
|
docker ps --filter name=infinito-coredns --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}'
|
|
container logs --tail=10 infinito-coredns || true
|
|
ok "CoreDNS container is running"
|
|
else
|
|
fail "CoreDNS container not running"
|
|
fi
|
|
|
|
# ------------------------------------------------------------
|
|
# Infinito outer container DNS
|
|
# ------------------------------------------------------------
|
|
section "Infinito container (outer) DNS"
|
|
|
|
docker exec "${INFINITO_CONTAINER}" sh -lc "
|
|
set -e
|
|
|
|
echo '>>> /etc/resolv.conf'
|
|
cat /etc/resolv.conf || true
|
|
echo
|
|
|
|
echo '>>> getent hosts'
|
|
h1=\$(getent hosts ${DOMAIN} | awk '{print \$1}' || true)
|
|
h2=\$(getent hosts ${SUBDOMAIN} | awk '{print \$1}' || true)
|
|
|
|
echo \"${DOMAIN} -> \${h1}\"
|
|
echo \"${SUBDOMAIN} -> \${h2}\"
|
|
|
|
[ \"\${h1}\" = \"${IP4_EXPECTED}\" ] || exit 11
|
|
[ \"\${h2}\" = \"${IP4_EXPECTED}\" ] || exit 12
|
|
"
|
|
|
|
ok "Outer container DNS works"
|
|
|
|
# ------------------------------------------------------------
|
|
# DONE
|
|
# ------------------------------------------------------------
|
|
section "DONE"
|
|
echo "DNS chain is fully functional:"
|
|
echo "Host -> CoreDNS -> Outer container -> Inner container"
|