-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.nix
74 lines (65 loc) · 2.5 KB
/
docker.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
{ writeScriptBin, dockerTools
, glibcLocales, iana-etc, openssl, bashInteractive, coreutils, utillinux, iproute, iputils, curl, socat
, cardano-node-simple, cardanoConfig
, environment ? "mainnet"
, type ? null
, connect
, connectArgs ? {}
, version ? "unstable"
}:
# assertOneOf "type" type [ "wallet" "explorer" "node" ];
let
localLib = import ../lib.nix;
connectToCluster = connect ({
inherit environment;
stateDir = "/wallet/${environment}";
walletListen = "0.0.0.0:8090";
walletDocListen = "0.0.0.0:8091";
ekgListen = "0.0.0.0:8000";
} // connectArgs);
startScriptConnect = name: args: writeScriptBin "cardano-start-${name}" ''
#!/bin/sh
set -euo pipefail
export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive"
if [ ! -d /wallet ]; then
echo '/wallet volume not mounted, you need to create one with `docker volume create` and pass the correct -v flag to `docker run`'
exit 1
fi
cd /wallet
exec ${connectToCluster.override args}
'';
confKey = localLib.environments.${environment}.confKey;
startScripts = [
(startScriptConnect "wallet" {})
(startScriptConnect "explorer" { executable = "explorer"; })
(writeScriptBin "cardano-start-node" ''
#!/bin/sh
set -euo pipefail
export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive"
if [ ! -d /state ]; then
echo '/state volume not mounted, you need to create one with `docker volume create` and pass the correct -v flag to `docker run`'
exit 1
cd /state
node_args="--db-path /state/db --rebuild-db --listen 0.0.0.0:3000 --json-log /state/logs/node.json --logs-prefix /state/logs --log-config /state/logs/log-config-node.yaml --metrics +RTS -N2 -qg -A1m -I0 -T -RTS --configuration-file ${cardanoConfig}/lib/configuration.yaml --configuration-key ${confKey}"
exec ${cardano-node-simple}/bin/cardano-node-simple $node_args "$@"
'')
];
in dockerTools.buildImage {
name = "cardano-sl";
tag = "${version}${if (type != null) then "-" + type else ""}-${environment}";
contents = [ iana-etc openssl bashInteractive coreutils utillinux iproute iputils curl socat ]
++ startScripts;
config = {
Cmd = [ "cardano-start-${if (type != null) then type else "wallet"}" ];
ExposedPorts = {
"3000/tcp" = {}; # protocol
"8090/tcp" = {}; # wallet
"8091/tcp" = {}; # wallet doc
"8100/tcp" = {}; # explorer api
"8000/tcp" = {}; # ekg
};
};
created = "2019-07-11T00:00:00Z";
extraCommands = ''
'';
}