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

Commit

Permalink
Merge #4196
Browse files Browse the repository at this point in the history
4196: Enable custom configuration when starting demo cluster r=Sam-Jeston a=Sam-Jeston

## Description

It can be convenient to start the cardano-sl demo cluster with a custom configuration file, rather than the default file defined at `lib/configuration.yaml`.

I've updated the demo cluster nix tooling such that:
- `./scripts/launch/demo-nix.sh` behaves as it used to
- `./scripts/launch/demo-nix.sh -c config_file_name.yaml` will use the corresponding file in the top level configurations folder



Co-authored-by: Sam Jeston <[email protected]>
  • Loading branch information
iohk-bors[bot] and Sam Jeston committed Jul 22, 2019
2 parents 3a8ce88 + ac29de3 commit 668d7ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 6 additions & 2 deletions nix/launch/demo-cluster/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ with import ../../../lib.nix;
, disableClientAuth ? false
, walletListen ? "127.0.0.1:8090"
, walletDocListen ? "127.0.0.1:8190"
, customConfigurationFile ? "false"
}:

let
Expand All @@ -33,6 +34,7 @@ let
assetLockFile = writeText "asset-lock-file" (intersperse "\n" assetLockAddresses);
ifAssetLock = optionalString (assetLockAddresses != []);
ifDisableClientAuth = optionalString disableClientAuth;
ifCustomConfiguration = optionalString (customConfigurationFile != "false");
prepareGenesis = callPackage ../../prepare-genesis {
inherit numCoreNodes stateDir;
configurationKey = "testnet_full";
Expand All @@ -47,6 +49,7 @@ in writeScript "demo-cluster" ''
export DEMO_SYSTEM_START=$(($(date +%s) + 14))
${ifAssetLock "export DEMO_ASSET_LOCK_FILE=${assetLockFile}"}
${ifDisableClientAuth "export DEMO_NO_CLIENT_AUTH=True"}
${ifCustomConfiguration "export DEMO_CONFIGURATION_FILE=${customConfigurationFile}"}
# 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
Expand All @@ -66,13 +69,14 @@ in writeScript "demo-cluster" ''
trap "stop_cardano" INT TERM
echo "Launching a demo cluster..."
echo "Configuration file: $DEMO_CONFIGURATION_FILE"
cardano-sl-cluster-prepare-environment "DEMO_" --cores ${builtins.toString numCoreNodes} --relays ${builtins.toString numRelayNodes} --edges ${builtins.toString numEdgeNodes}
cardano-sl-cluster-demo --cores ${builtins.toString numCoreNodes} --relays ${builtins.toString numRelayNodes} --edges 0 &
pidCluster=$!
${ifWallet ''
cardano-node \
--configuration-file ${cardanoConfig}/lib/configuration.yaml \
cardano-node \
--configuration-file $DEMO_CONFIGURATION_FILE \
--tlscert ${stateDir}/tls/edge/server.crt \
--tlskey ${stateDir}/tls/edge/server.key \
--tlsca ${stateDir}/tls/edge/ca.crt \
Expand Down
4 changes: 2 additions & 2 deletions nix/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ in {

});
inherit demoCluster;
demo-function = { disableClientAuth, numImportedWallets, runWallet }: demoCluster.override {
inherit disableClientAuth numImportedWallets runWallet;
demo-function = { disableClientAuth, numImportedWallets, runWallet, customConfigurationFile }: demoCluster.override {
inherit disableClientAuth numImportedWallets runWallet customConfigurationFile;
};
dockerImages = let
build = args: pkgs.callPackage ./docker.nix ({
Expand Down
15 changes: 11 additions & 4 deletions scripts/launch/demo-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ display_help() {
echo " -d run with client auth disabled"
echo " -w enable wallet"
echo " -i INT number of wallets to import (default: 0)"
echo " -c Absolute path to a custom config file"
echo
echo "$0 is used to launch a demo cluster with limited parameters."

Expand All @@ -18,19 +19,19 @@ display_help() {
RUN_WALLET="false"
NUM_IMPORTED_WALLETS=0
DISABLE_CLIENT_AUTH="false"
ARGS=()
CUSTOM_CONFIGURATION_FILE="false"

while getopts hdwi: option
while getopts hdwic: option
do
case "${option}" in
d) DISABLE_CLIENT_AUTH="true";;
w) RUN_WALLET="true";;
i) NUM_IMPORTED_WALLETS="${OPTARG}"; RUN_WALLET="true";;
c) CUSTOM_CONFIGURATION_FILE="${OPTARG}";;
h) display_help; exit 0;;
*) display_help; exit 1
esac
done
ARGS+=(--arg runWallet "${RUN_WALLET}" --arg numImportedWallets "${NUM_IMPORTED_WALLETS}")

if ! [ -x "$(command -v nix-build)" ]; then
echo 'Error: nix is not installed.' >&2
Expand All @@ -41,5 +42,11 @@ fi

GITREV=$(git rev-parse HEAD)

nix-build -A demo-function --arg disableClientAuth "$DISABLE_CLIENT_AUTH" --arg numImportedWallets "$NUM_IMPORTED_WALLETS" --arg runWallet "$RUN_WALLET" -o "launch_$GITREV"
nix-build -A demo-function \
--arg disableClientAuth "$DISABLE_CLIENT_AUTH" \
--arg numImportedWallets "$NUM_IMPORTED_WALLETS" \
--arg runWallet "$RUN_WALLET" \
--argstr customConfigurationFile "$CUSTOM_CONFIGURATION_FILE" \
-o "launch_$GITREV" \

exec ./launch_"$GITREV"

0 comments on commit 668d7ec

Please sign in to comment.