Files
computer-playbook/scripts/tests/deploy/swarm/utils/release.sh
T
kevinveenbirkenbachandClaude Opus 5.5 74d99201e0 feat(cache): share package and tool caches across stacks and release swarm clusters after rescue
Parallel compose slots, swarm lab clusters and GUI lanes each kept their own pip, npm and pacman downloads, and a failed swarm run left its cluster (about 25 GB of node docker data plus the rescue bundle in the act container) on the root filesystem until someone ran make swarm-down. INFINITO_CACHE_SHARED_HOST_PATH (default <DIR_CACHE>/shared) is now mounted read-write at the same path into every compose slot and every swarm lab node, with PIP_CACHE_DIR and npm_config_cache below it; empty, the renders stay byte-identical to before. On a host whose os-release ID is exactly arch running an arch stack, INFINITO_CACHE_HOST_PACMAN_PATH mounts the host pacman cache read-only and scripts/docker/cache/pacman.sh makes it the first CacheDir with <shared>/pacman/ second, so new downloads land in the shared folder and the host cache stays untouched; on Manjaro and every other host pacman uses the shared folder alone.

make swarm-zombie without keep=true now copies the act job's rescue diagnostics and Playwright artefacts to the host and then releases the lab nodes, the lab network, the NFS export volume and the act outer container, on success and on failure; when the copy fails the nodes still go, the act container stays and the run exits naming make swarm-down. make roundtrip passes keep to every swarm step, make clean-cache removes the shared folder, and the disc-space cleanup skips pacman cache directories it cannot write. apt and dnf keep their per-container caches behind the package-cache proxy, and no docker data root is shared between daemons. Requirement 065.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 22:04:38 +01:00

75 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Param: SWARM_NAME cluster id the drill runs under
# Param: keep true keeps the cluster and the act outer container up; empty or false releases both
# Param: INFINITO_CONTAINER worktree label the act outer containers carry
# Param: INFINITO_RESCUE_DIAGNOSTICS_BASE rescue root, the same path inside the act job and on the host
# Param: $@ the drill command; its exit code is the script's exit code
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../../.." && pwd)"
PLAYWRIGHT_ARTEFACTS=/tmp/playwright-artifacts
: "${SWARM_NAME:?SWARM_NAME is required (the cluster id)}"
: "${keep?keep is required: true keeps the cluster, empty or false releases it}"
: "${INFINITO_CONTAINER:?INFINITO_CONTAINER is not set; source scripts/meta/env/load.sh or invoke via make}"
: "${INFINITO_RESCUE_DIAGNOSTICS_BASE:?INFINITO_RESCUE_DIAGNOSTICS_BASE is not set; source scripts/meta/env/load.sh or invoke via make}"
case "${keep}" in
true | false | "") ;;
*)
echo "release: keep must be true, false or empty, got '${keep}'" >&2
exit 2
;;
esac
[ "$#" -gt 0 ] || {
echo "usage: release.sh <drill command...>" >&2
exit 2
}
save_artefacts() {
local id path out
local -a ids
mapfile -t ids < <(docker ps -aq --filter "name=^act-" --filter "label=infinito.worktree=${INFINITO_CONTAINER}")
for id in "${ids[@]}"; do
for path in "${INFINITO_RESCUE_DIAGNOSTICS_BASE}" "${PLAYWRIGHT_ARTEFACTS}"; do
mkdir -p "${path}"
# nocheck: container-cp - the act outer container runs on this host's own daemon, never on a swarm worker
if out="$(docker cp "${id}:${path}/." "${path}/" 2>&1)"; then
echo "==> release: saved ${path} from act container ${id}"
continue
fi
case "${out}" in
*"Could not find the file"* | *"No such container:path"*)
echo "==> release: act container ${id} holds no ${path}"
;;
*)
echo "==> release: FAILED to save ${path} from act container ${id}: ${out}" >&2
return 1
;;
esac
done
done
}
release() {
local rc=$? saved=true
trap - EXIT
save_artefacts || saved=false
if [ "${keep}" = true ]; then
echo "==> release: keep=true, cluster ${SWARM_NAME} stays up; release it with make swarm-down name=${SWARM_NAME}"
exit "${rc}"
fi
SWARM_NAME="${SWARM_NAME}" INFINITO_KEEP_SWARM_NODES=false \
bash "${SCRIPT_DIR}/clean/teardown.sh"
if [ "${saved}" = true ]; then
bash "${REPO_ROOT}/scripts/tests/deploy/act/down_act_outer.sh"
else
echo "==> release: the act outer container stays because its artefacts could not be copied; copy them, then run make swarm-down name=${SWARM_NAME}" >&2
[ "${rc}" -ne 0 ] || rc=1
fi
exit "${rc}"
}
trap release EXIT
"$@"