diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.sh index 71b9fe4..12e35fd 100755 --- a/scripts/smoke-test.sh +++ b/scripts/smoke-test.sh @@ -1,40 +1,91 @@ #!/usr/bin/env bash -# Smoke-test a built k8s-debug image: every advertised tool must exist and -# the pinned binaries must run. Usage: scripts/smoke-test.sh [image] +# Smoke-test a built k8s-debug image. +# +# scripts/smoke-test.sh [image] [--db-clients] +# +# Checks (all inside ONE container, so it costs a single container start): +# 1. every advertised tool exists on PATH +# 2. tools that matter during an incident actually execute (catches +# wrong-arch downloads and missing shared libraries, which `command -v` +# cannot) +# 3. pinned tool versions match the ARGs in the Dockerfile +# 4. the interactive shell config loads (alias, completion, banner) +# --db-clients additionally requires redis-cli, psql and mysql (image built +# with INSTALL_DB_CLIENTS=true). set -euo pipefail -IMAGE="${1:-k8s-debug:dev}" +IMAGE="k8s-debug:dev" +DB_CLIENTS=false +for a in "$@"; do + case "$a" in + --db-clients) DB_CLIENTS=true ;; + *) IMAGE="$a" ;; + esac +done + +DOCKERFILE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/Dockerfile" +arg() { sed -n "s/^ARG $1=//p" "$DOCKERFILE" | head -n1; } + +# --- Test body: runs inside the container. Prints FAIL lines, exits non-zero. +read -r -d '' BODY <<'INNER' || true +fail=0 +bad() { echo "FAIL: $*"; fail=1; } -TOOLS=( - curl wget dig nslookup drill ping traceroute mtr tcpdump nmap ncat nc socat +tools="curl wget dig nslookup drill ping traceroute mtr tcpdump nmap ncat nc socat ss ip iptables nft conntrack ethtool iperf3 openssl strace ltrace gdb lsof htop pidstat iostat iotop bpftrace ps - jq yq kubectl stern grpcurl git ssh python3 vi nano -) + jq yq kubectl stern grpcurl git ssh python3 vi nano" +[ "$DB_CLIENTS" = true ] && tools="$tools redis-cli psql mysql" +for t in $tools; do command -v "$t" >/dev/null || bad "missing tool: $t"; done -fail=0 -for t in "${TOOLS[@]}"; do - if ! docker run --rm --entrypoint bash "$IMAGE" -c "command -v $t" >/dev/null; then - echo "MISSING: $t" - fail=1 - fi -done +# Must execute, not just exist. +run() { "$@" >/dev/null 2>&1 || bad "does not run: $*"; } +run kubectl version --client +run yq --version +run stern --version +run grpcurl -version +run jq --version +run tcpdump --version +run strace -V +run gdb --version +run bpftrace --version +run nmap --version +run dig -v +run openssl version +run iperf3 --version +run python3 --version + +# Pinned versions must match the Dockerfile ARGs. +ver() { #