#!/usr/bin/env bash # The installer on clean machines: the generated kit (standalone/default/rigdeps.sh) in # stock distro containers, as a non-root user, the way it reaches a real machine. # Needs docker and the network; takes minutes. Exits 1 on a failure. # Usage: installtest.sh [IMAGE...] default: ubuntu:22.04 debian:trixie-slim, then offline # Notes: docs/notes/installer-testing.md set -uo pipefail cd "$(dirname "$0")" KIT="$(cd .. && pwd)/standalone/default/rigdeps.sh" images=("$@") if [ ${#images[@]} -eq 0 ]; then images=(ubuntu:22.04 debian:trixie-slim); fi rc=0 passed=0 check() { # name, expected, actual if [ "$2" = "$3" ]; then printf ' ok %s\n' "$1" passed=$((passed + 1)) else printf ' FAIL %s\n expected: %s\n got: %s\n' "$1" "$2" "$3" rc=1 fi } if ! docker info >/dev/null 2>&1; then echo "installtest needs a running docker it can reach" >&2 exit 1 fi # A stale kit would test yesterday's installer. if ! bash ./standalone.sh check >/dev/null 2>&1; then echo "the kit is stale — run: make standalone" >&2 exit 1 fi for img in "${images[@]}"; do printf '\n%s\n' "$img" # A stock image has no curl or wget: the installer must say so and stop, not # half-install. This is the bootstrap paradox BOOTSTRAP.md describes. out=$(docker run --rm -v "$KIT:/kit/rigdeps.sh:ro" "$img" bash /kit/rigdeps.sh install dev 2>&1) code=$? check "bare: install refuses" "1" "$code" check "bare: and names what is missing" "yes" \ "$(grep -q 'neither curl nor wget' <<< "$out" && echo yes || echo no)" # The one root step a machine owner takes, then everything else as a plain user — # the Workspace's case: no sudo from the installer, tools in ~/.local/bin. out=$(docker run --rm -v "$KIT:/kit/rigdeps.sh:ro" "$img" bash -c ' set -e apt-get update -qq >/dev/null DEBIAN_FRONTEND=noninteractive apt-get install -y -qq curl ca-certificates >/dev/null useradd -m t su t -s /bin/bash -c " set -e bash /kit/rigdeps.sh install dev echo ==verify; PATH=\$HOME/.local/bin:\$PATH bash /kit/rigdeps.sh verify dev echo ==manifests; bash /kit/rigdeps.sh manifests --to \$HOME/m echo ==bin; ls \$HOME/.local/bin echo ==m; ls \$HOME/m "' 2>&1) code=$? check "user: install, verify and manifests succeed" "0" "$code" check "user: the dev tier lands in ~/.local/bin" "ctlptl docker-compose jq kind kubectl tilt" \ "$(sed -n '/^==bin$/,/^==m$/p' <<< "$out" | grep -vE '^==' | sort | xargs)" check "user: tells them to put it on PATH" "yes" \ "$(grep -q 'Put the toolchain on your PATH' <<< "$out" && echo yes || echo no)" check "user: the three manifests, verified" "3" \ "$(sed -n '/^==m$/,$p' <<< "$out" | grep -c '\.yaml$')" if [ "$code" -ne 0 ]; then printf '%s\n' "$out" | tail -15 | sed 's/^/ | /'; fi done # The air-gapped path: everything baked into the image, then run with no network at all. printf '\noffline (deps-full, --network none)\n' tag="rig-installtest:full" if docker build -q -f Dockerfile.deps --target deps-full -t "$tag" .. >/dev/null 2>&1; then out=$(docker run --rm --network none --entrypoint bash "$tag" -c ' set -e /work/rigdeps.sh install dev /work/rigdeps.sh manifests --to /tmp/m echo ==bin; ls /out/bin echo ==m; ls /tmp/m' 2>&1) code=$? check "offline: install and manifests succeed" "0" "$code" check "offline: the dev tier, from the image" "ctlptl docker-compose jq kind kubectl tilt" \ "$(sed -n '/^==bin$/,/^==m$/p' <<< "$out" | grep -vE '^==' | sort | xargs)" check "offline: the three manifests, from the image" "3" \ "$(sed -n '/^==m$/,$p' <<< "$out" | grep -c '\.yaml$')" if [ "$code" -ne 0 ]; then printf '%s\n' "$out" | tail -15 | sed 's/^/ | /'; fi docker rmi -f "$tag" >/dev/null 2>&1 || true else check "offline: the deps-full image builds" "yes" "no" fi printf '\n' if [ "$rc" -eq 0 ]; then printf '%d install checks passed\n' "$passed" else printf 'FAILED — the installer did not do on a clean machine what it says\n' >&2 fi exit "$rc"