diff options
| author | Pjotr <wrk@bosa.lan> | 2026-09-27 14:50:13 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-09-27 14:50:13 +0000 |
| commit | 7b6a8ccfce385a081ee2e9ca21469b91de491a0d (patch) | |
| tree | 328a98f3ee6f17d2a7635ab6384c0aa10cec4e97 | |
| parent | bec3b5fd138cf3364837f490bd113d84a43d2ecb (diff) | |
| download | gn-bnw-7b6a8ccfce385a081ee2e9ca21469b91de491a0d.tar.gz | |
test: run the full container cycle (build, start, test, stop)
test/run_container_tests.sh builds the bnw-container definition, starts it through the run-guix-system-container daemon, waits for the web server on port 8881, runs the 22-check HTTP suite and the container tool check over ssh, and stops the container (kept on failure or --keep for debugging).
| -rw-r--r-- | README.md | 11 | ||||
| -rwxr-xr-x | test/run_container_tests.sh | 113 |
2 files changed, 124 insertions, 0 deletions
diff --git a/README.md b/README.md index 12de8a5d..d1ce9660 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,17 @@ A second script, `test/check_container_tools.sh`, verifies that every unix tool BNW calls externally exists in the (container) environment; run it inside the container. +`test/run_container_tests.sh` does the whole cycle: it builds the +system container (gn-machines/genenetwork/services/bnw-container.scm, +needing the guix-bioinformatics and gn-machines channels on the load +path), starts it through the run-guix-system-container daemon, waits +for the web server, runs the HTTP test suite and the tool check, and +stops the container again (kept running on failure, or with --keep): + +```sh +test/run_container_tests.sh # or --keep to inspect afterwards +``` + Memory footprint measured in a Guix system container (8-node example run, php-fpm + nginx + octave + shepherd): diff --git a/test/run_container_tests.sh b/test/run_container_tests.sh new file mode 100755 index 00000000..72db1ecd --- /dev/null +++ b/test/run_container_tests.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# Build the BNW system container, start it through the +# run-guix-system-container daemon, wait for the web server, and run +# the HTTP functional test suite plus the container tool check. +# +# Usage (from anywhere): +# test/run_container_tests.sh [--keep] +# +# --keep leave the container running after the run (default: +# killed on success, kept on failure for debugging) +# +# Environment overrides: +# FACTORY factory root (default: derived from this script) +# DAEMON daemon address (default 127.0.0.1:8900) +# BASE_URL BNW base url (default http://127.0.0.1:8881) + +set -u + +HERE="$(cd "$(dirname "$0")" && pwd)" +FACTORY="${FACTORY:-$(cd "$HERE/../../.." && pwd)}" +DAEMON="${DAEMON:-127.0.0.1:8900}" +export BASE_URL="${BASE_URL:-http://127.0.0.1:8881}" + +GUIX_BIOINF="$FACTORY/code/guix-bioinformatics" +GN_MACHINES="$FACTORY/code/gn-machines" +CONTAINER_SCM="$GN_MACHINES/genenetwork/services/bnw-container.scm" +RUN_GUIX_CONTAINER="$FACTORY/code/run-guix-container/bin/run-guix-container.rb" +CLIENT_KEY="$FACTORY/code/run-guix-container/etc/hello-container-key" +SSH_PORT=2222 +SSH_BIN="${SSH_BIN:-$(command -v ssh || echo /gnu/store/by018qdrlqk5akqkh7c9l6g1j2nijm2p-openssh-10.3p1/bin/ssh)}" + +KEEP=0 +[ "${1:-}" = "--keep" ] && KEEP=1 + +die() { echo "ERROR: $*" >&2; exit 1; } + +client() { "$RUN_GUIX_CONTAINER" --daemon "$DAEMON" "$@"; } + +# --- 1. stop any container the daemon is currently running ------------ +echo "== stopping any running container ==" +for pid in $(client --list 2>/dev/null | awk '$1 ~ /^[0-9]+$/ {print $1}'); do + echo "killing $pid" + client --kill "$pid" >/dev/null 2>&1 +done +sleep 2 + +# --- 2. build the container ------------------------------------------- +echo "== building container ==" +HASH=$(guix system container --network \ + -L "$GUIX_BIOINF" -L "$GN_MACHINES" \ + "$CONTAINER_SCM" 2>/dev/null | tail -1) +[ -n "$HASH" ] || die "container build failed" +echo "built: $HASH" + +# --- 3. start it via the daemon --------------------------------------- +echo "== starting container ==" +OUT=$(client "$HASH" 2>&1) || true +PID=$(echo "$OUT" | awk '/^OK/ {print $2}') +if [ -z "$PID" ]; then + # a container may still be running (stray); try once more + for pid in $(client --list 2>/dev/null | awk '$1 ~ /^[0-9]+$/ {print $1}'); do + client --kill "$pid" >/dev/null 2>&1 + done + sleep 3 + OUT=$(client "$HASH" 2>&1) || true + PID=$(echo "$OUT" | awk '/^OK/ {print $2}') +fi +[ -n "$PID" ] || die "could not start container: $OUT" +echo "running as PID $PID" + +cleanup() { + if [ "$KEEP" = 1 ] || [ "${FAILED:-0}" -gt 0 ]; then + echo "container $PID left running (inspect via ssh -p $SSH_PORT + -i $CLIENT_KEY root@127.0.0.1 or http://127.0.0.1:8881/)" + else + echo "== stopping container ==" + client --kill "$PID" >/dev/null 2>&1 + fi +} +trap cleanup EXIT + +# --- 4. wait for the web server --------------------------------------- +echo "== waiting for the web server ==" +UP=0 +for i in $(seq 1 30); do + code=$(curl -s -m 3 -o /dev/null -w '%{http_code}' "$BASE_URL/" 2>/dev/null) + if [ "$code" = 200 ]; then UP=1; break; fi + sleep 4 +done +[ "$UP" = 1 ] || die "web server did not come up on $BASE_URL" +echo "web server is up" + +# --- 5. run the tests --------------------------------------------------- +echo "== HTTP functional tests ==" +python3 "$HERE/bnw_http_tests.py" +TEST_RC=$? + +echo "== container tool check ==" +"$SSH_BIN" -p "$SSH_PORT" -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null -i "$CLIENT_KEY" -o ConnectTimeout=10 \ + root@127.0.0.1 'bash -s' < "$HERE/check_container_tools.sh" +TOOLS_RC=$? + +echo +if [ "$TEST_RC" = 0 ] && [ "$TOOLS_RC" = 0 ]; then + echo "== ALL CONTAINER TESTS PASSED ==" + FAILED=0 + exit 0 +else + echo "== CONTAINER TESTS FAILED (tests=$TEST_RC tools=$TOOLS_RC) ==" + FAILED=1 + exit 1 +fi |
