-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.nix
80 lines (77 loc) · 2.19 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
75
76
77
78
79
80
{
lib,
nix2container,
python-kidra,
buildEnv,
runCommand,
wlo-topic-assistant,
wlo-classification,
its-jointprobability,
}:
let
# this function takes a list of image layers and nests them, such that all
# previous layers are dependencies of later layers. this avoids duplicate
# dependencies
# from https://blog.eigenvalue.net/2023-nix2container-everything-once/
foldImageLayers =
let
mergeToLayer =
priorLayers: component:
assert builtins.isList priorLayers;
assert builtins.isAttrs component;
let
layer = nix2container.buildLayer (component // { layers = priorLayers; });
in
priorLayers ++ [ layer ];
in
layers: lib.foldl mergeToLayer [ ] layers;
in
nix2container.buildImage {
name = python-kidra.pname;
tag = python-kidra.version;
config = {
Cmd = [ "${python-kidra}/bin/python-kidra" ];
ExposedPorts = {
"8080/tcp" = { };
};
};
# create an empty /tmp directory for playwright (playwright assumes there to
# be a /tmp directory and will fail if it does not exist -- nix does not
# create one for the image by default)
copyToRoot = buildEnv {
name = "tmp";
pathsToLink = [ "/tmp" ];
paths = [
(runCommand "mk-tmp" { } ''
mkdir -p $out/tmp
'')
];
};
# separate out some of the larger dependencies into their own layers, so that
# we don't need to push / pull them every time
layers =
let
layerDefinitions = [
{
deps = [ wlo-classification ];
# while we could probably increase the number of automatically
# generated layers a bit, due to inherent redundancy between the
# manually defined layers, choosing these such that the total number
# of layers is less than 100 is always going to be safe (whereas
# choosing something larger may cause issues)
maxLayers = 25;
}
{
deps = [ its-jointprobability ];
maxLayers = 25;
}
{
deps = [ wlo-topic-assistant ];
maxLayers = 25;
}
];
in
# de-duplicate the manually defined layers
foldImageLayers layerDefinitions;
maxLayers = 25;
}