|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# An environment setup script for cardano-node-tests local development. |
| 4 | +# |
| 5 | +# Create a `.source` script in the root of the repository. |
| 6 | +# Source this file from the .source script. You can also include additional environment |
| 7 | +# variables such as DBSYNC_SCHEMA_DIR and GITHUB_TOKEN in that file, or change INSTANCE_NUM. |
| 8 | +# |
| 9 | +# export DBSYNC_SCHEMA_DIR="$HOME/Source/repos/cardano-db-sync/schema" |
| 10 | +# export GITHUB_TOKEN=ghp_.... |
| 11 | +INSTANCE_NUM="${INSTANCE_NUM:-0}" |
| 12 | + |
| 13 | +# Ensure we are in the correct directory |
| 14 | +if [[ "${PWD##*/}" != "cardano-node-tests"* ]]; then |
| 15 | + echo "Must be in cardano-node-tests* directory" >&2 |
| 16 | + return 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Activate poetry virtual environment |
| 20 | +if [ -z "${VIRTUAL_ENV:-}" ]; then |
| 21 | + # shellcheck disable=SC2091 |
| 22 | + $(poetry env activate) |
| 23 | + # Override PYTHONPATH to prefer virtual environment packages over nix packages |
| 24 | + PYTHONPATH="$(echo "$VIRTUAL_ENV"/lib/python3*/site-packages):$PYTHONPATH" |
| 25 | + export PYTHONPATH |
| 26 | +fi |
| 27 | + |
| 28 | +# Set Cardano Node socket path and other environment variables |
| 29 | +export CARDANO_NODE_SOCKET_PATH="/var/tmp/cardonnay/state-cluster${INSTANCE_NUM}/bft1.socket" |
| 30 | +export DEV_CLUSTER_RUNNING=1 CLUSTERS_COUNT=1 FORBID_RESTART=1 NO_ARTIFACTS=1 |
| 31 | +unset BOOTSTRAP_DIR |
| 32 | + |
| 33 | +mkdir -p "${CARDANO_NODE_SOCKET_PATH%/*}" |
| 34 | + |
| 35 | +# Set temporary directory for this instance |
| 36 | +TMPDIR="$PWD/tmp" |
| 37 | +if [ "$INSTANCE_NUM" != 0 ]; then |
| 38 | + TMPDIR="$PWD/tmp${INSTANCE_NUM}" |
| 39 | +fi |
| 40 | +mkdir -p "$TMPDIR" |
| 41 | +export TMPDIR |
| 42 | + |
| 43 | +# Remove ghcup from PATH to avoid conflicts with nix environment |
| 44 | +PATH="$(echo "$PATH" | tr ":" "\n" | grep -v "ghcup" | tr "\n" ":")" |
| 45 | +export PATH |
| 46 | + |
| 47 | +# Prepend instance-specific .bin directory to PATH if it exists |
| 48 | +if [ -e "$PWD/.bin${INSTANCE_NUM}" ]; then |
| 49 | + export PATH="$PWD/.bin${INSTANCE_NUM}:$PATH" |
| 50 | +fi |
| 51 | + |
| 52 | +# Prepend default .bin directory to PATH for instance 0 if it exists |
| 53 | +if [ "$INSTANCE_NUM" = 0 ] && [ -e "$PWD/.bin" ]; then |
| 54 | + export PATH="$PWD/.bin:$PATH" |
| 55 | +fi |
| 56 | + |
| 57 | +# Set database connection environment variables for db-sync |
| 58 | +export PGHOST=localhost PGUSER=postgres |
| 59 | + |
| 60 | +# Enable SMASH server if available |
| 61 | +if [ -n "${DBSYNC_SCHEMA_DIR:-}" ] && command -v cardano-smash-server >/dev/null 2>&1; then |
| 62 | + export SMASH=true |
| 63 | +fi |
| 64 | + |
| 65 | +# Enable cardano-cli bash completion |
| 66 | +if ! command -v _cardano-cli >/dev/null 2>&1 && command -v cardano-cli >/dev/null 2>&1; then |
| 67 | + # shellcheck disable=SC1090 |
| 68 | + . <(cardano-cli --bash-completion-script cardano-cli) |
| 69 | +fi |
| 70 | + |
| 71 | +unset INSTANCE_NUM |
0 commit comments