#!/usr/bin/env bash # Bring-up runs of nisse-review on this development VM (Development Plan M7.3). # # It runs from the exported code under test, in a virtualenv of its own, as a # transient systemd unit, so it outlives the shell that started it. It runs # from its image after M7.6, and on the agent host after M7.7. # # scripts/review-bringup.sh start [REF] export REF (default HEAD), install # it, and start the reviewer # scripts/review-bringup.sh stop stop it cleanly (SIGTERM) # scripts/review-bringup.sh status the unit, and its items # scripts/review-bringup.sh logs follow its log # # Layout, under $REVIEW (default /root/nisse-review): # nisse-review.yaml, .env the config and its secrets (made by hand once) # code/, venv/ the exported code and its install # state.db, scratch/ its state, and repository trees while reviewing # vault/ its memory (memory/nisse-review) set -euo pipefail REVIEW=${NISSE_REVIEW:-/root/nisse-review} SRC=${NISSE_SRC:-/root/nisse} UNIT=nisse-review-bringup export PATH="$HOME/.local/bin:$PATH" die() { echo "review-bringup: $*" >&2; exit 1; } running() { systemctl is-active --quiet "$UNIT"; } cmd_start() { local ref=${1:-HEAD} sha [ -f "$REVIEW/nisse-review.yaml" ] && [ -f "$REVIEW/.env" ] || die "no config in $REVIEW" running && die "already running; stop it first" sha=$(git -C "$SRC" rev-parse --verify "$ref^{commit}") || die "unknown ref $ref" rm -rf "$REVIEW/code" && mkdir -p "$REVIEW/code" "$REVIEW/vault/memory/nisse-review" git -C "$SRC" archive "$sha" | tar -x -C "$REVIEW/code" UV_PROJECT_ENVIRONMENT="$REVIEW/venv" uv sync -q --frozen --no-dev \ --package nisse-review --no-editable --project "$REVIEW/code" echo "$sha" > "$REVIEW/run-info" systemd-run --unit="$UNIT" --collect \ -p WorkingDirectory="$REVIEW" \ -E NISSE_CONFIG="$REVIEW/nisse-review.yaml" -E NISSE_ENV="$REVIEW/.env" \ "$REVIEW/venv/bin/nisse-review" echo "started $UNIT at $sha" } cmd_stop() { running && systemctl stop "$UNIT" || echo "not running"; } cmd_status() { systemctl status "$UNIT" --no-pager || true [ -f "$REVIEW/state.db" ] && sqlite3 "$REVIEW/state.db" \ "SELECT id, position, status, outcome FROM work_items ORDER BY opened_at" } cmd_logs() { journalctl -u "$UNIT" -f; } case "${1:-}" in start) shift; cmd_start "$@" ;; stop) cmd_stop ;; status) cmd_status ;; logs) cmd_logs ;; *) die "usage: $0 start [REF] | stop | status | logs" ;; esac