Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 92a28a2

Browse files
authored
Merge pull request #3342 from input-output-hk/devops-985-nix-stack-flag
[DEVOPS-985] add useStackBinaries parameter to default.nix
2 parents 8b3a33d + 83292c2 commit 92a28a2

File tree

7 files changed

+82
-46
lines changed

7 files changed

+82
-46
lines changed

default.nix

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ in
2020
, enableDebugging ? false
2121
, enableBenchmarks ? true
2222
, allowCustomConfig ? true
23+
, useStackBinaries ? false
2324
}:
2425

2526
with pkgs.lib;
@@ -117,13 +118,14 @@ let
117118
walletConfigFile = ./custom-wallet-config.nix;
118119
walletConfig = if allowCustomConfig then (if builtins.pathExists walletConfigFile then import walletConfigFile else {}) else {};
119120
in
120-
args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev; } // walletConfig );
121+
args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev useStackBinaries; } // walletConfig );
121122
other = rec {
122-
walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; };
123+
walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev useStackBinaries; };
123124
validateJson = pkgs.callPackage ./tools/src/validate-json {};
124-
demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev; };
125+
demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; };
126+
demoClusterDaedalusDev = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; disableClientAuth = true; numImportedWallets = 0; };
125127
demoClusterLaunchGenesis = pkgs.callPackage ./scripts/launch/demo-cluster {
126-
inherit gitrev;
128+
inherit gitrev useStackBinaries;
127129
launchGenesis = true;
128130
configurationKey = "testnet_full";
129131
runWallet = false;
@@ -156,7 +158,7 @@ let
156158
inherit (pkgs) purescript;
157159
connectScripts = {
158160
mainnet = {
159-
wallet = connect {};
161+
wallet = connect { };
160162
explorer = connect { executable = "explorer"; };
161163
};
162164
staging = {

docs/how-to/demo-cluster.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# How to launch a local demo cluster with nix
2+
3+
1. Make sure nix is installed and IOHK binary cache is configured [nix setup] (https://github.com/input-output-hk/cardano-sl/blob/develop/docs/how-to/build-cardano-sl-and-daedalus-from-source-code.md#nix-build-mode-recommended)
4+
2. To generate a script that will launch the demo cluster run `nix-build -A demoCluster -o launch_demo_cluster`
5+
3. To generate a script that will launch demo cluster suitable for Daedalus development, run `nix-build -A demoClusterDaedalusDev -o launch_demo_cluster`
6+
4. To launch cluster, run `./launch_demo_cluster`
7+
5. To stop, hit `ctrl-c` and it will terminate all the nodes.
8+
6. A `state-demo` state folder will be automatically created relative to your current
9+
working directory.
10+
* Logs will be found in `state-demo/logs`
11+
* TLS certs/keys will be found in `state-demo/tls`
12+
* 11 genesis wallets will be pre-loaded with 37 million Ada each

scripts/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mode, it will run in `dev` mode as well, and if you built it in `prod` mode, it
1313
## Launch
1414

1515
* `launch/demo.sh` - run nodes in `tmux`-session (3 nodes by default).
16+
* `launch/demo-nix.sh` - run demo cluster using nix with 4 core nodes, 1 relay, 1 wallet in background
1617
* `launch/demo-with-wallet-api.sh` - run nodes in `tmux`-session, with enabled wallet web API (3 nodes by default).
1718
* `launch/kill-demo.sh` - kill `tmux`-session with running nodes.
1819
* `launch/testnet-{public,staging}.sh` - connect one node to the cluster (testnet or testnet staging

scripts/launch/connect-to-cluster/default.nix

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
, debug ? false
1919
, disableClientAuth ? false
2020
, extraParams ? ""
21+
, useStackBinaries ? false
2122
}:
2223

2324
with localLib;
@@ -51,8 +52,9 @@ let
5152
};
5253
};
5354
executables = {
54-
wallet = "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node";
55-
explorer = "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer";
55+
wallet = if useStackBinaries then "stack exec -- cardano-node" else "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node";
56+
explorer = if useStackBinaries then "stack exec -- cardano-explorer" else "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer";
57+
x509gen = if useStackBinaries then "stack exec -- cardano-x509-certificates" else "${iohkPkgs.cardano-sl-tools}/bin/cardano-x509-certificates";
5658
};
5759
ifWallet = localLib.optionalString (executable == "wallet");
5860
iohkPkgs = import ./../../../default.nix { inherit config system pkgs gitrev; };
@@ -92,14 +94,14 @@ in pkgs.writeScript "${executable}-connect-to-${environment}" ''
9294
${utf8LocaleSetting}
9395
if [ ! -d ${stateDir}/tls ]; then
9496
mkdir -p ${stateDir}/tls/server && mkdir -p ${stateDir}/tls/client
95-
${iohkPkgs.cardano-sl-tools}/bin/cardano-x509-certificates \
97+
${executables.x509gen} \
9698
--server-out-dir ${stateDir}/tls/server \
9799
--clients-out-dir ${stateDir}/tls/client \
98100
${configurationArgs}
99101
fi
100102
''}
101103
102-
${executables.${executable}} \
104+
exec ${executables.${executable}} \
103105
${configurationArgs} \
104106
${ ifWallet "--tlscert ${stateDir}/tls/server/server.crt"} \
105107
${ ifWallet "--tlskey ${stateDir}/tls/server/server.key"} \

scripts/launch/demo-cluster/default.nix

+33-34
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
, runExplorer ? false
66
, numCoreNodes ? 4
77
, numRelayNodes ? 1
8+
, numImportedWallets ? 11
89
, assetLockAddresses ? []
910
, system ? builtins.currentSystem
1011
, pkgs ? import localLib.fetchNixPkgs { inherit system config; }
@@ -14,22 +15,21 @@
1415
, keepAlive ? true
1516
, launchGenesis ? false
1617
, configurationKey ? "default"
18+
, useStackBinaries ? false
19+
, disableClientAuth ? false
1720
}:
1821

