#!/usr/bin/env bash # Populates the running test stack with realm users, plus the identity # fixtures of whichever integrations this stack composes. Run after # `docker compose up -d` brings the stack up. # # Idempotent: seed-keycloak.sh is no-op when entities already exist; # render.sh re-templates against the current realm state. Re-run any # time the realm is reseeded or KC volume is wiped. # # Integration steps are skipped, not failed, when that integration's compose # profile is not selected (COMPOSE_PROFILES in test/.env). set -euo pipefail REPO_ROOT="$(git rev-parse --show-toplevel)" TEST_DIR="${REPO_ROOT}/test" cd "$TEST_DIR" # Load this worktree's port/hostname assignments. Without them the seed # scripts fall back to the single-stack defaults (keycloak.localhost:8080) # and cannot reach a slot-allocated stack at all. if [[ ! -f .env ]]; then echo "error: test/.env not found. Run ./bootstrap-stack.sh first." >&2 exit 1 fi set -a # shellcheck source=/dev/null . ./.env set +a # seed-keycloak.sh addresses Keycloak and the forum by their host-facing # URLs; .env carries the parts, not the assembled URLs. export KC_URL="http://${KC_HOSTNAME}:${KEYCLOAK_PORT}" export DISCOURSE_URL="http://${DISCOURSE_HOSTNAME}:${DISCOURSE_PORT}" service_present() { # Empty both when the service is not running and when its profile is # inactive, and tolerant of compose versions that error on an unknown # service — so this needs no knowledge of profile names. [[ -n "$(docker compose ps -q "$1" 2>/dev/null)" ]] } echo "==> Seeding Keycloak realm..." ./seed/keycloak/seed-keycloak.sh echo if service_present fedwiki; then # Through the compose one-shot, not ./seed/fedwiki/render.sh directly: # render.sh is container-native (hardcoded /seed and /data mounts, and it # writes as root so the fedwiki node user can read the result). The service # definition is the only place those mounts and the KC admin credentials # are declared. echo "==> Rendering FedWiki identity fixtures..." docker compose run --rm fedwiki-render echo echo "==> Restarting fedwiki to pick up rendered config.json..." docker compose restart fedwiki else echo "==> Skipping FedWiki fixtures: no fedwiki service in this composition." echo " Add 'fedwiki' to COMPOSE_PROFILES in test/.env and re-run" echo " 'docker compose up -d' to compose the farm." fi echo echo "Stack seeded."