Skip to content

Commit

Permalink
Merge #3628
Browse files Browse the repository at this point in the history
3628: workbench:  fixes & updates r=deepfire a=deepfire

This fixes both:

1. `make cluster-shell` and
2. `start-cluster` inside `make shell-dev`.

Co-authored-by: Kosyrev Serge <[email protected]>
  • Loading branch information
iohk-bors[bot] and deepfire authored Feb 23, 2022
2 parents 525c3d9 + 470fd41 commit 75de27d
Show file tree
Hide file tree
Showing 24 changed files with 290 additions and 108 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ cluster-shell: ## Enter Nix shell and start the workbench cluster
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr profileName ${PROFILE} --arg 'autoStartCluster' true

shell-dev: ARGS += --arg 'workbenchDevMode' true ## Enter Nix shell, dev mode (workbench run from checkout)
cluster-shell: ARGS += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true ## Enter Nix shell, and start workbench cluster
cluster-shell: ARGS += --arg 'autoStartCluster' true ## Enter Nix shell, and start workbench cluster
cluster-shell-dev: ARGS += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true ## Enter Nix shell, dev mode, and start workbench cluster
cluster-shell-trace: ARGS += --arg 'autoStartCluster' true --argstr 'autoStartClusterArgs' '--trace --trace-workbench' ## Enter Nix shell, start workbench cluster, with shell tracing
cluster-shell-dev-trace: ARGS += --arg 'autoStartCluster' true --arg 'workbenchDevMode' true --argstr 'autoStartClusterArgs' '--trace --trace-workbench' ## Enter Nix shell, dev mode, start workbench cluster, with shell tracing
shell-dev cluster-shell-dev cluster-shell-trace cluster-shell-dev-trace: shell
fixed: ARGS += --arg 'autoStartCluster' true
fixed: PROFILE = fixed-alzo
smoke: ARGS += --arg 'autoStartCluster' true --run "grep TraceOpenEvent.ClosedDB run/current/node-0/stdout >/dev/null && echo 'Smoke test: PASS' || echo 'Smoke test: FAIL'"
smoke: PROFILE = smoke-alzo
smoke-loaded: ARGS += --arg 'autoStartCluster' true --run "grep TraceOpenEvent.ClosedDB run/current/node-0/stdout >/dev/null && echo 'Smoke test: PASS' || echo 'Smoke test: FAIL'"
smoke-loaded: PROFILE = smoke-loaded-alzo
shell-dev cluster-shell-dev cluster-shell-trace cluster-shell-dev-trace fixed smoke smoke-loaded: shell

shell: ## Enter Nix shell, CI mode (workbench run from Nix store)
nix-shell --max-jobs 8 --cores 0 --show-trace --argstr profileName ${PROFILE} ${ARGS}
Expand Down
10 changes: 6 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ let
withHoogle = true;
};

clusterCabal = workbench-supervisord { inherit profileName haskellPackages; useCabalRun = true; };
clusterNix = workbench-supervisord { inherit profileName haskellPackages; useCabalRun = false; };
workbench-smoke-test = clusterNix.smoke-test { profileName = "smoke-loaded-alzo"; };

packages = {
inherit haskellPackages shell
cardano-node cardano-node-profiled cardano-node-eventlogged
cardano-cli db-converter cardano-ping
locli locli-profiled
tx-generator tx-generator-profiled
scripts environments dockerImage submitApiDockerImage bech32;

clusterCabal = mkSupervisordCluster { inherit profileName; useCabalRun = true; };
clusterNix = mkSupervisordCluster { inherit profileName; useCabalRun = false; };
scripts environments dockerImage submitApiDockerImage bech32
clusterNix clusterCabal workbench-smoke-test;

devopsShell = shell.devops;

Expand Down
10 changes: 10 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ let
inherit system;
gitrev = sources.plutus-example.rev;
}).haskellPackages.plutus-example.components.exes) plutus-example;

# This provides a supervisord-backed instance of a the workbench development environment
# that can be used with nix-shell or lorri.
# See https://input-output-hk.github.io/haskell.nix/user-guide/development/
workbench-supervisord =
{ useCabalRun, profileName, haskellPackages }:
pkgs.callPackage ./supervisord-cluster
{ inherit profileName useCabalRun haskellPackages;
workbench = pkgs.callPackage ./workbench { inherit useCabalRun; };
};
})
# And, of course, our haskell-nix-ified cabal project:
(import ./pkgs.nix)
Expand Down
104 changes: 82 additions & 22 deletions nix/supervisord-cluster/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let
profileNameDefault = "default-alzo";
in
{ pkgs
, haskellPackages
, workbench
, lib
, bech32
Expand Down Expand Up @@ -55,7 +56,7 @@ let
finaliseNodeConfig =
{ port, ... }: cfg: recursiveUpdate cfg
({
AlonzoGenesisFile = "../genesis-alonzo.json";
AlonzoGenesisFile = "../genesis.alonzo.json";
ShelleyGenesisFile = "../genesis-shelley.json";
ByronGenesisFile = "../genesis/byron/genesis.json";
} // optionalAttrs enableEKG {
Expand All @@ -66,6 +67,9 @@ let
];
});

