marchwarden/scripts/docker-test.sh

63 lines
1.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Helper for the dockerized test/run environment.
#
# Usage:
# scripts/docker-test.sh build Build the image
# scripts/docker-test.sh test Run pytest in the container
# scripts/docker-test.sh ask "..." Run `marchwarden ask` end-to-end
# (mounts ~/secrets ro and ~/.marchwarden rw)
# scripts/docker-test.sh shell Drop into a bash shell in the container
set -euo pipefail
IMAGE="marchwarden-test"
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cmd="${1:-test}"
shift || true
case "$cmd" in
build)
docker build -t "$IMAGE" "$ROOT"
;;
test)
docker run --rm -v "$ROOT:/app" "$IMAGE" pytest -q "$@"
;;
ask)
if [ ! -f "$HOME/secrets" ]; then
echo "error: ~/secrets not found on host" >&2
exit 1
fi
mkdir -p "$HOME/.marchwarden/traces"
docker run --rm -it \
-v "$ROOT:/app" \
-v "$HOME/secrets:/root/secrets:ro" \
-v "$HOME/.marchwarden:/root/.marchwarden" \
"$IMAGE" marchwarden ask "$@"
;;
replay)
mkdir -p "$HOME/.marchwarden/traces"
docker run --rm \
-v "$ROOT:/app" \
-v "$HOME/.marchwarden:/root/.marchwarden" \
"$IMAGE" marchwarden replay "$@"
;;
shell)
docker run --rm -it \
-v "$ROOT:/app" \
-v "$HOME/secrets:/root/secrets:ro" \
-v "$HOME/.marchwarden:/root/.marchwarden" \
"$IMAGE" bash
;;
*)
echo "unknown command: $cmd" >&2
echo "usage: $0 {build|test|ask|replay|shell}" >&2
exit 1
;;
esac