init rig
This commit is contained in:
58
rig/ctrl/docs.sh
Executable file
58
rig/ctrl/docs.sh
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
# Documentation: render the diagrams, and serve the pages.
|
||||
#
|
||||
# The docs are the instructions for building the cluster, so they must work
|
||||
# BEFORE anything else exists. That rules out serving them from the cluster, and
|
||||
# it rules out python -m http.server too — a minimal Debian has no python3. What
|
||||
# it does have, by definition, is Docker: the single prerequisite rig already
|
||||
# demands. So a throwaway nginx container serves a read-only bind mount.
|
||||
#
|
||||
# Rendered SVGs are committed alongside their .dot sources for the same reason:
|
||||
# the pages have to read on a machine with no Graphviz installed.
|
||||
#
|
||||
# Usage: docs.sh serve | graphs
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
source ./lib/config.sh
|
||||
load_config
|
||||
|
||||
REPO="$(cd .. && pwd)"
|
||||
DOCS_PORT="${DOCS_PORT:-$((HTTP_PORT + 4))}" # +4 sits inside this env's block
|
||||
|
||||
serve() {
|
||||
if [ ! -f "$REPO/docs/index.html" ]; then
|
||||
echo "no docs/index.html" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "docs for '$CLUSTER' on http://localhost:${DOCS_PORT}"
|
||||
echo " (ctrl-c to stop; nothing is installed and nothing persists)"
|
||||
docker run --rm \
|
||||
--name "${CLUSTER}-docs" \
|
||||
-p "${DOCS_PORT}:80" \
|
||||
-v "$REPO/docs:/usr/share/nginx/html:ro" \
|
||||
nginx:alpine
|
||||
}
|
||||
|
||||
graphs() {
|
||||
if ! command -v dot >/dev/null 2>&1; then
|
||||
echo "graphviz not found — install with: sudo apt install graphviz" >&2
|
||||
echo "(only needed to re-render; the committed .svg files already work)" >&2
|
||||
exit 1
|
||||
fi
|
||||
shopt -s nullglob
|
||||
local found=0 f out
|
||||
for f in "$REPO"/docs/graphs/*.dot; do
|
||||
out="${f%.dot}.svg"
|
||||
echo " graphviz $(basename "$f") → $(basename "$out")"
|
||||
dot -Tsvg "$f" -o "$out"
|
||||
found=1
|
||||
done
|
||||
[ "$found" -eq 1 ] || echo " no .dot files in docs/graphs/"
|
||||
}
|
||||
|
||||
case "${1:-serve}" in
|
||||
serve) serve ;;
|
||||
graphs) graphs ;;
|
||||
*) echo "usage: $0 [serve|graphs]" >&2; exit 1 ;;
|
||||
esac
|
||||
Reference in New Issue
Block a user