finaliseNodeArgs =
{ port, ... }: cfg: cfg;

finaliseGeneratorService =
svc: recursiveUpdate svc
({
Expand All @@ -79,7 +83,7 @@ let
finaliseGeneratorConfig =
cfg: recursiveUpdate cfg
({
AlonzoGenesisFile = "../genesis-alonzo.json";
AlonzoGenesisFile = "../genesis.alonzo.json";
ShelleyGenesisFile = "../genesis-shelley.json";
ByronGenesisFile = "../genesis/byron/genesis.json";
});
Expand Down Expand Up @@ -114,28 +118,22 @@ let
};
};

## IMPORTANT: keep in sync with envArgs in 'workbench/default.nix/generateProfiles/environment'.
envArgs =
{
inherit (pkgs) cardanoLib;
inherit
stateDir
cacheDir basePort;
staggerPorts = true;
};

workbenchProfiles = workbench.generateProfiles
{ inherit pkgs backend envArgs; };
inherit
(workbench.with-workbench-profile
{ inherit pkgs backend profileName;

## IMPORTANT: keep in sync with envArgs in 'workbench/default.nix/generateProfiles/environment'.
envArgs =
{
inherit (pkgs) cardanoLib;
inherit stateDir cacheDir basePort;
staggerPorts = true;
};
})
profile profileOut;
in

let
profile = workbenchProfiles.profiles."${profileName}"
or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames workbenchProfiles.profiles)}");

profileOut = workbench.profileOutput { inherit profile;
backendProfileOutput =
backend.profileOutput { inherit profile; };
};

inherit (profile.value) era composition monetary;

Expand All @@ -152,6 +150,7 @@ let
export PATH=$PATH:${path}
set -x
wb start \
--batch-name ${batchName} \
--profile-name ${profileName} \
Expand All @@ -163,6 +162,67 @@ let
echo 'workbench: cluster started. Run `stop-cluster` to stop' >&2
'';

smoke-test =
{ profileName }:
let inherit
(workbench.with-workbench-profile
{ inherit pkgs backend profileName;

## IMPORTANT: keep in sync with envArgs in 'workbench/default.nix/generateProfiles/environment'.
envArgs =
{
inherit (pkgs) cardanoLib;
inherit basePort;
cacheDir = "./cache";
stateDir = "./";
staggerPorts = true;
};
})
profile profileOut;
in
pkgs.runCommand "workbench-test-${profileName}"
{ requiredSystemFeatures = [ "benchmark" ];
nativeBuildInputs = with haskellPackages; with pkgs; [
bash
bech32
coreutils
gnused
jq
moreutils
nixWrapped
psmisc
python3Packages.supervisor
workbench.workbench
];
}
''
mkdir -p $out/cache
cd $out
${workbench.shellHook}
export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${stateDir})
wb start \
--batch-name smoke-test \
--profile-name ${profileName} \
--profile-out ${profileOut} \
--cache-dir ./cache \
--base-port ${toString basePort} \
## Cleanup:
rm -rf cache
rm -f run/{current,-current} genesis
mv run/env.json .
tag=$(cd run; ls)
echo "workbench-test: completed run $tag"
mv run/$tag/* .
rmdir run/$tag run
rm -f node-*/node.socket
'';

stop = pkgs.writeScriptBin "stop-cluster" ''
set -euo pipefail
Expand All @@ -175,10 +235,10 @@ let
wb run restart "$@" && \
echo "workbench: alternate command for this action: wb run restart" >&2
'';

in
{
inherit workbench;
inherit (workbenchProfiles) profilesJSON;
inherit profile stateDir start stop restart;
inherit smoke-test;
}
5 changes: 4 additions & 1 deletion nix/supervisord-cluster/supervisor-conf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ let
{
"program:generator" = {
directory = "${stateDir}/generator";
command = "${stateDir}/generator/start.sh";
command = "sh start.sh";
stdout_logfile = "${stateDir}/generator/stdout";
stderr_logfile = "${stateDir}/generator/stderr";
autostart = false;
startretries = 0;
};
}
//
Expand All @@ -58,6 +59,8 @@ let
command = "sh start.sh";
stdout_logfile = "${service.value.stateDir}/stdout";
stderr_logfile = "${service.value.stateDir}/stderr";
startretries = 0;
autorestart = false;
};

