mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
The image runs this module from a layer that holds three files of utils: __init__.py, install/__init__.py and install/collections.py, the sliceef45d69dc3cut so the source tree cannot invalidate the collection install.67f5398985established that the module therefore stays on the standard library, andd4ae5cf9f0broke it 15 minutes later by routing the reads through utils.cache.files to satisfy the cache-read lint. The import raises ModuleNotFoundError: No module named 'utils.cache' in that layer, which no import inside a full checkout can show, because this repository installs utils into site-packages. Nothing turned red. The caller reads only the exit code, and the module's contract is exit 1 with the missing collections on stdout, so a crash - exit 1, nothing on stdout - is indistinguishable from work to do. Every image build since has reinstalled every collection with --force-with-deps, which is the cost the check exists to avoid. The deploy job the traceback was found in finished green. The reads go back to Path.read_text with a cache-read marker each. The cache was never earning its place here: read_text is an lru_cache keyed on the path, and one run reads the requirements file once and one MANIFEST.json per collection, eight distinct paths, none of them twice. Copying utils/cache into the slice instead would work - the closure is three stdlib-only files - but it binds a package with 51 commits in the last twelve months to the layer that installs ansible, in front of a cache with no possible hit. The caller now exits 3 when a non-zero status arrives with an empty stdout, a state the contract cannot produce, so the next crash stops the install instead of quietly reinstalling everything. all.sh runs under set -e and touches the stamp only after ansible.sh returns, so the failure also leaves the stamp stale rather than recording an install that did not happen. The probe that would have caught this builds the slice in a tempdir from the Dockerfile's own COPY lines and runs the module inside it. It has to pass python -S: without it the interpreter resolves every submodule from the installed checkout however the slice is built, and the test passes on a module that cannot import in the image. Verified by injecting the import back into the tempdir copy, which reproduces the traceback verbatim. Delta measured by loading the committed module and this one side by side: identical on both requirements files, against the real collections directory and an empty one, on a missing file, on non-UTF-8 input and on a corrupt MANIFEST.json. The one behavioural difference is that a file changed within a process is now read fresh rather than from the memo. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
94 lines
2.5 KiB
Bash
Executable File
94 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
echo "📦 Installing Ansible collections"
|
|
|
|
: "${PYTHON:?PYTHON not set}"
|
|
: "${ANSIBLE_COLLECTIONS_DIR:?ANSIBLE_COLLECTIONS_DIR not set}"
|
|
|
|
echo "→ Target: ${ANSIBLE_COLLECTIONS_DIR}"
|
|
mkdir -p "${ANSIBLE_COLLECTIONS_DIR}"
|
|
|
|
MAX_ATTEMPTS=5
|
|
ATTEMPT=1
|
|
INSTALL_TIMEOUT=15m
|
|
|
|
GALAXY_REQ="requirements/requirements.galaxy.yml"
|
|
GIT_REQ="requirements/requirements.git.yml"
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
|
cd "${REPO_ROOT}"
|
|
|
|
if [[ -z "${INFINITO_ANSIBLE_COLLECTIONS_SOURCE:-}" ]]; then
|
|
# shellcheck source=/dev/null
|
|
source <(grep -E '^INFINITO_ANSIBLE_COLLECTIONS_SOURCE=' default.env)
|
|
fi
|
|
|
|
: "${INFINITO_ANSIBLE_COLLECTIONS_SOURCE:?not declared in default.env}"
|
|
|
|
case "${INFINITO_ANSIBLE_COLLECTIONS_SOURCE}" in
|
|
galaxy) SOURCE_ORDER=("Galaxy:${GALAXY_REQ}" "Git:${GIT_REQ}") ;;
|
|
git) SOURCE_ORDER=("Git:${GIT_REQ}" "Galaxy:${GALAXY_REQ}") ;;
|
|
*)
|
|
echo "❌ INFINITO_ANSIBLE_COLLECTIONS_SOURCE must be 'galaxy' or 'git'," \
|
|
"got '${INFINITO_ANSIBLE_COLLECTIONS_SOURCE}'" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
if MISSING="$("${PYTHON}" -m utils.install.collections "${GALAXY_REQ}" "${ANSIBLE_COLLECTIONS_DIR}")"; then
|
|
echo "✅ Every pinned collection is already installed"
|
|
echo "🎉 All collections are ready"
|
|
exit 0
|
|
fi
|
|
if [ -z "${MISSING}" ]; then
|
|
echo "❌ The collection check exited non-zero without naming a collection," \
|
|
"so it crashed rather than finding work; see its traceback above" >&2
|
|
exit 3
|
|
fi
|
|
echo "→ Not satisfied yet: ${MISSING}"
|
|
|
|
installed=0
|
|
while ((installed == 0)); do
|
|
echo "▶️ Attempt ${ATTEMPT}/${MAX_ATTEMPTS}"
|
|
|
|
for entry in "${SOURCE_ORDER[@]}"; do
|
|
label="${entry%%:*}"
|
|
req="${entry#*:}"
|
|
|
|
echo "🌐 Trying ${label} source (${req})…"
|
|
if timeout --foreground "${INSTALL_TIMEOUT}" \
|
|
"${PYTHON}" -m ansible.cli.galaxy collection install \
|
|
-r "${req}" \
|
|
-p "${ANSIBLE_COLLECTIONS_DIR}" \
|
|
--force-with-deps; then
|
|
|
|
echo "✅ Collections installed successfully via ${label} on attempt ${ATTEMPT}"
|
|
installed=1
|
|
break
|
|
fi
|
|
|
|
echo "⚠️ ${label} install failed on attempt ${ATTEMPT}"
|
|
done
|
|
|
|
if ((installed == 1)); then
|
|
break
|
|
fi
|
|
|
|
if ((ATTEMPT >= MAX_ATTEMPTS)); then
|
|
echo "❌ Installation failed after ${MAX_ATTEMPTS} attempts."
|
|
echo " Galaxy and Git fallback both failed."
|
|
exit 1
|
|
fi
|
|
|
|
SLEEP_TIME=$((60 + RANDOM % 61))
|
|
echo "⏸️ Attempt ${ATTEMPT} failed for both sources."
|
|
echo " Waiting ${SLEEP_TIME}s before retry…"
|
|
|
|
sleep "${SLEEP_TIME}"
|
|
((ATTEMPT++))
|
|
done
|
|
|
|
echo "🎉 All collections are ready"
|