Files
stack/dev/scripts/test_network_isolation.sh
kert 85ce5e719d
Some checks failed
CI / skinny-install (aco) (push) Successful in 45s
CI / skinny-install (api) (push) Successful in 29s
CI / skinny-install (bcda) (push) Successful in 25s
CI / skinny-install (bib) (push) Successful in 23s
CI / skinny-install (bls) (push) Successful in 20s
CI / skinny-install (ccw) (push) Successful in 36s
CI / skinny-install (cli) (push) Successful in 27s
CI / skinny-install (cms) (push) Successful in 24s
CI / skinny-install (conf) (push) Successful in 27s
CI / skinny-install (pfs) (push) Successful in 25s
CI / skinny-install (rex) (push) Successful in 25s
CI / lint-test (push) Successful in 6m2s
Infra CI / notebooks (push) Successful in 7s
Infra CI / zotero (push) Failing after 6s
Infra CI / docs (push) Successful in 33s
Infra CI / api (push) Successful in 6s
Infra CI / mc (push) Successful in 7s
Deploy / build-scan-report (push) Has been cancelled
chore: clean sweep — lint, format, stale refs, generated artifacts
- Fix all 72 ruff lint errors (unused imports, unused variables, E402)
- Format all 14 unformatted dev/scripts files
- Move generated artifacts to assets/ (dag.html, pfs.html)
- Remove duplicate root coverage.svg (already in assets/icons/)
- Update .dockerignore for infra/ tree layout
- Update .gitignore: add .env.bak, mirrors/, htmlcov/
- Fix stale path refs in coverage_badge.py, woodpecker backend,
  test_network_isolation.sh, docs custom.css
- Add .gitkeep to empty dirs (infra/polaris, cloud/*/terraform)
- Delete 12 stale local branches, 10 stale remote branches
2026-03-24 17:33:55 -04:00

98 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# test_network_isolation.sh — Verify Docker builds succeed without internet.
#
# Builds each Dockerfile with --network=none to prove all packages
# come from local mirrors. Requires mirrors to be running first.
#
# Usage:
# bash dev/scripts/test_network_isolation.sh # test all
# bash dev/scripts/test_network_isolation.sh api docs # test specific images
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
MANIFEST="${ROOT}/data/pkg-manifest.json"
if [ ! -f "$MANIFEST" ]; then
echo "ERROR: ${MANIFEST} not found. Run: uv run python dev/scripts/pkg_inventory.py"
exit 2
fi
# Image definitions — matches stack.toml [images]
declare -A DOCKERFILES=(
[api]="infra/images/api.Dockerfile"
[notebooks]="infra/images/notebooks.Dockerfile"
[docs]="infra/images/docs.Dockerfile"
[zotero]="infra/images/zotero.Dockerfile"
[mc]="infra/images/mc.Dockerfile"
)
declare -A CONTEXTS=(
[api]="."
[notebooks]="notebooks/"
[docs]="."
[zotero]="zotero/"
[mc]="infra/rustfs/"
)
# Select images to test
if [ $# -gt 0 ]; then
IMAGES=("$@")
else
IMAGES=("${!DOCKERFILES[@]}")
fi
PASS=0
FAIL=0
SKIP=0
echo "=== Network Isolation Test ==="
echo "Testing ${#IMAGES[@]} image(s) with --network=none"
echo ""
for img in "${IMAGES[@]}"; do
dockerfile="${DOCKERFILES[$img]:-}"
context="${CONTEXTS[$img]:-}"
if [ -z "$dockerfile" ]; then
echo "SKIP $img (unknown image)"
((SKIP++))
continue
fi
echo -n "TEST $img ... "
# Build with no network — will fail if any RUN step needs internet
if docker build \
--network=none \
-f "${ROOT}/${dockerfile}" \
-t "isolation-test/${img}:test" \
"${ROOT}/${context}" \
> "/tmp/isolation-${img}.log" 2>&1; then
echo "PASS"
((PASS++))
# Clean up test image
docker rmi "isolation-test/${img}:test" > /dev/null 2>&1 || true
else
echo "FAIL"
echo " Build log: /tmp/isolation-${img}.log"
echo " Last 5 lines:"
tail -5 "/tmp/isolation-${img}.log" | sed 's/^/ /'
((FAIL++))
fi
done
echo ""
echo "=== Results ==="
echo " Pass: ${PASS} Fail: ${FAIL} Skip: ${SKIP}"
if [ "$FAIL" -gt 0 ]; then
echo ""
echo "FAILED — ${FAIL} image(s) require external network access."
echo "Ensure mirrors are running: docker compose up -d apt-cache devpi"
exit 1
fi
echo "All images build without external network access."
exit 0