Skip to content

Commit e2579d0

Browse files
Added cli wrappers to allow easy access to cli (#10)
* Make it easy to run node cli * feat: if direnv isn't working give an appropriate error message. * feat: automatically create a random node key. * feat: only randomise the postgres password once. * feat: parametrise cardano network * feat: add details on how to reset the environment. * feat: add script to run cardano cli commands * feat: require signed commits at commit time rather than PR raising time --------- Signed-off-by: Squirrel <giles.cope@shielded.io> Co-authored-by: Fenton Haslam <fentonhaslam@gmail.com>
1 parent d538cba commit e2579d0

File tree

8 files changed

+129
-20
lines changed

8 files changed

+129
-20
lines changed

.envrc

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
# If your on windows use wsl / git bash / cygwin / msys2 with direnv
22

3+
# This repo only accepts signed commits:
4+
# point out to users at commit time that commits need to be signed,
5+
# not once they've done many commits and are trying to push a PR:
6+
git config --local commit.gpgSign true
7+
git config --local tag.gpgSign true
8+
39
export MIDNIGHT_NODE_IMAGE="midnightnetwork/midnight-node:0.8.0"
410

5-
export POSTGRES_HOST="x.x.x.x" # TODO: replace x.x.x.x with IP or host to postgres connection
11+
export POSTGRES_HOST="postgres" # TODO: replace with IP or host to postgres connection if not connecting to the docker one.
612
export POSTGRES_PORT="5432"
713
export POSTGRES_USER="postgres"
814

915
# A random password is used for your safety. Docker (but not podman) exposes
1016
# ports to the internet by default. This needs to be unguessable.
11-
export POSTGRES_PASSWORD=$(< /dev/random tr -dc 'A-Za-z0-9!@#$%^&*()_+-=' | head -c 20)
17+
if [ ! -f postgres.password ]; then
18+
uuidgen | tr -d '-' | head -c 16 > postgres.password
19+
fi
20+
export POSTGRES_PASSWORD="$(cat ./postgres.password)"
21+
1222
export POSTGRES_DB="cexplorer"
23+
24+
# We bring together the above variables into a database connection string:
1325
export DB_SYNC_POSTGRES_CONNECTION_STRING="psql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB"
1426

27+
# These are well known addresses of a network that allow you to discover all the other nodes.
1528
export BOOTNODES="/dns/boot-node-01.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWMjUq13USCvQR9Y6yFzYNYgTQBLNAcmc8psAuPx2UUdnB \
1629
/dns/boot-node-02.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWR1cHBUWPCqk3uqhwZqUFekfWj8T7ozK6S18DUT745v4d \
1730
/dns/boot-node-03.testnet-02.midnight.network/tcp/30333/ws/p2p/12D3KooWQxxUgq7ndPfAaCFNbAxtcKYxrAzTxDfRGNktF75SxdX5"
@@ -23,12 +36,18 @@ export APPEND_ARGS="--no-private-ip --validator --pool-limit 10 --trie-cache-siz
2336
export CFG_PRESET=testnet-02
2437

2538
# Validator Values:
26-
# TODO: generate node key like this: docker run --rm -it docker.io/parity/subkey:latest generate-node-key. Use the second output for NODE_KEY
27-
export NODE_KEY=""
39+
if [ ! -f node.privatekey ]; then
40+
# generate node key like this:
41+
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -it docker.io/parity/subkey:latest generate-node-key | sed -n '2p' > midnight-node.privatekey
42+
# Use the second line of output for NODE_KEY (that's what sed -n '2p' does)
43+
fi
44+
export NODE_KEY="$(cat ./midnight-node.privatekey)"
2845

2946
#
3047
# Partner chains config:
3148
#
49+
export CARDANO_NETWORK=preview
50+
export CARDANO_IMAGE="ghcr.io/intersectmbo/cardano-node:10.2.1"
3251
export CARDANO_DATA_DIR=./cardano-data
33-
export CARDANO_CONFIG_DIR=./cardano-config/preview
52+
export CARDANO_CONFIG_DIR=./cardano-config/${CARDANO_NETWORK}
3453
export HOME_IPC=${HOME}/ipc

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/cardano-data/*
2+
/data
3+
*.privatekey
4+
*.password

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
9+
### 🚀 Features
10+
11+
- Port from prior repo (#3)
12+
- If direnv isn't working give an appropriate error message.
13+
- /data dir should be .gitignored
14+
- Automatically create a random node key.
15+
- Only randomise the postgres password once.
16+
- Parametise cardano network
17+
18+
### 💼 Other
19+
20+
- *(deps)* Bump checkmarx/ast-github-action from 2.3.18 to 2.3.19 (#9)
21+
- Be explicit about image

README.md

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,81 @@ This allows for easy orchestration of the Midnight Node service.
55
## System requirements
66

77
- Install [Docker Engine](https://docs.docker.com/engine/install/)
8-
- Install [Docker-Compose](https://docs.docker.com/compose/install/)
8+
- Install [Docker Compose](https://docs.docker.com/compose/install/)
99
- Install [direnv](https://direnv.net/docs/installation.html)
1010

1111
## Usage
1212

1313
1. Clone repo
1414

15-
2. Modify values in `.envrc` file as applicable
15+
2. run `direnv allow` to load the environment variables
1616

17-
3. Run `direnv allow` to load the environment variables
17+
3. Run `docker-compose up`
1818

19-
3. Choose which compose files to use:
19+
The `.envrc` file will automatically create a random private key and save it as `midnight-node.privatekey`.
20+
21+
Choose which compose files to use:
2022
- `compose.yml` for Midnight Node
21-
- `compose-partner-chains.yml` for Cardano DB Sync
23+
- `compose-partner-chains.yml` for Cardano + DB Sync
2224
- `proof-server.yml` for Local Proof Server
2325

2426
One can use one or multiple compose files at once.
2527

2628
For example, to run the Midnight Node, you can do:
2729
```shell
28-
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose up -d
30+
docker compose up -d
2931
```
3032

3133
or to run the Midnight Node and Cardano DB Sync, you can do:
3234
```shell
33-
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose -f ./compose-partner-chains.yml -f ./compose.yml up -d
35+
docker compose -f ./compose-partner-chains.yml -f ./compose.yml up -d
3436
```
3537

3638
or to run the Midnight Node, Cardano DB Sync and a local Proof Server, you can do:
3739
```shell
38-
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-server.yml up -d
40+
docker compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-server.yml up -d
3941
```
4042

4143
🚀 That's it.
4244

45+
### Troubleshooting
46+
47+
### Clean start
48+
49+
To restart from fresh, run:
50+
51+
```sh
52+
docker compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-server.yml down -v
53+
docker compose -f ./compose-partner-chains.yml -f ./compose.yml -f ./proof-server.yml kill
54+
rm ~/ipc/node.socket
55+
rm -R ./data
56+
rm -R ./cardano-data
57+
```
58+
59+
#### Env vars not setup
60+
61+
If you get warnings like this then likely `direnv` is not setup or `direnv allow` has not been run:
62+
```
63+
WARN[0000] The "HOME_IPC" variable is not set. Defaulting to a blank string.
64+
```
65+
66+
#### IPC Errors
67+
68+
If you get IPC errors with Cardano node then delete the stale
69+
socket file: `rm ~/ipc/node.socket` and restart.
70+
71+
#### Midnight node Errors
72+
73+
If you encounter this message on the midnight node it's likely that the
74+
cardano-node is still syncing and it will go away once it's fully synced:
75+
76+
```
77+
Unable to author block in slot. Failure creating inherent data provider:
78+
'No latest block on chain.' not found.
79+
Possible causes: main chain follower configuration error, db-sync not synced fully,
80+
or data not set on the main chain.
81+
```
82+
4383
### LICENSE
4484

4585
Apache 2.0. PRs welcome, please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

cardano-cli.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$CARDANO_NETWORK" = "preview" ]; then
4+
CARDANO_NODE_NETWORK_ID=2
5+
elif [ "$CARDANO_NETWORK" = "mainnet" ]; then
6+
CARDANO_NODE_NETWORK_ID=1
7+
elif [ "$CARDANO_NETWORK" = "preprod" ]; then
8+
CARDANO_NODE_NETWORK_ID=0
9+
else
10+
echo "Error: Unknown CARDANO_NETWORK: $CARDANO_NETWORK"
11+
exit 1
12+
fi
13+
14+
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm \
15+
--network container:cardano-node \
16+
-e CARDANO_NODE_SOCKET_PATH="/ipc/node.socket" \
17+
-e CARDANO_NODE_NETWORK_ID=${CARDANO_NODE_NETWORK_ID} \
18+
-v ~/ipc:/ipc \
19+
${CARDANO_IMAGE} \
20+
cli $*

compose-partner-chains.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ volumes:
2222

2323
services:
2424
cardano-node:
25-
image: ghcr.io/intersectmbo/cardano-node:10.1.4
25+
image: ${CARDANO_IMAGE}
2626
restart: unless-stopped
2727
container_name: cardano-node
2828
ports:
2929
- "3001:3001"
3030
environment:
31-
- NETWORK=preview
31+
- NETWORK=${CARDANO_NETWORK}
3232
- CARDANO_NODE_SOCKET_PATH=/ipc/node.socket
3333
volumes:
3434
- ${HOME_IPC}:/ipc # Use ${HOME_IPC} from .envrc
35-
- $CARDANO_DATA_DIR:/data
35+
- ${CARDANO_DATA_DIR}:/data
3636

3737
postgres:
3838
image: postgres:15.3
39+
platform: linux/amd64
3940
container_name: db-sync-postgres
4041
environment:
4142
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
@@ -53,13 +54,14 @@ services:
5354

5455
db-sync:
5556
image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.4
57+
platform: linux/amd64
5658
container_name: db-sync
5759
restart: unless-stopped
5860
depends_on:
5961
postgres:
6062
condition: service_healthy
6163
environment:
62-
- NETWORK=preview
64+
- NETWORK=${CARDANO_NETWORK}
6365
- POSTGRES_HOST=${POSTGRES_HOST}
6466
- POSTGRES_PORT=${POSTGRES_PORT}
6567
- POSTGRES_DB=${POSTGRES_DB}
@@ -84,7 +86,7 @@ services:
8486
- --node-socket
8587
- /ipc/node.socket
8688
- --node-config
87-
- /config/preview/cardano-node/config.json
89+
- /config/${CARDANO_NETWORK}/cardano-node/config.json
8890
- --host
8991
- 0.0.0.0
9092

compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ services:
2121
container_name: midnight
2222
restart: unless-stopped
2323
image: ${MIDNIGHT_NODE_IMAGE}
24-
platform: linux/amd64
2524
ports:
2625
- "9944:9944" # WebSocket - For RPC/relay type of nodes (queries, new transaction submissions etc).
2726
- "30333:30333" # P2P Traffic - Peer-to-peer communication for node connectivity.

midnight-node.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z "$MIDNIGHT_NODE_IMAGE" ]; then
4+
echo "Error: Env var MIDNIGHT_NODE_IMAGE is not set or is empty"
5+
echo "Please install direnv and run `direnv allow` to activate it."
6+
exit 1
7+
fi
8+
9+
docker run -it \
10+
-e CFG_PRESET=${CFG_PRESET} \
11+
-e DB_SYNC_POSTGRES_CONNECTION_STRING=${DB_SYNC_POSTGRES_CONNECTION_STRING} \
12+
-v ./data:/data ${MIDNIGHT_NODE_IMAGE} \
13+
$*

0 commit comments

Comments
 (0)