Skip to content

Commit

Permalink
workbench: Make shell multi-backend aware
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaste committed Nov 23, 2022
1 parent 106bd14 commit 3bc066b
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 59 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ NUM_PROC = $(nproc --all)
ERA ?= bage

PROFILE ?= default-${ERA}
BACKEND ?= supervisor
REV ?= master
ITER ?=
ARGS ?=
Expand Down Expand Up @@ -49,7 +50,7 @@ ci-targets: $(CI_TARGETS)
## Base targets:
##
shell: ## Nix shell, (workbench from /nix/store), vars: PROFILE, CMD, RUN
nix-shell -A 'workbench-shell' --max-jobs 8 --cores 0 --show-trace --argstr profileName ${PROFILE} ${ARGS} ${if ${CMD},--command "${CMD}"} ${if ${RUN},--run "${RUN}"}
nix-shell -A 'workbench-shell' --max-jobs 8 --cores 0 --show-trace --argstr profileName ${PROFILE} --argstr backendName ${BACKEND} ${ARGS} ${if ${CMD},--command "${CMD}"} ${if ${RUN},--run "${RUN}"}
shell-dev shell-prof shell-nix: shell
shell-nix: ARGS += --arg 'workbenchDevMode' false ## Nix shell, (workbench from Nix store), vars: PROFILE, CMD, RUN
shell-prof: ARGS += --arg 'profiled' true ## Nix shell, everything Haskell built profiled
Expand Down
1 change: 1 addition & 0 deletions nix/custom-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ self: {
stateDir = "run/current";
batchName = "plain";
profileName = "default-bage";
backendName = "supervisor";
basePort = 30000;
enableEKG = true;
workbenchDevMode = true;
Expand Down
1 change: 0 additions & 1 deletion nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ final: prev: with final; {
nomad-workbench-for-profile =
{ batchName ? customConfig.localCluster.batchName
, profileName ? customConfig.localCluster.profileName
# FIXME: Makes no sense for this backend!
, useCabalRun ? false
, workbenchDevMode ? false
, profiled ? false
Expand Down
2 changes: 1 addition & 1 deletion nix/workbench/backend/nomad-run.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ in
mv run/$run/* .
rmdir run/$run run
cat > $out/nix-support/hydra-build-products <<EOF
report workbench-log $out wb-start.log
report meta $out meta.json
Expand All @@ -144,6 +143,7 @@ in
in
{
inherit stateDir;
inherit profileName;
inherit workbench nomad-workbench;
inherit (nomad-workbench) backend;
inherit profileNix profile topology genesis;
Expand Down
3 changes: 3 additions & 0 deletions nix/workbench/backend/nomad.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ let
rec
{ name = "nomad";

# Unlike the supervisor backend `useCabalRun` is always false here.
useCabalRun = false;

services-config = import ./services-config.nix {inherit lib workbench basePort stateDir; useCabalRun = false; inherit enableEKG;};

extraShellPkgs = with pkgs; [
Expand Down
2 changes: 2 additions & 0 deletions nix/workbench/backend/supervisor-run.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ in
in
{
inherit stateDir;
inherit profileName;
inherit workbench supervisord-workbench;
inherit (supervisord-workbench) backend;
inherit profileNix profile topology genesis;
inherit interactive-start interactive-stop interactive-restart;
inherit profile-run;
Expand Down
21 changes: 21 additions & 0 deletions nix/workbench/backend/supervisor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,29 @@ let
rec
{ name = "supervisor";

# Unlike the nomad backend `useCabalRun` is honored here.
inherit useCabalRun;

services-config = import ./services-config.nix {inherit lib workbench basePort stateDir useCabalRun enableEKG;};

extraShellPkgs = with pkgs; [
python3Packages.supervisor
]
++ lib.optionals ( useCabalRun)
(with haskellPackages; [
cabalWrapped
ghcid
haskellBuildUtils
cabal-plan
])
## Workbench's main script is called directly in dev mode.
++ lib.optionals (!useCabalRun)
[
cardano-node
cardano-tracer
tx-generator
];

materialise-profile =
{ profileNix }:
pkgs.runCommand "workbench-backend-output-${profileNix.name}-${name}d"
Expand Down
14 changes: 13 additions & 1 deletion nix/workbench/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ case "$op" in
local usage="USAGE: wb run $op BATCH-NAME PROFILE-NAME [ENV-CONFIG-OPTS..] [-- BACKEND-ARGS-AND-ENV-CONFIG-OPTS..]"
local batch=${1:?$usage}; shift
local profile_name=${1:?$usage}; shift
local backend_name=${1:?$usage}; shift

local profile= topology= genesis_cache_entry= manifest= preset= cabal_mode=
while test $# -gt 0
Expand Down Expand Up @@ -360,7 +361,18 @@ case "$op" in
profile describe-timing "$timing"

## 3. decide the tag:
local run=$(jq '.start_tag' -r <<<$timing)$(if test "$batch" != 'plain'; then echo -n .$batch; fi).$hash.$profile_name$(test -z "$cabal_mode" && echo '.nix')
if [ "$backend_name" == "supervisor" ];
then
local backend_identifier="sup"
else
if [ "$backend_name" == "nomad" ];
then
local backend_identifier="nom"
else
local backend_identifier="$backend_name"
fi
fi
local run=$(jq '.start_tag' -r <<<$timing)$(if test "$batch" != 'plain'; then echo -n .$batch; fi).$hash.$profile_name.$backend_identifier
progress "run | tag" "allocated run identifier (tag): $(with_color white $run)"

## 4. allocate directory:
Expand Down
48 changes: 16 additions & 32 deletions nix/workbench/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
##
, cardano-mainnet-mirror
##
, profileName
, workbenchRun
, workbenchDevMode ? false
, useCabalRun ? false
##
, profiled ? false
, withHoogle ? true
Expand All @@ -18,18 +17,15 @@

with lib;

let cluster = pkgs.supervisord-workbench-for-profile {
inherit profileName useCabalRun profiled;
};

inherit (cluster) profile;
let
inherit (workbenchRun) profileName backend profile;

shellHook = { workbenchDevMode, useCabalRun, profiled, profileName, withMainnet }: ''
shellHook = { profileName, backend, workbenchDevMode, profiled, withMainnet }: ''
while test $# -gt 0
do shift; done ## Flush argv[]
echo 'workbench shellHook: workbenchDevMode=${toString workbenchDevMode} useCabalRun=${toString useCabalRun} profiled=${toString profiled} profileName=${profileName}'
export WB_BACKEND=supervisor
echo 'workbench shellHook: profileName=${profileName} backendName=${backend.name} useCabalRun=${toString backend.useCabalRun} workbenchDevMode=${toString workbenchDevMode} profiled=${toString profiled} '
export WB_BACKEND=${backend.name}
export WB_SHELL_PROFILE=${profileName}
export WB_SHELL_PROFILE_DIR=${profile}
Expand All @@ -46,7 +42,7 @@ let cluster = pkgs.supervisord-workbench-for-profile {
''}
${optionalString
useCabalRun
backend.useCabalRun
''
. nix/workbench/lib.sh
. nix/workbench/lib-cabal.sh ${optionalString profiled "--profiled"}
Expand Down Expand Up @@ -74,7 +70,7 @@ let cluster = pkgs.supervisord-workbench-for-profile {
in project.shellFor {
name = "workbench-shell";

shellHook = shellHook { inherit workbenchDevMode useCabalRun profiled profileName withMainnet; };
shellHook = shellHook { inherit profileName backend workbenchDevMode profiled withMainnet; };

inherit withHoogle;

Expand All @@ -97,19 +93,14 @@ in project.shellFor {
# These programs will be available inside the nix-shell.
nativeBuildInputs = with pkgs; with haskellPackages; with cardanoNodePackages; [
cardano-ping
cabalWrapped
db-analyser
ghcid
haskellBuildUtils
pkgs.graphviz
graphmod
cabal-plan
weeder
nixWrapped
pkgconfig
profiteur
profiterole
python3Packages.supervisor
ghc-prof-flamegraph
sqlite-interactive
tmux
Expand All @@ -118,24 +109,17 @@ in project.shellFor {
pkgs.moreutils
pkgs.pstree
pkgs.time
cluster.interactive-start
cluster.interactive-stop
cluster.interactive-restart
workbenchRun.interactive-start
workbenchRun.interactive-stop
workbenchRun.interactive-restart
] ++ lib.optional haveGlibcLocales pkgs.glibcLocales
## Workbench's main script is called directly in dev mode.
++ lib.optionals (!useCabalRun)
[
cardano-cli
cardano-node
cardano-topology
cardano-tracer
locli
tx-generator
]
++ lib.optionals (!backend.useCabalRun) [cardano-topology cardano-cli locli]
++ backend.extraShellPkgs
++ lib.optionals (!workbenchDevMode)
[
cluster.workbench.workbench
];
workbenchRun.workbench.workbench
]
;

} // { inherit shellHook;
}
4 changes: 2 additions & 2 deletions nix/workbench/wb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ start()
{
local batch_name=
local profile_name= profile=
local backend=supervisor
local backend=${WB_BACKEND:-supervisor}
local node_source=.
local node_rev=
local cabal_mode=
Expand Down Expand Up @@ -185,7 +185,7 @@ start()
${run_allocate_args[@]}
--manifest "$manifest"
)
run ${run_args[@]} 'allocate' $batch_name $profile_name "${args[@]}"
run ${run_args[@]} 'allocate' $batch_name $profile_name $backend "${args[@]}"
local run=$(run current-tag)

current_run_path=$(run current-path)
Expand Down
63 changes: 42 additions & 21 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let defaultCustomConfig = import ./nix/custom-config.nix defaultCustomConfig;
in
{ withHoogle ? defaultCustomConfig.withHoogle
, profileName ? defaultCustomConfig.localCluster.profileName
, backendName ? defaultCustomConfig.localCluster.backendName
, workbenchDevMode ? defaultCustomConfig.localCluster.workbenchDevMode
, useCabalRun ? true
, customConfig ? {
Expand Down Expand Up @@ -55,26 +56,46 @@ let

haveGlibcLocales = pkgs.glibcLocales != null && stdenv.hostPlatform.libc == "glibc";

workbench-shell = with customConfig.localCluster;
import ./nix/workbench/shell.nix
{ inherit pkgs lib haskellLib project;
inherit setLocale haveGlibcLocales commandHelp;
inherit cardano-mainnet-mirror;
inherit profileName workbenchDevMode useCabalRun;
inherit profiled withHoogle;
};
workbench-shell =
let
workbenchRun =
if backendName == "nomad"
then pkgs.nomad-workbench-for-profile
{ inherit profileName useCabalRun profiled; }
# Supervidor by default.
else pkgs.supervisord-workbench-for-profile
{ inherit profileName useCabalRun profiled; }
;
in with customConfig.localCluster;
import ./nix/workbench/shell.nix
{ inherit pkgs lib haskellLib project;
inherit setLocale haveGlibcLocales commandHelp;
inherit cardano-mainnet-mirror;
inherit workbenchRun workbenchDevMode;
inherit profiled withHoogle;
};

devops =
let devopsShellParams =
{ inherit workbenchDevMode profiled;
profileName = "devops-bage";
withMainnet = false;
let profileName = "devops-bage";
workbenchRun = pkgs.supervisord-workbench-for-profile
{
inherit profileName;
useCabalRun = false;
};
cluster = pkgs.supervisord-workbench-for-profile
{
inherit (devopsShellParams) profileName useCabalRun;
devopsShellParams =
{ inherit profileName;
backend = workbenchRun.backend;
inherit workbenchDevMode profiled;
withMainnet = false;
};
devopsShell = with customConfig.localCluster;
import ./nix/workbench/shell.nix
{ inherit pkgs lib haskellLib project;
inherit setLocale haveGlibcLocales commandHelp;
inherit cardano-mainnet-mirror;
inherit workbenchRun workbenchDevMode;
inherit profiled withHoogle;
};
in project.shellFor {
name = "devops-shell";

Expand All @@ -94,11 +115,11 @@ let
pkgs.graphviz
python3Packages.supervisor
python3Packages.ipython
cluster.interactive-start
cluster.interactive-stop
cluster.interactive-restart
workbenchRun.interactive-start
workbenchRun.interactive-stop
workbenchRun.interactive-restart
cardanolib-py
cluster.workbench.workbench
workbenchRun.workbench.workbench
pstree
pkgs.time
];
Expand All @@ -108,10 +129,10 @@ let
| ${figlet}/bin/figlet -f banner -c \
| ${lolcat}/bin/lolcat
${workbench-shell.shellHook devopsShellParams}
${devopsShell.shellHook devopsShellParams}
# Socket path default to first node launched by "start-cluster":
export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${cluster.stateDir} 'node-0')
export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${workbenchRun.stateDir} 'node-0')
${setLocale}
Expand Down

0 comments on commit 3bc066b

Please sign in to comment.