in
Expand Down
4 changes: 2 additions & 2 deletions nix/supervisord-cluster/tests/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ pkgs
}: let
inherit (pkgs) mkSupervisordCluster cardano-cli cardanolib-py cardano-node;
inherit (pkgs) workbench-supervisord cardano-cli cardanolib-py cardano-node;
stateDir = "./state-cluster-test";
# We want a really short duration for tests
cluster' = mkSupervisordCluster {
cluster' = workbench-supervisord {
genesisParams = {
slotLength = 0.1;
decentralisationParam = 0.8;
Expand Down
12 changes: 0 additions & 12 deletions nix/svclib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,11 @@ let
name: decl:
extractServiceScript (decl // { svcName = name; });

# This provides a development environment that can be used with nix-shell or
# lorri. See https://input-output-hk.github.io/haskell.nix/user-guide/development/
# NOTE: due to some cabal limitation,
# you have to remove all `source-repository-package` entries from cabal.project
# after entering nix-shell for cabal to use nix provided dependencies for them.
mkSupervisordCluster =
{ useCabalRun, profileName }:
pkgs.callPackage ./supervisord-cluster
{ inherit profileName useCabalRun;
workbench = pkgs.callPackage ./workbench { inherit useCabalRun; };
};
in
{
inherit
defServiceModule
mkScriptOfService
mkServiceScript
mkSupervisordCluster
;
}
3 changes: 3 additions & 0 deletions nix/workbench/backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ usage_backend() {
Start generator
cleanup-cluster RUNDIR
Wipe cluster state to pristine
wait-pools-stopped RUNDIR
Wait until all pools are stopped
stop-cluster RUNDIR
lostream-fixup-jqargs RUNDIR
Expand All @@ -44,6 +46,7 @@ case "${op}" in
start-cluster ) backend_$WORKBENCH_BACKEND "$@";;
start-generator ) backend_$WORKBENCH_BACKEND "$@";;
cleanup-cluster ) backend_$WORKBENCH_BACKEND "$@";;
wait-pools-stopped ) backend_$WORKBENCH_BACKEND "$@";;
stop-cluster ) backend_$WORKBENCH_BACKEND "$@";;
lostream-fixup-jqargs ) backend_$WORKBENCH_BACKEND "$@";;
lostream-fixup-jqexpr ) backend_$WORKBENCH_BACKEND "$@";;
Expand Down
26 changes: 21 additions & 5 deletions nix/workbench/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,28 @@ let
else "nix-exes+checkout-wb";

shellHook = ''
echo 'workbench shellHook: workbenchDevMode=${toString workbenchDevMode} useCabalRun=${toString useCabalRun}'
export WORKBENCH_BACKEND=supervisor
${optionalString
workbenchDevMode
''
echo 'workbench: dev mode enabled, calling wb directly from checkout (instead of using Nix store)' >&2
export WORKBENCH_CARDANO_NODE_REPO_ROOT=$(git rev-parse --show-toplevel)
export WORKBENCH_EXTRA_FLAGS=
function wb() {
$WORKBENCH_CARDANO_NODE_REPO_ROOT/nix/workbench/wb --set-mode ${checkoutWbMode} $WORKBENCH_EXTRA_FLAGS "$@"
}
export -f wb
''}
${optionalString
useCabalRun
''
. nix/workbench/lib.sh
. nix/workbench/lib-cabal.sh
''}
''}
export CARDANO_NODE_SOCKET_PATH=run/current/node-0/node.socket
'';

Expand Down Expand Up @@ -197,9 +196,26 @@ let
cp $nodeServicesPath $out/node-services.json
cp $generatorServicePath $out/generator-service.json
'';

with-workbench-profile =
{ pkgs, backend, envArgs, profileName }:
let
workbenchProfiles = generateProfiles
{ inherit pkgs backend envArgs; };

profile = workbenchProfiles.profiles."${profileName}"
or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames workbenchProfiles.profiles)}");

profileOut = profileOutput
{ inherit profile;
backendProfileOutput =
backend.profileOutput { inherit profile; };
};
in { inherit profile profileOut; };

in
{
inherit workbench runWorkbench runJq;
inherit workbench runWorkbench runJq with-workbench-profile;

inherit generateProfiles profileOutput shellHook;
}
Loading

0 comments on commit 75de27d

Please sign in to comment.