From d53d64bfa41f01484144469504ca093ce51f3090 Mon Sep 17 00:00:00 2001 From: Samuel Leathers Date: Tue, 31 Jul 2018 13:27:46 -0400 Subject: [PATCH 1/3] [DEVOPS-985] add useStackBinaries parameter to default.nix --- default.nix | 7 ++++--- scripts/launch/connect-to-cluster/default.nix | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/default.nix b/default.nix index 32e2c54fee3..61b6c8ee373 100644 --- a/default.nix +++ b/default.nix @@ -20,6 +20,7 @@ in , enableDebugging ? false , enableBenchmarks ? true , allowCustomConfig ? true +, useStackBinaries ? false }: with pkgs.lib; @@ -156,15 +157,15 @@ let inherit (pkgs) purescript; connectScripts = { mainnet = { - wallet = connect {}; + wallet = connect { inherit useStackBinaries;}; explorer = connect { executable = "explorer"; }; }; staging = { - wallet = connect { environment = "mainnet-staging"; }; + wallet = connect { inherit useStackBinaries; environment = "mainnet-staging"; }; explorer = connect { executable = "explorer"; environment = "mainnet-staging"; }; }; testnet = { - wallet = connect { environment = "testnet"; }; + wallet = connect { inherit useStackBinaries; environment = "testnet"; }; explorer = connect { executable = "explorer"; environment = "testnet"; }; }; demoWallet = connect { environment = "demo"; }; diff --git a/scripts/launch/connect-to-cluster/default.nix b/scripts/launch/connect-to-cluster/default.nix index 21d7274df15..2ad3e8b254a 100755 --- a/scripts/launch/connect-to-cluster/default.nix +++ b/scripts/launch/connect-to-cluster/default.nix @@ -18,6 +18,7 @@ , debug ? false , disableClientAuth ? false , extraParams ? "" +, useStackBinaries ? false }: with localLib; @@ -51,8 +52,9 @@ let }; }; executables = { - wallet = "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node"; + wallet = if useStackBinaries then "stack exec -- cardano-node" else "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node"; explorer = "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer"; + x509gen = if useStackBinaries then "stack exec -- cardano-x509-certificates" else "${iohkPkgs.cardano-sl-tools}/bin/cardano-x509-certificates"; }; ifWallet = localLib.optionalString (executable == "wallet"); iohkPkgs = import ./../../../default.nix { inherit config system pkgs gitrev; }; @@ -92,7 +94,7 @@ in pkgs.writeScript "${executable}-connect-to-${environment}" '' ${utf8LocaleSetting} if [ ! -d ${stateDir}/tls ]; then mkdir -p ${stateDir}/tls/server && mkdir -p ${stateDir}/tls/client - ${iohkPkgs.cardano-sl-tools}/bin/cardano-x509-certificates \ + ${executables.x509gen} \ --server-out-dir ${stateDir}/tls/server \ --clients-out-dir ${stateDir}/tls/client \ ${configurationArgs} From d2cbe38c80f6292c8bba439e8192f7453348b048 Mon Sep 17 00:00:00 2001 From: Samuel Leathers Date: Thu, 2 Aug 2018 11:46:15 -0400 Subject: [PATCH 2/3] [DEVOPS-985] demo cluster/wallet integration tests --- default.nix | 14 ++++----- scripts/launch/connect-to-cluster/default.nix | 2 +- scripts/launch/demo-cluster/default.nix | 31 +++++++++---------- scripts/test/wallet/integration/default.nix | 13 ++++++-- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/default.nix b/default.nix index 61b6c8ee373..faca51c7995 100644 --- a/default.nix +++ b/default.nix @@ -118,13 +118,13 @@ let walletConfigFile = ./custom-wallet-config.nix; walletConfig = if allowCustomConfig then (if builtins.pathExists walletConfigFile then import walletConfigFile else {}) else {}; in - args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev; } // walletConfig ); + args: pkgs.callPackage ./scripts/launch/connect-to-cluster (args // { inherit gitrev useStackBinaries; } // walletConfig ); other = rec { - walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; }; + walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev useStackBinaries; }; validateJson = pkgs.callPackage ./tools/src/validate-json {}; - demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev; }; + demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; }; demoClusterLaunchGenesis = pkgs.callPackage ./scripts/launch/demo-cluster { - inherit gitrev; + inherit gitrev useStackBinaries; launchGenesis = true; configurationKey = "testnet_full"; runWallet = false; @@ -157,15 +157,15 @@ let inherit (pkgs) purescript; connectScripts = { mainnet = { - wallet = connect { inherit useStackBinaries;}; + wallet = connect { }; explorer = connect { executable = "explorer"; }; }; staging = { - wallet = connect { inherit useStackBinaries; environment = "mainnet-staging"; }; + wallet = connect { environment = "mainnet-staging"; }; explorer = connect { executable = "explorer"; environment = "mainnet-staging"; }; }; testnet = { - wallet = connect { inherit useStackBinaries; environment = "testnet"; }; + wallet = connect { environment = "testnet"; }; explorer = connect { executable = "explorer"; environment = "testnet"; }; }; demoWallet = connect { environment = "demo"; }; diff --git a/scripts/launch/connect-to-cluster/default.nix b/scripts/launch/connect-to-cluster/default.nix index 2ad3e8b254a..4c8049da6c5 100755 --- a/scripts/launch/connect-to-cluster/default.nix +++ b/scripts/launch/connect-to-cluster/default.nix @@ -53,7 +53,7 @@ let }; executables = { wallet = if useStackBinaries then "stack exec -- cardano-node" else "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node"; - explorer = "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer"; + explorer = if useStackBinaries then "stack exec -- cardano-explorer" else "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer"; x509gen = if useStackBinaries then "stack exec -- cardano-x509-certificates" else "${iohkPkgs.cardano-sl-tools}/bin/cardano-x509-certificates"; }; ifWallet = localLib.optionalString (executable == "wallet"); diff --git a/scripts/launch/demo-cluster/default.nix b/scripts/launch/demo-cluster/default.nix index aa83ee551a4..490492e8645 100755 --- a/scripts/launch/demo-cluster/default.nix +++ b/scripts/launch/demo-cluster/default.nix @@ -14,19 +14,16 @@ , keepAlive ? true , launchGenesis ? false , configurationKey ? "default" +, useStackBinaries ? false }: with localLib; let - executables = { - corenode = "${iohkPkgs.cardano-sl-node-static}/bin/cardano-node-simple"; - wallet = "${iohkPkgs.cardano-sl-wallet-new}/bin/cardano-node"; - integration-test = "${iohkPkgs.cardano-sl-wallet-new}/bin/wal-integr-test"; - keygen = "${iohkPkgs.cardano-sl-tools}/bin/cardano-keygen"; - explorer = "${iohkPkgs.cardano-sl-explorer-static}/bin/cardano-explorer"; - }; - demoClusterDeps = with pkgs; (with iohkPkgs; [ jq coreutils pkgs.curl gnused openssl cardano-sl-tools cardano-sl-wallet-new cardano-sl-node-static ]); + stackExec = optionalString useStackBinaries "stack exec -- "; + cardanoDeps = with iohkPkgs; [ cardano-sl-tools cardano-sl-wallet-new cardano-sl-node-static ]; + demoClusterDeps = with pkgs; [ jq coreutils curl gnused openssl ]; + allDeps = demoClusterDeps ++ (optionals (!useStackBinaries ) cardanoDeps); walletConfig = { inherit stateDir; topologyFile = walletTopologyFile; @@ -39,9 +36,9 @@ let } else { environment = "demo"; }; - demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev; debug = false; } // walletEnvironment // walletConfig); - ifWallet = localLib.optionalString (runWallet); - ifKeepAlive = localLib.optionalString (keepAlive); + demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev useStackBinaries; debug = false; } // walletEnvironment // walletConfig); + ifWallet = optionalString (runWallet); + ifKeepAlive = optionalString (keepAlive); iohkPkgs = import ./../../.. { inherit config system pkgs gitrev; }; src = ./../../..; topologyFile = import ./make-topology.nix { inherit (pkgs) lib; cores = numCoreNodes; relays = numRelayNodes; }; @@ -52,8 +49,8 @@ let fallbacks = 1; }; }); - assetLockFile = pkgs.writeText "asset-lock-file" (localLib.intersperse "\n" assetLockAddresses); - ifAssetLock = localLib.optionalString (assetLockAddresses != []); + assetLockFile = pkgs.writeText "asset-lock-file" (intersperse "\n" assetLockAddresses); + ifAssetLock = optionalString (assetLockAddresses != []); configFiles = pkgs.runCommand "cardano-config" {} '' mkdir -pv $out cd $out @@ -69,7 +66,7 @@ let in pkgs.writeScript "demo-cluster" '' #!${pkgs.stdenv.shell} - export PATH=${pkgs.lib.makeBinPath demoClusterDeps} + export PATH=${pkgs.lib.makeBinPath allDeps}:$PATH # Set to 0 (passing) by default. Tests using this cluster can set this variable # to force the `stop_cardano` function to exit with a different code. EXIT_STATUS=0 @@ -111,7 +108,7 @@ in pkgs.writeScript "demo-cluster" '' '' else '' echo "Creating genesis keys..." config_files=${configFiles} - cardano-keygen --system-start 0 generate-keys-by-spec --genesis-out-dir ${stateDir}/genesis-keys --configuration-file $config_files/configuration.yaml --configuration-key ${configurationKey} + ${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} ''} trap "stop_cardano" INT TERM @@ -120,7 +117,7 @@ in pkgs.writeScript "demo-cluster" '' do 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}"}" echo Launching core node $i: cardano-node-simple $node_args - cardano-node-simple $node_args &> ${stateDir}/logs/core$i.log & + ${stackExec}cardano-node-simple $node_args &> ${stateDir}/logs/core$i.log & core_pid[$i]=$! done @@ -128,7 +125,7 @@ in pkgs.writeScript "demo-cluster" '' do 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}" echo Launching relay node $i: cardano-node-simple $node_args - cardano-node-simple $node_args &> ${stateDir}/logs/relay$i.log & + ${stackExec}cardano-node-simple $node_args &> ${stateDir}/logs/relay$i.log & relay_pid[$i]=$! done diff --git a/scripts/test/wallet/integration/default.nix b/scripts/test/wallet/integration/default.nix index 969ed8b520b..1657d72a4aa 100755 --- a/scripts/test/wallet/integration/default.nix +++ b/scripts/test/wallet/integration/default.nix @@ -7,13 +7,18 @@ , gitrev ? "123456" # Dummy git revision to prevent mass rebuilds , ghcRuntimeArgs ? "-N2 -qg -A1m -I0 -T" , additionalNodeArgs ? "" +, useStackBinaries ? false }: with localLib; let + stackExec = optionalString useStackBinaries "stack exec -- "; + cardanoDeps = with iohkPkgs; [ cardano-sl-tools ]; + integrationTestDeps = with pkgs; [ gnugrep ]; + allDeps = integrationTestDeps ++ (optionals (!useStackBinaries ) cardanoDeps); demo-cluster = iohkPkgs.demoCluster.override { - inherit gitrev numCoreNodes stateDir; + inherit gitrev numCoreNodes stateDir useStackBinaries; keepAlive = false; assetLockAddresses = [ "DdzFFzCqrhswMWoTiWaqXUDZJuYUx63qB6Aq8rbVbhFbc8NWqhpZkC7Lhn5eVA7kWf4JwKvJ9PqQF78AewMCzDZLabkzm99rFzpNDKp5" ]; }; @@ -22,14 +27,16 @@ let }; iohkPkgs = import ./../../../.. { inherit config system pkgs gitrev; }; in pkgs.writeScript "integration-tests" '' + #!${pkgs.stdenv.shell} + export PATH=${pkgs.lib.makeBinPath allDeps}:$PATH set -e source ${demo-cluster} - ${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 + ${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 EXIT_STATUS=$? # Verify we see "transaction list is empty after filtering out asset-locked source addresses" in at least 1 core node log file if [[ $EXIT_STATUS -eq 0 ]] then - ${pkgs.gnugrep}/bin/grep "transaction list is empty after filtering out asset-locked source addresses" state-demo/logs/core*.json + grep "transaction list is empty after filtering out asset-locked source addresses" state-demo/logs/core*.json EXIT_STATUS=$? fi stop_cardano From 83292c2fb6fda62db503defff86fdd9da432348e Mon Sep 17 00:00:00 2001 From: Samuel Leathers Date: Fri, 27 Jul 2018 06:13:10 -0400 Subject: [PATCH 3/3] [DEVOPS-978] Add demoClusterDaedalusDev attribute and documentation (cherry picked from commit e7d61de2f5baae691d2be448358dbca72cf96593) --- default.nix | 1 + docs/how-to/demo-cluster.md | 12 +++++++ scripts/README.md | 1 + scripts/launch/connect-to-cluster/default.nix | 2 +- scripts/launch/demo-cluster/default.nix | 36 ++++++++++--------- scripts/launch/demo-nix.sh | 13 +++++++ 6 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 docs/how-to/demo-cluster.md create mode 100755 scripts/launch/demo-nix.sh diff --git a/default.nix b/default.nix index faca51c7995..761f5afec69 100644 --- a/default.nix +++ b/default.nix @@ -123,6 +123,7 @@ let walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev useStackBinaries; }; validateJson = pkgs.callPackage ./tools/src/validate-json {}; demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; }; + demoClusterDaedalusDev = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; disableClientAuth = true; numImportedWallets = 0; }; demoClusterLaunchGenesis = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev useStackBinaries; launchGenesis = true; diff --git a/docs/how-to/demo-cluster.md b/docs/how-to/demo-cluster.md new file mode 100644 index 00000000000..dfe7d95e4c7 --- /dev/null +++ b/docs/how-to/demo-cluster.md @@ -0,0 +1,12 @@ +# How to launch a local demo cluster with nix + +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) +2. To generate a script that will launch the demo cluster run `nix-build -A demoCluster -o launch_demo_cluster` +3. To generate a script that will launch demo cluster suitable for Daedalus development, run `nix-build -A demoClusterDaedalusDev -o launch_demo_cluster` +4. To launch cluster, run `./launch_demo_cluster` +5. To stop, hit `ctrl-c` and it will terminate all the nodes. +6. A `state-demo` state folder will be automatically created relative to your current + working directory. + * Logs will be found in `state-demo/logs` + * TLS certs/keys will be found in `state-demo/tls` + * 11 genesis wallets will be pre-loaded with 37 million Ada each diff --git a/scripts/README.md b/scripts/README.md index ad4cc0a0503..95c82a7fa71 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -13,6 +13,7 @@ mode, it will run in `dev` mode as well, and if you built it in `prod` mode, it ## Launch * `launch/demo.sh` - run nodes in `tmux`-session (3 nodes by default). +* `launch/demo-nix.sh` - run demo cluster using nix with 4 core nodes, 1 relay, 1 wallet in background * `launch/demo-with-wallet-api.sh` - run nodes in `tmux`-session, with enabled wallet web API (3 nodes by default). * `launch/kill-demo.sh` - kill `tmux`-session with running nodes. * `launch/testnet-{public,staging}.sh` - connect one node to the cluster (testnet or testnet staging diff --git a/scripts/launch/connect-to-cluster/default.nix b/scripts/launch/connect-to-cluster/default.nix index 4c8049da6c5..ad45e0695c0 100755 --- a/scripts/launch/connect-to-cluster/default.nix +++ b/scripts/launch/connect-to-cluster/default.nix @@ -101,7 +101,7 @@ in pkgs.writeScript "${executable}-connect-to-${environment}" '' fi ''} - ${executables.${executable}} \ + exec ${executables.${executable}} \ ${configurationArgs} \ ${ ifWallet "--tlscert ${stateDir}/tls/server/server.crt"} \ ${ ifWallet "--tlskey ${stateDir}/tls/server/server.key"} \ diff --git a/scripts/launch/demo-cluster/default.nix b/scripts/launch/demo-cluster/default.nix index 490492e8645..45cf506b88e 100755 --- a/scripts/launch/demo-cluster/default.nix +++ b/scripts/launch/demo-cluster/default.nix @@ -5,6 +5,7 @@ , runExplorer ? false , numCoreNodes ? 4 , numRelayNodes ? 1 +, numImportedWallets ? 11 , assetLockAddresses ? [] , system ? builtins.currentSystem , pkgs ? import localLib.fetchNixPkgs { inherit system config; } @@ -15,6 +16,7 @@ , launchGenesis ? false , configurationKey ? "default" , useStackBinaries ? false +, disableClientAuth ? false }: with localLib; @@ -25,8 +27,9 @@ let demoClusterDeps = with pkgs; [ jq coreutils curl gnused openssl ]; allDeps = demoClusterDeps ++ (optionals (!useStackBinaries ) cardanoDeps); walletConfig = { - inherit stateDir; + inherit stateDir disableClientAuth; topologyFile = walletTopologyFile; + environment = "demo"; }; walletEnvironment = if launchGenesis then { environment = "override"; @@ -158,23 +161,22 @@ in pkgs.writeScript "demo-cluster" '' fi done echo Blockchain Synced: $PERC% - # import keys - echo "Importing poor HD keys/wallet..." - - for i in {0..11} - do - echo "Importing key$i.sk ..." - curl https://${demoWallet.walletListen}/api/wallets/keys \ - --cacert ${stateDir}/tls/client/ca.crt \ - --cert ${stateDir}/tls/client/client.pem \ - -X POST \ - -H 'cache-control: no-cache' \ - -H 'content-type: application/json' \ - -d "\"${stateDir}/genesis-keys/generated-keys/poor/key$i.sk\"" | jq . - done - + if [ ${builtins.toString numImportedWallets} -gt 0 ] + then + echo "Importing ${builtins.toString numImportedWallets} poor HD keys/wallet..." + for i in {0..${builtins.toString numImportedWallets}} + do + echo "Importing key$i.sk ..." + curl https://${demoWallet.walletListen}/api/wallets/keys \ + --cacert ${stateDir}/tls/client/ca.crt \ + --cert ${stateDir}/tls/client/client.pem \ + -X POST \ + -H 'cache-control: no-cache' \ + -H 'content-type: application/json' \ + -d "\"${stateDir}/genesis-keys/generated-keys/poor/key$i.sk\"" | jq . + done + fi ''} - ${ifKeepAlive '' sleep infinity ''} diff --git a/scripts/launch/demo-nix.sh b/scripts/launch/demo-nix.sh new file mode 100755 index 00000000000..faabc929e9c --- /dev/null +++ b/scripts/launch/demo-nix.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +if ! [ -x "$(command -v nix-build)" ]; then + echo 'Error: nix is not installed.' >&2 + # shellcheck disable=SC2016 + echo 'Run `curl https://nixos.org/nix/install | sh` and re-run this script' >&2 + exit 1 +fi + +GITREV=$(git rev-parse HEAD) + +nix-build -A demoClusterDaedalusDev --argstr gitrev "$GITREV" -o "launch_$GITREV" +exec ./launch_"$GITREV"