|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Cold-start a kurtosis-pos devnet from source. |
| 4 | +# |
| 5 | +# Used by consumers who need to test against an unpublished kurtosis-pos |
| 6 | +# branch (the snapshot publisher only refreshes weekly + only off `main`). |
| 7 | +# Total wall-time: ~10 minutes vs ~30s for the snapshot path. The snapshot |
| 8 | +# is the default; this is the escape hatch. |
| 9 | +# |
| 10 | +# # Inputs (env vars, set by the composite action with documented defaults) |
| 11 | +# |
| 12 | +# KURTOSIS_POS_REF git ref of 0xPolygon/kurtosis-pos to clone. |
| 13 | +# ARGS_FILE kurtosis args file in the consumer's checkout |
| 14 | +# (resolved against GITHUB_WORKSPACE). |
| 15 | +# WORK_DIR scratch dir for the clone. |
| 16 | +# |
| 17 | +# # After this script exits 0 |
| 18 | +# |
| 19 | +# `kurtosis enclave inspect pos` reports RUNNING. Downstream steps reach |
| 20 | +# the chain via the kurtosis-emitted env vars (each consumer's e2e suite |
| 21 | +# already has its own kurtosis adapter — this script doesn't export |
| 22 | +# anything to GITHUB_ENV). |
| 23 | + |
| 24 | +set -euo pipefail |
| 25 | + |
| 26 | +KURTOSIS_POS_REF="${KURTOSIS_POS_REF:-main}" |
| 27 | +ARGS_FILE="${ARGS_FILE:-kurtosis-params.yml}" |
| 28 | +WORK_DIR="${WORK_DIR:-/tmp/kurtosis-pos}" |
| 29 | + |
| 30 | +REPO_ROOT="${GITHUB_WORKSPACE:-$PWD}" |
| 31 | +ARGS_FILE_ABS="${REPO_ROOT}/${ARGS_FILE}" |
| 32 | +if [ ! -f "$ARGS_FILE_ABS" ]; then |
| 33 | + echo "[e2e-cold-start] ERROR: args file not found at ${ARGS_FILE_ABS}" >&2 |
| 34 | + echo "[e2e-cold-start] Pass the path relative to your repo root via the action's args_file input." >&2 |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +############################################################################## |
| 39 | +# 1. Install kurtosis CLI |
| 40 | +############################################################################## |
| 41 | +if command -v kurtosis >/dev/null 2>&1; then |
| 42 | + echo "[e2e-cold-start] kurtosis already installed: $(kurtosis version | head -n1)" |
| 43 | +else |
| 44 | + echo "[e2e-cold-start] installing kurtosis-cli via apt" |
| 45 | + echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" \ |
| 46 | + | sudo tee /etc/apt/sources.list.d/kurtosis.list >/dev/null |
| 47 | + sudo apt-get update -qq |
| 48 | + sudo apt-get install -y --no-install-recommends kurtosis-cli |
| 49 | + # Kurtosis prompts for analytics consent on first interactive use; disable |
| 50 | + # explicitly so the CLI never blocks on stdin in a non-TTY shell. |
| 51 | + kurtosis analytics disable |
| 52 | +fi |
| 53 | + |
| 54 | +############################################################################## |
| 55 | +# 2. Start the kurtosis engine |
| 56 | +############################################################################## |
| 57 | +echo "[e2e-cold-start] starting kurtosis engine" |
| 58 | +kurtosis engine start |
| 59 | + |
| 60 | +############################################################################## |
| 61 | +# 3. Clone kurtosis-pos and run the enclave |
| 62 | +############################################################################## |
| 63 | +if kurtosis enclave inspect pos 2>/dev/null | grep -q RUNNING; then |
| 64 | + echo "[e2e-cold-start] enclave 'pos' already running" |
| 65 | + exit 0 |
| 66 | +fi |
| 67 | + |
| 68 | +if [ ! -d "$WORK_DIR" ]; then |
| 69 | + echo "[e2e-cold-start] cloning kurtosis-pos@${KURTOSIS_POS_REF} into ${WORK_DIR}" |
| 70 | + git clone --depth 1 --branch "$KURTOSIS_POS_REF" \ |
| 71 | + https://github.com/0xPolygon/kurtosis-pos.git "$WORK_DIR" |
| 72 | +fi |
| 73 | + |
| 74 | +# kurtosis-pos hardcodes `MAX_CPU = 4000, MAX_MEM = 16384` for EL services, |
| 75 | +# which exceeds what private-repo GitHub-hosted runners provide (2 vCPU, |
| 76 | +# 7 GB). Scale down in place so the enclave fits on ubuntu-latest. On a |
| 77 | +# developer machine with more headroom this rewrite is a no-op from the |
| 78 | +# suite's perspective — the services just use less of the available |
| 79 | +# capacity. Remove once kurtosis-pos exposes these as inputs. |
| 80 | +# |
| 81 | +# This patch is brittle by nature: it depends on the file path and the |
| 82 | +# variable names. `kurtosis_pos_ref` is consumer-overridable, so an |
| 83 | +# unexpected ref could rename either and make the sed a silent no-op — |
| 84 | +# the enclave would then request 16 GB and the runner OOM-kills it with a |
| 85 | +# confusing failure. Verify the override actually landed and fail loud if |
| 86 | +# not, so the cause is unambiguous. |
| 87 | +shared_star="$WORK_DIR/src/el/shared.star" |
| 88 | +if [ ! -f "$shared_star" ]; then |
| 89 | + echo "[e2e-cold-start] ERROR: expected ${shared_star} not found — kurtosis-pos@${KURTOSIS_POS_REF} may have moved the EL resource config. Update cold-start.sh for this ref." >&2 |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | +sed -i.bak -E \ |
| 93 | + -e 's/^MAX_CPU = [0-9]+.*/MAX_CPU = 1800 # CI override (ubuntu-latest 2-vCPU private-repo runner)/' \ |
| 94 | + -e 's/^MAX_MEM = [0-9]+.*/MAX_MEM = 4096 # CI override (ubuntu-latest 7-GB private-repo runner)/' \ |
| 95 | + "$shared_star" |
| 96 | +rm -f "${shared_star}.bak" |
| 97 | +# Confirm both overrides applied — grep for the marker comment the sed adds. |
| 98 | +# Two matches expected (MAX_CPU + MAX_MEM); anything less means a var was |
| 99 | +# renamed and we'd silently run at full resource request. |
| 100 | +override_count="$(grep -c 'CI override (ubuntu-latest' "$shared_star" || true)" |
| 101 | +if [ "$override_count" -ne 2 ]; then |
| 102 | + echo "[e2e-cold-start] ERROR: EL resource scale-down did not apply (${override_count}/2 markers found in ${shared_star}). kurtosis-pos@${KURTOSIS_POS_REF} likely renamed MAX_CPU/MAX_MEM — the runner would OOM. Update the sed patterns for this ref." >&2 |
| 103 | + exit 1 |
| 104 | +fi |
| 105 | + |
| 106 | +echo "[e2e-cold-start] running enclave 'pos' (this takes ~5–10m)" |
| 107 | +( cd "$WORK_DIR" && kurtosis run --enclave pos --args-file "$ARGS_FILE_ABS" . ) |
| 108 | + |
| 109 | +# Export the enclave name so the consumer's e2e suite can locate it via the |
| 110 | +# kurtosis CLI in cold-start mode (symmetric with snapshot mode exporting |
| 111 | +# E2E_SNAPSHOT_ADDRESSES_JSON). Lets a consumer write a single env-driven |
| 112 | +# adapter instead of hardcoding the enclave name per mode. |
| 113 | +if [ -n "${GITHUB_ENV:-}" ]; then |
| 114 | + echo "E2E_KURTOSIS_ENCLAVE=pos" >> "$GITHUB_ENV" |
| 115 | +fi |
| 116 | + |
| 117 | +echo "[e2e-cold-start] ready" |
0 commit comments