diff --git a/default.nix b/default.nix index 0953b489326..fd721d543f0 100644 --- a/default.nix +++ b/default.nix @@ -159,6 +159,7 @@ let other = rec { validateJson = pkgs.callPackage ./tools/src/validate-json {}; demoCluster = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev; }; + demoClusterDaedalusDev = pkgs.callPackage ./scripts/launch/demo-cluster { inherit gitrev; disableClientAuth = true; numImportedWallets = 0; }; shellcheckTests = pkgs.callPackage ./scripts/test/shellcheck.nix { src = ./.; }; swaggerSchemaValidation = pkgs.callPackage ./scripts/test/wallet/swaggerSchemaValidation.nix { inherit gitrev; }; walletIntegrationTests = pkgs.callPackage ./scripts/test/wallet/integration { inherit gitrev; }; 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 9a11280d900..931effd0881 100755 --- a/scripts/launch/connect-to-cluster/default.nix +++ b/scripts/launch/connect-to-cluster/default.nix @@ -99,7 +99,7 @@ in pkgs.writeScript "${executable}-connect-to-${environment}" '' fi ''} - ${executables.${executable}} \ + exec ${executables.${executable}} \ --configuration-file ${configFiles}/lib/configuration.yaml \ --configuration-key ${environments.${environment}.confKey} \ ${ ifWallet "--tlscert ${stateDir}/tls/server/server.crt"} \ diff --git a/scripts/launch/demo-cluster/default.nix b/scripts/launch/demo-cluster/default.nix index ce2ac518f4a..58da90ffe93 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; } @@ -12,6 +13,7 @@ , ghcRuntimeArgs ? "-N2 -qg -A1m -I0 -T" , additionalNodeArgs ? "" , keepAlive ? true +, disableClientAuth ? false }: with localLib; @@ -26,10 +28,11 @@ let }; demoClusterDeps = with pkgs; (with iohkPkgs; [ jq coreutils pkgs.curl gnused openssl cardano-sl-tools cardano-sl-wallet-new cardano-sl-node-static ]); walletConfig = { - inherit stateDir; + inherit stateDir disableClientAuth; topologyFile = walletTopologyFile; + environment = "demo"; }; - demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev; debug = false; environment = "demo"; } // walletConfig); + demoWallet = pkgs.callPackage ./../connect-to-cluster ({ inherit gitrev; } // walletConfig); ifWallet = localLib.optionalString (runWallet); ifKeepAlive = localLib.optionalString (keepAlive); iohkPkgs = import ./../../.. { inherit config system pkgs gitrev; }; @@ -137,19 +140,22 @@ in pkgs.writeScript "demo-cluster" '' 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://localhost:8090/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://localhost:8090/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"