myxce/src/xceadmin/meson-build.sh
Rongsong Shen 0f1df4998e
feat(deploy,xceadmin): standalone xceadmin packaging + deploy-ha usability (bug-1566)
Three related enhancements to make /xce-deploy-ha's output a
self-contained, directly-usable cluster for manual testing:

- xceadmin now builds an installable wheel (meson-build.sh) with
  correct dependencies (click/pycapnp/PyYAML/jsonschema, verified
  against actual imports -- pyproject.toml was missing several).
- deploy-ha.sh resolves the deploy environment's own bash
  ($BASH_BIN, baked into every generated script's shebang -- this
  environment's deploy-ha.sh had drifted to #!/bin/sh while still
  using bash-only syntax) and generates scripts/start-worker.sh /
  scripts/start-scheduler.sh sharing the controllers' --peers, plus
  a standalone xceadmin install (wheel extracted directly, resolved
  $PYTHONPATH baked into a wrapper script -- nix devShell packages
  are $PYTHONPATH entries, not merged into python3's own
  site-packages, so a --system-site-packages venv can't see them).
- bug-1566: xceadmin's --controller option had no relationship to a
  deployment's actual peers (hardcoded localhost:9991 default) --
  every command required an explicit --controller or silently tried
  the wrong port. Fixed via a $XCEADMIN_CONTROLLER envvar fallback
  (click precedence: explicit flag > envvar > bare default),
  exported by deploy-ha.sh's generated scripts/xceadmin wrapper.

Fixed/validated via TDD + live reproduction against a real deployed
cluster in a fully stripped environment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-17 10:20:52 +00:00

81 lines
3.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# Meson-driven xceadmin build: install + test out-of-tree, in the meson
# build directory. Never writes into the live source checkout -- unlike
# xce-build.sh's separate xceadmin case (editable install, .venv inside
# src/xceadmin/, meant for fast dev-loop iteration), this path is what
# `meson compile`/`nix build .#xcecore` actually invoke, and both need
# the same purity guarantee every other meson subdir here already has.
#
# Several tests reach for sibling directories outside xcecommon/xceadmin's
# own tree via a fixed relative path (src/configs/, src/schema/, ha/data/
# -- e.g. test_validation.py's REPO_CONFIGS_DIR deliberately fails loud
# rather than skips if that layout assumption breaks, by design). Rather
# than touch test code, this script recreates the exact repo layout
# out-of-tree via symlinks (read-only references, never a write into the
# real tree) so every one of those relative-path assumptions still
# resolves correctly from the copied location.
set -euo pipefail
SOURCE_DIR="$1" # .../src/xceadmin (meson.current_source_dir())
BUILD_DIR="$2" # .../xceadmin (meson.current_build_dir())
REPO_ROOT="$3" # real repo root (contains ha/, src/)
PYTHON="$4" # meson's resolved python3 (import('python').find_installation()),
# NOT a bare `python3` PATH lookup -- see meson.build's comment
STAMP_FILE="$5"
SRC_DIR="$REPO_ROOT/src"
MIRROR_DIR="$BUILD_DIR/repo-mirror"
WORK_DIR="$MIRROR_DIR/src/xceadmin"
VENV_DIR="$BUILD_DIR/.venv"
echo "=== xceadmin (meson): staging out-of-tree repo-layout mirror ==="
rm -rf "$MIRROR_DIR"
mkdir -p "$MIRROR_DIR/src"
ln -s "$REPO_ROOT/ha" "$MIRROR_DIR/ha"
ln -s "$SRC_DIR/configs" "$MIRROR_DIR/src/configs"
ln -s "$SRC_DIR/schema" "$MIRROR_DIR/src/schema"
cp -r "$SOURCE_DIR" "$WORK_DIR"
# Never trust a stray dev-loop artifact from the live checkout (xce-build.sh's
# own editable-install byproducts, if this happens to be a live checkout and
# not a nix-sandboxed source copy) -- always start from a clean tree.
rm -rf "$WORK_DIR/.venv" "$WORK_DIR/build" "$WORK_DIR"/src/*.egg-info \
"$WORK_DIR/.pytest_cache" "$WORK_DIR/.ruff_cache" \
"$WORK_DIR/src/xcecommon/schema_files"
find "$WORK_DIR" -name "__pycache__" -type d -prune -exec rm -rf {} +
SCHEMA_DST="$WORK_DIR/src/xcecommon/schema_files"
echo "=== xceadmin (meson): syncing bundled schemas ==="
mkdir -p "$SCHEMA_DST/json"
cp "$SRC_DIR/schema/controller.capnp" "$SCHEMA_DST/controller.capnp"
cp "$SRC_DIR/schema/c.capnp" "$SCHEMA_DST/c.capnp"
cp "$SRC_DIR/configs/schema/"*.schema.json "$SCHEMA_DST/json/"
echo "=== xceadmin (meson): pinned install into build-dir venv (python: $PYTHON) ==="
rm -rf "$VENV_DIR"
"$PYTHON" -m venv --system-site-packages "$VENV_DIR"
"$VENV_DIR/bin/pip" install "$WORK_DIR" --quiet
echo "=== xceadmin (meson): running tests ==="
"$VENV_DIR/bin/python" -m pytest "$WORK_DIR/tests" -v
# Build an installable wheel from the SAME schema-synced $WORK_DIR the pinned
# install above just tested -- not a second, separately-assembled tree --
# so the wheel is guaranteed to carry the identical schema_files/ package
# data (Requirement 5.5) the just-passed test run actually exercised. Only
# reached after `set -e` has let the test run above succeed, so a wheel is
# never produced (or left stale) from a red test run. --no-deps: this is
# xceadmin's own wheel only, not a vendored bundle of click/pycapnp/etc --
# installing it still needs those from PyPI or (preferably) the nix shell,
# same as the pinned install just above.
DIST_DIR="$BUILD_DIR/dist"
echo "=== xceadmin (meson): building installable wheel ==="
rm -rf "$DIST_DIR"
mkdir -p "$DIST_DIR"
"$VENV_DIR/bin/pip" wheel "$WORK_DIR" --no-deps -w "$DIST_DIR" --quiet
WHEEL_FILE=$(ls "$DIST_DIR"/xceadmin-*.whl)
echo "=== xceadmin (meson): wheel built at $WHEEL_FILE ==="
touch "$STAMP_FILE"
echo "=== xceadmin (meson): done ==="