Skip to content

Commit

Permalink
[#2801] Allow docker container configuration through env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed Jun 10, 2021
1 parent 4655c6a commit d9c8317
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 22 deletions.
18 changes: 18 additions & 0 deletions configuration/cardano/mainnet-alonzo-genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"adaPerUTxOWord": 0,
"executionPrices": {
"prMem": 1,
"prSteps": 1
},
"maxTxExUnits": {
"exUnitsMem": 1,
"exUnitsSteps": 1
},
"maxBlockExUnits": {
"exUnitsMem": 1,
"exUnitsSteps": 1
},
"maxValueSize": 1000,
"collateralPercentage": 100,
"maxCollateralInputs": 1
}
16 changes: 15 additions & 1 deletion configuration/cardano/mainnet-config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"AlonzoGenesisFile": "mainnet-alonzo-genesis.json",
"AlonzoGenesisHash": "06cc024b823b6d20f5dde2faf8de2d895f47983ab584db38ea62111b61038e35",
"ApplicationName": "cardano-sl",
"ApplicationVersion": 1,
"ByronGenesisFile": "mainnet-byron-genesis.json",
"ByronGenesisHash": "5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb",
"LastKnownBlockVersion-Alt": 0,
"LastKnownBlockVersion-Major": 2,
"LastKnownBlockVersion-Major": 3,
"LastKnownBlockVersion-Minor": 0,
"MaxKnownMajorProtocolVersion": 2,
"Protocol": "Cardano",
Expand All @@ -21,19 +23,28 @@
"TraceChainSyncClient": false,
"TraceChainSyncHeaderServer": false,
"TraceChainSyncProtocol": false,
"TraceConnectionManager": true,
"TraceDNSResolver": true,
"TraceDNSSubscription": true,
"TraceDiffusionInitialization": true,
"TraceErrorPolicy": true,
"TraceForge": true,
"TraceHandshake": false,
"TraceInboundGovernor": true,
"TraceIpSubscription": true,
"TraceLedgerPeers": true,
"TraceLocalChainSyncProtocol": false,
"TraceLocalErrorPolicy": true,
"TraceLocalHandshake": false,
"TraceLocalRootPeers": true,
"TraceLocalTxSubmissionProtocol": false,
"TraceLocalTxSubmissionServer": false,
"TraceMempool": true,
"TraceMux": false,
"TracePeerSelection": true,
"TracePeerSelectionActions": true,
"TracePublicRootPeers": true,
"TraceServer": true,
"TraceTxInbound": false,
"TraceTxOutbound": false,
"TraceTxSubmissionProtocol": false,
Expand All @@ -59,6 +70,9 @@
"mapBackends": {
"cardano.node.metrics": [
"EKGViewBK"
],
"cardano.node.resources": [
"EKGViewBK"
]
},
"mapSubtrace": {
Expand Down
103 changes: 103 additions & 0 deletions nix/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

## Build Cardano Node + Image

https://docs.cardano.org/projects/cardano-node/en/latest/getting-started/building-the-node-using-nix.html

```
# Build + Install the cardano node
nix-build -A scripts.mainnet.node -o ~/bin/cardano-node
# Build + Install the cardano Docker image
docker load -i $(nix-build -A dockerImage --no-out-link) \
&& GITHASH=`git log -n1 --pretty='%H'` \
&& docker tag inputoutput/cardano-node:$GITHASH inputoutput/cardano-node:dev \
&& docker rmi inputoutput/cardano-node:$GITHASH
GITTAG=`git describe --exact-match --tags $GITHASH`
if [ $? -eq 0 ]; then
echo "Current tag: $GITTAG"
docker tag inputoutput/cardano-node:dev inputoutput/cardano-node:$GITTAG
fi
# Bash into the node to look around
docker run --rm -it --entrypoint=bash \
-v node-data:/opt/cardano/data \
inputoutput/cardano-node:dev
cardano-node run \
--config /opt/cardano/config/mainnet-config.json \
--topology /opt/cardano/config/mainnet-topology.json \
--socket-path /opt/cardano/ipc/socket \
--database-path /opt/cardano/data \
--host-addr 0.0.0.0 \
--port 3001
```

## Manual Testing

1. Run -e NETWORK=mainnet and check graceful shutdown SIGINT with -it
2. Run -e NETWORK=mainnet and check graceful shutdown SIGTERM with --detach
3. Run without -e NETWORK and check graceful shutdown SIGINT with -it
4. Run without -e NETWORK and check graceful shutdown SIGTERM with --detach
5. Check cardano-cli access

### Run with NETWORK

Run -e NETWORK=mainnet and check graceful shutdown SIGINT with -it

```
docker run --rm -it \
-p 3001:3001 \
-e NETWORK=mainnet \
-v node-data:/data/db \
inputoutput/cardano-node:dev
```

Run -e NETWORK=mainnet and check graceful shutdown SIGTERM with --detach

```
docker rm -f relay
docker run --detach \
--name=relay \
-p 3001:3001 \
-e NETWORK=mainnet \
-v node-data:/data/db \
inputoutput/cardano-node:dev
docker logs -f relay
```

### Run without NETWORK

Check graceful shutdown SIGINT with -it

```
docker run --rm -it \
-p 3001:3001 \
-v node-data:/opt/cardano/data \
inputoutput/cardano-node:dev run
```

Check graceful shutdown SIGTERM with --detach

```
docker rm -f relay
docker run --detach \
--name=relay \
-p 3001:3001 \
-v node-data:/opt/cardano/data \
-v node-ipc:/opt/cardano/ipc \
inputoutput/cardano-node:dev run
docker logs -f relay
```

### Check cardano-cli

```
alias cardano-cli="docker run --rm -it \
-v node-ipc:/opt/cardano/ipc \
inputoutput/cardano-node:dev cli"
cardano-cli query tip --mainnet
```
20 changes: 20 additions & 0 deletions nix/docker/context/bin/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/env bash

if [[ -n $NETWORK ]]; then

exec /usr/local/bin/run-network $@

elif [[ $1 == "run" ]]; then

exec /usr/local/bin/run-node $@

elif [[ $1 == "cli" ]]; then

exec /usr/local/bin/run-client $@

else

echo "Nothing to do! Perhaps try [run|cli]"
exit 1

fi
10 changes: 10 additions & 0 deletions nix/docker/context/bin/run-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/env bash

# Shift the first option by one index
shift

if [[ -z $CARDANO_NODE_SOCKET_PATH ]]; then
export CARDANO_NODE_SOCKET_PATH="/opt/cardano/ipc/socket"
fi

/usr/local/bin/cardano-cli $@
Loading

0 comments on commit d9c8317

Please sign in to comment.