1922
with localLib;
2023

2124
let
22-
executables = {
23-
corenode = "${iohkPkgs.cardano-sl-node-static}/bin/cardano-node-simple";
24-
wallet = "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node";
25-
integration-test = "${iohkPkgs.cardano-sl-wallet-new}/bin/wal-integr-test";
26-
keygen = "${iohkPkgs.cardano-sl-tools}/bin/cardano-keygen";
27-
explorer = "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer";
28-
};
29-
demoClusterDeps = with pkgs; (with iohkPkgs; [ jq coreutils pkgs.curl gnused openssl cardano-sl-tools cardano-sl-wallet-new cardano-sl-node-static ]);
25+
stackExec = optionalString useStackBinaries "stack exec -- ";
26+
cardanoDeps = with iohkPkgs; [ cardano-sl-tools cardano-sl-wallet-new cardano-sl-node-static ];
27+
demoClusterDeps = with pkgs; [ jq coreutils curl gnused openssl ];
28+
allDeps = demoClusterDeps ++ (optionals (!useStackBinaries ) cardanoDeps);
3029
walletConfig = {
31-
inherit stateDir;
30+
inherit stateDir disableClientAuth;
3231
topologyFile = walletTopologyFile;
32+
environment = "demo";
3333
};
3434
walletEnvironment = if launchGenesis then {
3535
environment = "override";
@@ -39,9 +39,9 @@ let
3939
} else {
4040
environment = "demo";
4141
};
42-
demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev; debug = false; } // walletEnvironment // walletConfig);
43-
ifWallet = localLib.optionalString (runWallet);
44-
ifKeepAlive = localLib.optionalString (keepAlive);
42+
demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev useStackBinaries; debug = false; } // walletEnvironment // walletConfig);
43+
ifWallet = optionalString (runWallet);
44+
ifKeepAlive = optionalString (keepAlive);
4545
iohkPkgs = import ./../../.. { inherit config system pkgs gitrev; };
4646
src = ./../../..;
4747
topologyFile = import ./make-topology.nix { inherit (pkgs) lib; cores = numCoreNodes; relays = numRelayNodes; };
@@ -52,8 +52,8 @@ let
5252
fallbacks = 1;
5353
};
5454
});
55-
assetLockFile = pkgs.writeText "asset-lock-file" (localLib.intersperse "\n" assetLockAddresses);
56-
ifAssetLock = localLib.optionalString (assetLockAddresses != []);
55+
assetLockFile = pkgs.writeText "asset-lock-file" (intersperse "\n" assetLockAddresses);
56+
ifAssetLock = optionalString (assetLockAddresses != []);
5757
configFiles = pkgs.runCommand "cardano-config" {} ''
5858
mkdir -pv $out
5959
cd $out
@@ -69,7 +69,7 @@ let
6969

