From 571639a6327838e7259ef16a1b19e4a4db7f7dfe Mon Sep 17 00:00:00 2001 From: Damon Chen Date: Mon, 6 Dec 2021 13:09:55 +0800 Subject: [PATCH] Override dotenv in start-cronos/start-chainmain This make these two script-bins defined in `scripts.nix` always use the same yaml and dotenv file, for metting the "re-producibility" requirement during one/same `nix-shell` environment. These script-bins are wrappers of pystarport with fixed yaml and dotenv. If you want to create the cronos/chainmain instance with different configurations, you should avoid using the script-bins. Please run the scripts directly, or use `pystarport` step by step. Besides, if you change the yaml or dotenv, you need to exit and re-enter the nix-shell. So that the modified yaml or dotenv are copied to nix store, and their paths can be rewritten into these two script-bins. --- nix/default.nix | 10 +++++----- nix/scripts.nix | 6 ++---- scripts/start-chainmain | 16 ++++++++++++---- scripts/start-cronos | 15 +++++++++++++-- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index c039e343a3..31074afd7b 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -24,11 +24,11 @@ import sources.nixpkgs { import ./scripts.nix { inherit pkgs; config = { - chainmain-config = builtins.toString ../scripts/chainmain-devnet.yaml; - cronos-config = builtins.toString ../scripts/cronos-devnet.yaml; - hermes-config = builtins.toString ../scripts/hermes.toml; - geth-genesis = builtins.toString ../scripts/geth-genesis.json; - dotenv = builtins.toString ../scripts/.env; + chainmain-config = ../scripts/chainmain-devnet.yaml; + cronos-config = ../scripts/cronos-devnet.yaml; + hermes-config = ../scripts/hermes.toml; + geth-genesis = ../scripts/geth-genesis.json; + dotenv = builtins.path { name = "dotenv"; path = ../scripts/.env; }; }; }) (_: pkgs: { diff --git a/nix/scripts.nix b/nix/scripts.nix index f91ef75c07..677a40c6fa 100644 --- a/nix/scripts.nix +++ b/nix/scripts.nix @@ -7,14 +7,12 @@ }: rec { start-chainmain = pkgs.writeShellScriptBin "start-chainmain" '' export PATH=${pkgs.pystarport}/bin:${chainmain}/bin:$PATH - source ${config.dotenv} - ${../scripts/start-chainmain} ${config.chainmain-config} $@ + ${../scripts/start-chainmain} ${config.chainmain-config} ${config.dotenv} $@ ''; start-cronos = pkgs.writeShellScriptBin "start-cronos" '' # rely on environment to provide cronosd export PATH=${pkgs.pystarport}/bin:$PATH - source ${config.dotenv} - ${../scripts/start-cronos} ${config.cronos-config} $@ + ${../scripts/start-cronos} ${config.cronos-config} ${config.dotenv} $@ ''; start-geth = pkgs.writeShellScriptBin "start-geth" '' export PATH=${pkgs.go-ethereum}/bin:$PATH diff --git a/scripts/start-chainmain b/scripts/start-chainmain index 2157af3ba0..f0772a05c8 100755 --- a/scripts/start-chainmain +++ b/scripts/start-chainmain @@ -8,6 +8,12 @@ if [ -z "$CONFIG" ]; then fi shift +DOTENV=$1 +if [ -z "$DOTENV" ]; then + echo "No dotenv file supplied" + exit 1 +fi +shift DATA=$1 if [ -z "$DATA" ]; then @@ -16,8 +22,10 @@ if [ -z "$DATA" ]; then fi shift -# `pystarport serve` don't work for integration test for some weird reason -echo 'config'$CONFIG -echo 'data'$DATA -pystarport init --config $CONFIG --data $DATA $@ +echo 'pystarport:' +echo ' config: '$CONFIG +echo ' dotenv: '$DOTENV +echo ' data: '$DATA + +pystarport init --config $CONFIG --dotenv $DOTENV --data $DATA $@ supervisord -c $DATA/tasks.ini diff --git a/scripts/start-cronos b/scripts/start-cronos index 4d1ccdbee8..f0772a05c8 100755 --- a/scripts/start-cronos +++ b/scripts/start-cronos @@ -8,6 +8,13 @@ if [ -z "$CONFIG" ]; then fi shift +DOTENV=$1 +if [ -z "$DOTENV" ]; then + echo "No dotenv file supplied" + exit 1 +fi +shift + DATA=$1 if [ -z "$DATA" ]; then echo "No data directory supplied" @@ -15,6 +22,10 @@ if [ -z "$DATA" ]; then fi shift -# `pystarport serve` don't work for integration test for some weird reason -pystarport init --config $CONFIG --data $DATA $@ +echo 'pystarport:' +echo ' config: '$CONFIG +echo ' dotenv: '$DOTENV +echo ' data: '$DATA + +pystarport init --config $CONFIG --dotenv $DOTENV --data $DATA $@ supervisord -c $DATA/tasks.ini