-
Notifications
You must be signed in to change notification settings - Fork 721
/
supervisor-run.nix
155 lines (132 loc) · 4.38 KB
/
supervisor-run.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
let
batchNameDefault = "plain";
profileNameDefault = "default-bage";
in
{ pkgs
, cardanoNodePackages
, supervisord-workbench
##
, profileName ? profileNameDefault
, batchName ? batchNameDefault
##
, workbenchDevMode ? false
, cardano-node-rev ? "0000000000000000000000000000000000000000"
}:
let
inherit (supervisord-workbench) workbench backend cacheDir stateDir basePort;
with-supervisord-profile =
{ envArgsOverride ? {} }: ## TODO: envArgsOverride is not used!
workbench.with-profile
{ inherit backend profileName; };
inherit
(with-supervisord-profile {})
profileNix profile topology genesis;
in
let
inherit (profile.value) era composition monetary;
path = pkgs.lib.makeBinPath path';
path' =
[ cardanoNodePackages.bech32 pkgs.jq pkgs.gnused pkgs.coreutils pkgs.bash pkgs.moreutils
]
## In dev mode, call the script directly:
++ pkgs.lib.optionals (!workbenchDevMode)
[ workbench.workbench ];
interactive-start = pkgs.writeScriptBin "start-cluster" ''
set -euo pipefail
export PATH=$PATH:${path}
wb start \
--batch-name ${batchName} \
--profile-name ${profileName} \
--profile ${profile} \
--cache-dir ${cacheDir} \
--base-port ${toString basePort} \
''${WB_MODE_CABAL:+--cabal} \
"$@"
'';
interactive-stop = pkgs.writeScriptBin "stop-cluster" ''
set -euo pipefail
wb finish "$@"
'';
interactive-restart = pkgs.writeScriptBin "restart-cluster" ''
set -euo pipefail
wb run restart "$@" && \
echo "workbench: alternate command for this action: wb run restart" >&2
'';
nodeBuildProduct =
name:
"report ${name}-log $out ${name}/stdout";
profile-run =
{ trace ? false }:
let
inherit
(with-supervisord-profile
{ envArgsOverride = { cacheDir = "./cache"; stateDir = "./"; }; })
profileNix profile topology genesis;
run = pkgs.runCommand "workbench-run-supervisord-${profileName}"
{ requiredSystemFeatures = [ "benchmark" ];
nativeBuildInputs = with cardanoNodePackages; with pkgs; [
bash
bech32
coreutils
gnused
jq
moreutils
nixWrapped
pstree
python3Packages.supervisor
workbench.workbench
zstd
];
}
''
mkdir -p $out/{cache,nix-support}
cd $out
export HOME=$out
export WB_BACKEND=supervisor
export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${stateDir} node-0)
cmd=(
wb
${pkgs.lib.optionalString trace "--trace"}
start
--profile-name ${profileName}
--profile ${profile}
--topology ${topology}
--genesis-cache-entry ${genesis}
--batch-name smoke-test
--base-port ${toString basePort}
--node-source ${cardanoNodePackages.cardano-node.src.origSrc}
--node-rev ${cardano-node-rev}
--cache-dir ./cache
)
echo "''${cmd[*]}" > $out/wb-start.sh
time "''${cmd[@]}" 2>&1 |
tee $out/wb-start.log
## Convert structure from $out/run/RUN-ID/* to $out/*:
rm -rf cache
rm -f run/{current,-current}
find $out -type s | xargs rm -f
tag=$(cd run; ls)
(cd run; tar c $tag --zstd) > archive.tar.zst
mv run/$tag/* .
rmdir run/$tag run
cat > $out/nix-support/hydra-build-products <<EOF
report workbench-log $out wb-start.log
report meta $out meta.json
${pkgs.lib.concatStringsSep "\n"
(map nodeBuildProduct (__attrNames profileNix.node-specs.value))}
report archive-tar-zst $out archive.tar.zst
EOF
echo "workbench-test: completed run $tag"
'';
in
run // {
analysis = workbench.run-analysis { inherit pkgs workbench profileNix run; };
};
in
{
inherit stateDir;
inherit workbench supervisord-workbench;
inherit profileNix profile topology genesis;
inherit interactive-start interactive-stop interactive-restart;
inherit profile-run;
}