7070
in pkgs.writeScript "demo-cluster" ''
7171
#!${pkgs.stdenv.shell}
72-
export PATH=${pkgs.lib.makeBinPath demoClusterDeps}
72+
export PATH=${pkgs.lib.makeBinPath allDeps}:$PATH
7373
# Set to 0 (passing) by default. Tests using this cluster can set this variable
7474
# to force the `stop_cardano` function to exit with a different code.
7575
EXIT_STATUS=0
@@ -111,7 +111,7 @@ in pkgs.writeScript "demo-cluster" ''
111111
'' else ''
112112
echo "Creating genesis keys..."
113113
config_files=${configFiles}
114-
cardano-keygen --system-start 0 generate-keys-by-spec --genesis-out-dir ${stateDir}/genesis-keys --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey}
114+
${stackExec}cardano-keygen --system-start 0 generate-keys-by-spec --genesis-out-dir ${stateDir}/genesis-keys --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey}
115115
''}
116116
117117
trap "stop_cardano" INT TERM
@@ -120,15 +120,15 @@ in pkgs.writeScript "demo-cluster" ''
120120
do
121121
node_args="--db-path ${stateDir}/core-db$i --rebuild-db ${if launchGenesis then "--keyfile ${stateDir}/genesis-keys/generated-keys/rich/key$((i - 1)).sk" else "--genesis-secret $i"} --listen 127.0.0.1:$((3000 + i)) --json-log ${stateDir}/logs/core$i.json --logs-prefix ${stateDir}/logs --system-start $system_start --metrics +RTS -N2 -qg -A1m -I0 -T -RTS --node-id core$i --topology ${topologyFile} --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey} ${ifAssetLock "--asset-lock-file ${assetLockFile}"}"
122122
echo Launching core node $i: cardano-node-simple $node_args
123-
cardano-node-simple $node_args &> ${stateDir}/logs/core$i.log &
123+
${stackExec}cardano-node-simple $node_args &> ${stateDir}/logs/core$i.log &
124124
core_pid[$i]=$!
125125
126126
done
127127
for i in {1..${builtins.toString numRelayNodes}}
128128
do
129129
node_args="--db-path ${stateDir}/relay-db$i --rebuild-db --listen 127.0.0.1:$((3100 + i)) --json-log ${stateDir}/logs/relay$i.json --logs-prefix ${stateDir}/logs --system-start $system_start --metrics +RTS -N2 -qg -A1m -I0 -T -RTS --node-id relay$i --topology ${topologyFile} --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey}"
130130
echo Launching relay node $i: cardano-node-simple $node_args
131-
cardano-node-simple $node_args &> ${stateDir}/logs/relay$i.log &
131+
${stackExec}cardano-node-simple $node_args &> ${stateDir}/logs/relay$i.log &
132132
relay_pid[$i]=$!
133133
134134
done
@@ -161,23 +161,22 @@ in pkgs.writeScript "demo-cluster" ''
161161
fi
162162
done
163163
echo Blockchain Synced: $PERC%
164-
# import keys
165-
echo "Importing poor HD keys/wallet..."
166-
167-
for i in {0..11}
168-
do
169-
echo "Importing key$i.sk ..."
170-
curl https://${demoWallet.walletListen}/api/wallets/keys \
171-
--cacert ${stateDir}/tls/client/ca.crt \
172-
--cert ${stateDir}/tls/client/client.pem \
173-
-X POST \
174-
-H 'cache-control: no-cache' \
175-
-H 'content-type: application/json' \
176-
-d "\"${stateDir}/genesis-keys/generated-keys/poor/key$i.sk\"" | jq .
177-
done
178-
164+
if [ ${builtins.toString numImportedWallets} -gt 0 ]
165+
then
166+
echo "Importing ${builtins.toString numImportedWallets} poor HD keys/wallet..."
167+
for i in {0..${builtins.toString numImportedWallets}}
168+
do
169+
echo "Importing key$i.sk ..."
170+
curl https://${demoWallet.walletListen}/api/wallets/keys \
171+
--cacert ${stateDir}/tls/client/ca.crt \
172+
--cert ${stateDir}/tls/client/client.pem \
173+
-X POST \
174+
-H 'cache-control: no-cache' \
175+
-H 'content-type: application/json' \
176+
-d "\"${stateDir}/genesis-keys/generated-keys/poor/key$i.sk\"" | jq .
177+
done
178+
fi
179179
''}
180-
181180
${ifKeepAlive ''
182181
sleep infinity
183182
''}

