#!/usr/bin/env bash # Sandcastle → Kubernetes hand-off script. # # Reads the greeting `value` from the Sandcastle-produced branch (default # `sandcastle/hello-world-pico` on the durable target repo the Sandcastle # lab created under work/hello-world-pico-sandcastle/target-repo) and # writes a Crossplane XHelloWorldPico Composite Resource carrying the # same value. The generated XR is the exact shape consumed by the # existing labs/hello-pico-on-kubernetes lab (see its 05-xr.yaml). # # Usage: handoff.sh [] # work-root defaults to work/handoff-sandcastle-to-kubernetes set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" SANDCASTLE_WORK="${SANDCASTLE_WORK:-$REPO_ROOT/work/hello-world-pico-sandcastle}" TARGET_REPO="${TARGET_REPO:-$SANDCASTLE_WORK/target-repo}" BRANCH="${BRANCH:-sandcastle/hello-world-pico}" RULE_PATH="${RULE_PATH:-rules/hello.yaml}" XR_NAME="${XR_NAME:-hello}" WORK_ROOT="${1:-$REPO_ROOT/work/handoff-sandcastle-to-kubernetes}" BUILD_DIR="$WORK_ROOT/build" XR_OUT="$BUILD_DIR/xr.yaml" if [ ! -d "$TARGET_REPO" ]; then printf 'handoff: sandcastle target repo not found at %s\n' "$TARGET_REPO" >&2 printf 'handoff: run labs/hello-world-pico-sandcastle/downloads/sandcastle-run.sh first\n' >&2 exit 2 fi if ! git -C "$TARGET_REPO" rev-parse "$BRANCH" >/dev/null 2>&1; then printf 'handoff: branch %s not found in %s\n' "$BRANCH" "$TARGET_REPO" >&2 exit 2 fi RULE_YAML="$(git -C "$TARGET_REPO" show "${BRANCH}:${RULE_PATH}")" VALUE="$(RULE_YAML="$RULE_YAML" python3 <<'PY' import os, re, sys text = os.environ.get("RULE_YAML", "") val = None for line in text.splitlines(): m = re.match(r"^\s*value\s*:\s*(.+?)\s*$", line) if m: v = m.group(1) if len(v) >= 2 and v[0] == v[-1] and v[0] in ("'", '"'): v = v[1:-1] val = v break if val is None: sys.stderr.write("handoff: could not find `value:` field in rule\n") sys.exit(3) print(val) PY )" if [ -z "$VALUE" ]; then printf 'handoff: empty value extracted from %s on %s\n' "$RULE_PATH" "$BRANCH" >&2 exit 3 fi mkdir -p "$BUILD_DIR" # Emit the XR YAML. Shape matches labs/hello-pico-on-kubernetes/downloads/05-xr.yaml. cat > "$XR_OUT" <