Skip to content

Commit a32f245

Browse files
authored
Merge pull request #3171 from IntersectMBO/add_source.dev
feat(dev): add .source.dev for local env setup
2 parents 3e1c66d + 3fea6da commit a32f245

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ __pycache__/
2626

2727
# Env variables
2828
/.source*
29+
!/.source.dev
2930

3031
# Distribution / packaging
3132
.Python

.source.dev

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,20 @@ NODE_REV=10.5.1 BOOTSTRAP_DIR=~/tmp/preview_config/ ./.github/regression.sh
174174
make install
175175
```
176176

177-
### 🧱 Start Development Cluster
177+
### 🔧 Activate Dev Environment
178178

179179
```sh
180180
cd ../cardano-node
181181
git checkout <tag>
182182
nix develop .#devops
183183
/bin/bash --login # fresh shell needed
184184
cd ../cardano-node-tests
185-
source "$(poetry env info --path)"/bin/activate
186-
export PYTHONPATH="$(echo $VIRTUAL_ENV/lib/python3*/site-packages):$PYTHONPATH"
187-
export CARDANO_NODE_SOCKET_PATH="$PWD/dev_workdir/state-cluster0/bft1.socket" DEV_CLUSTER_RUNNING=1
188-
mkdir -p "${CARDANO_NODE_SOCKET_PATH%/*}"
185+
source .source.dev
186+
```
187+
188+
### 🧱 Start Development Cluster
189+
190+
```sh
189191
prepare-cluster-scripts -c -d dev_workdir/conway_fast -t conway_fast
190192
./dev_workdir/conway_fast/start-cluster
191193
```

0 commit comments

Comments
 (0)