|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Antithesis node container entrypoint. |
| 3 | +# |
| 4 | +# 1. Starts the cardano-node cluster on the shared 'cluster-state' volume so |
| 5 | +# the driver container can reach the node sockets without going over the |
| 6 | +# network (Unix socket on a shared Docker volume). |
| 7 | +# 2. Serves a lightweight HTTP health check on port 8090 over the Antithesis |
| 8 | +# network bridge. Returns "ready" once the cluster socket exists. |
| 9 | +# This cross-container HTTP traffic satisfies the Antithesis |
| 10 | +# "Containers joined the Antithesis network" property. |
| 11 | +# |
| 12 | +# Environment variables: |
| 13 | +# CLUSTER_STATE_DIR Mount point of the shared cluster-state volume |
| 14 | +# (default: /cluster-state). |
| 15 | +# TESTNET_VARIANT Cluster variant passed to prepare_cluster_scripts |
| 16 | +# (default: conway_fast). |
| 17 | + |
| 18 | +set -Eeuo pipefail |
| 19 | + |
| 20 | +# --------------------------------------------------------------------------- |
| 21 | +# 1. Force nix offline — all store paths are pre-built into the image. |
| 22 | +# --------------------------------------------------------------------------- |
| 23 | +echo "offline = true" >> /etc/nix/nix.conf |
| 24 | + |
| 25 | +# --------------------------------------------------------------------------- |
| 26 | +# 2. Point at pre-built binaries and Python venv. |
| 27 | +# --------------------------------------------------------------------------- |
| 28 | +export CARDANO_PREBUILT_DIR=/opt/cardano |
| 29 | +export _VENV_DIR=/opt/tests-venv |
| 30 | +_PATH_PREPEND="/opt/cardano/cardano-node/bin:/opt/cardano/cardano-submit-api/bin:/opt/cardano/cardano-cli/bin:/opt/cardano/bech32/bin" |
| 31 | + |
| 32 | +# --------------------------------------------------------------------------- |
| 33 | +# 3. Cluster state lives on the shared volume so the driver can read sockets. |
| 34 | +# --------------------------------------------------------------------------- |
| 35 | +CLUSTER_STATE_DIR="${CLUSTER_STATE_DIR:-/cluster-state}" |
| 36 | +_INSTANCE_NUM=0 |
| 37 | +_STATE_CLUSTER="${CLUSTER_STATE_DIR}/state-cluster${_INSTANCE_NUM}" |
| 38 | +_SCRIPTS_DEST="${CLUSTER_STATE_DIR}/startup_scripts" |
| 39 | + |
| 40 | +# Local clusters (conway_fast, etc.) use bft1.socket. |
| 41 | +export CARDANO_NODE_SOCKET_PATH="${_STATE_CLUSTER}/bft1.socket" |
| 42 | + |
| 43 | +_output_dir="${ANTITHESIS_OUTPUT_DIR:-/tmp/antithesis}" |
| 44 | +mkdir -p "$_output_dir" "${CLUSTER_STATE_DIR}" |
| 45 | + |
| 46 | +# --------------------------------------------------------------------------- |
| 47 | +# 4. Health check server on port 8090 (Antithesis network bridge traffic). |
| 48 | +# Returns HTTP 200 "ready" once the cluster socket file exists, |
| 49 | +# 503 "starting" while the cluster is still coming up. |
| 50 | +# --------------------------------------------------------------------------- |
| 51 | +python3 -c " |
| 52 | +import os, socket as _s |
| 53 | +_sock_path = os.environ.get('CARDANO_NODE_SOCKET_PATH', '') |
| 54 | +server = _s.socket(_s.AF_INET, _s.SOCK_STREAM) |
| 55 | +server.setsockopt(_s.SOL_SOCKET, _s.SO_REUSEADDR, 1) |
| 56 | +server.bind(('0.0.0.0', 8090)) |
| 57 | +server.listen(64) |
| 58 | +while True: |
| 59 | + conn, _ = server.accept() |
| 60 | + ready = os.path.exists(_sock_path) |
| 61 | + body = b'ready' if ready else b'starting' |
| 62 | + status = b'200 OK' if ready else b'503 Service Unavailable' |
| 63 | + conn.sendall(b'HTTP/1.1 ' + status + b'\r\nContent-Length: ' + str(len(body)).encode() + b'\r\n\r\n' + body) |
| 64 | + conn.close() |
| 65 | +" & |
| 66 | +_health_pid=$! |
| 67 | +trap 'kill "$_health_pid" 2>/dev/null || true' EXIT |
| 68 | + |
| 69 | +# --------------------------------------------------------------------------- |
| 70 | +# 5. Prepare cluster startup scripts and run the cluster. |
| 71 | +# We enter the nix testenv shell to ensure jq, postgres, and other cluster |
| 72 | +# tools are available. The inner script uses the pre-built venv so no |
| 73 | +# network access is needed. |
| 74 | +# --------------------------------------------------------------------------- |
| 75 | +_testnet_variant="${TESTNET_VARIANT:-conway_fast}" |
| 76 | + |
| 77 | +set +e |
| 78 | +nix develop --accept-flake-config .#testenv --command bash -c " |
| 79 | + set -euo pipefail |
| 80 | + . '${_VENV_DIR}/bin/activate' |
| 81 | + export PATH='${_PATH_PREPEND}:\${PATH}' |
| 82 | + export CARDANO_NODE_SOCKET_PATH='${CARDANO_NODE_SOCKET_PATH}' |
| 83 | + |
| 84 | + # Instantiate cluster scripts for instance ${_INSTANCE_NUM} into the |
| 85 | + # shared volume. --clean removes any previous attempt. |
| 86 | + python -m cardano_node_tests.prepare_cluster_scripts \ |
| 87 | + --dest-dir '${_SCRIPTS_DEST}' \ |
| 88 | + --testnet-variant '${_testnet_variant}' \ |
| 89 | + --instance-num ${_INSTANCE_NUM} \ |
| 90 | + --clean |
| 91 | + |
| 92 | + # start-cluster must run from the parent of the state-cluster directory. |
| 93 | + cd '${CLUSTER_STATE_DIR}' |
| 94 | + '${_SCRIPTS_DEST}/start-cluster' |
| 95 | + |
| 96 | + printf '{\"antithesis_setup\": {\"status\": \"complete\", \"details\": {\"info\": [\"cardano-node cluster ready, socket=%s\"]}}}\n' \ |
| 97 | + '${CARDANO_NODE_SOCKET_PATH}' >> '${_output_dir}/sdk.jsonl' |
| 98 | + |
| 99 | + # Keep the cluster alive until the container is stopped. |
| 100 | + tail -f /dev/null |
| 101 | +" |
| 102 | +_rc=$? |
| 103 | +set -e |
| 104 | +
|
| 105 | +echo "node_run.sh exiting with code ${_rc}" |
| 106 | +exit 0 |
0 commit comments