Skip to content

Commit

Permalink
Override dotenv in start-cronos/start-chainmain
Browse files Browse the repository at this point in the history
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 changes 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, so that their paths can be rewritten into these two
script-bins.
  • Loading branch information
damoncro committed Dec 6, 2021
1 parent 8adea89 commit 374671f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
10 changes: 5 additions & 5 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 2 additions & 4 deletions nix/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions scripts/start-chainmain
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
15 changes: 13 additions & 2 deletions scripts/start-cronos
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ 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"
exit 1
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

0 comments on commit 374671f

Please sign in to comment.