scripts/launch/demo-nix.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
if ! [ -x "$(command -v nix-build)" ]; then
4+
echo 'Error: nix is not installed.' >&2
5+
# shellcheck disable=SC2016
6+
echo 'Run `curl https://nixos.org/nix/install | sh` and re-run this script' >&2
7+
exit 1
8+
fi
9+
10+
GITREV=$(git rev-parse HEAD)
11+
12+
nix-build -A demoClusterDaedalusDev --argstr gitrev "$GITREV" -o "launch_$GITREV"
13+
exec ./launch_"$GITREV"

scripts/test/wallet/integration/default.nix

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
, gitrev ? "123456" # Dummy git revision to prevent mass rebuilds
88
, ghcRuntimeArgs ? "-N2 -qg -A1m -I0 -T"
99
, additionalNodeArgs ? ""
10+
, useStackBinaries ? false
1011
}:
1112

1213
with localLib;
1314

1415
let
16+
stackExec = optionalString useStackBinaries "stack exec -- ";
17+
cardanoDeps = with iohkPkgs; [ cardano-sl-tools ];
18+
integrationTestDeps = with pkgs; [ gnugrep ];
19+
allDeps = integrationTestDeps ++ (optionals (!useStackBinaries ) cardanoDeps);
1520
demo-cluster = iohkPkgs.demoCluster.override {
16-
inherit gitrev numCoreNodes stateDir;
21+
inherit gitrev numCoreNodes stateDir useStackBinaries;
1722
keepAlive = false;
1823
assetLockAddresses = [ "DdzFFzCqrhswMWoTiWaqXUDZJuYUx63qB6Aq8rbVbhFbc8NWqhpZkC7Lhn5eVA7kWf4JwKvJ9PqQF78AewMCzDZLabkzm99rFzpNDKp5" ];
1924
};
@@ -22,14 +27,16 @@ let
2227
};
2328
iohkPkgs = import ./../../../.. { inherit config system pkgs gitrev; };
2429
in pkgs.writeScript "integration-tests" ''
30+
#!${pkgs.stdenv.shell}
31+
export PATH=${pkgs.lib.makeBinPath allDeps}:$PATH
2532
set -e
2633
source ${demo-cluster}
27-
${executables.integration-test} --tls-ca-cert ${stateDir}/tls/client/ca.crt --tls-client-cert ${stateDir}/tls/client/client.pem --tls-key ${stateDir}/tls/client/client.key
34+
${stackExec}wal-integr-test --tls-ca-cert ${stateDir}/tls/client/ca.crt --tls-client-cert ${stateDir}/tls/client/client.pem --tls-key ${stateDir}/tls/client/client.key
2835
EXIT_STATUS=$?
2936
# Verify we see "transaction list is empty after filtering out asset-locked source addresses" in at least 1 core node log file
3037
if [[ $EXIT_STATUS -eq 0 ]]
3138
then
32-
${pkgs.gnugrep}/bin/grep "transaction list is empty after filtering out asset-locked source addresses" state-demo/logs/core*.json
39+
grep "transaction list is empty after filtering out asset-locked source addresses" state-demo/logs/core*.json
3340
EXIT_STATUS=$?
3441
fi
3542
stop_cardano

0 commit comments

Comments
 (0)