-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker.nix
173 lines (166 loc) · 4.57 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# This module creates some `pog` tools that help make you more productive in Docker!
final: prev:
with prev;
rec {
da = pog {
name = "da";
version = "0.0.1";
description = "a shorthand to see all containers on a host";
flags = [
{ name = "json"; description = "shorthand for json output"; bool = true; }
{ name = "wide"; description = "show more columns"; bool = true; }
];
script = h: with h; ''
if ${flag "json"}; then
${_.d} ps -a --format json
else
extra="\t{{.CreatedAt}}\t{{.Size}}"
${_.d} container ls -a --format "table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}''${wide:+$extra}"
fi
'';
};
drm = pog {
name = "drm";
version = "0.0.1";
description = "quickly remove containers from your docker daemon!";
flags = [
_.flags.common.force
];
script = ''
${_.docker.da} | ${_.fzfqm} --header-lines=1 | ${_.docker.get_container} | ${_.xargs} -r ${_.d} rm ''${force:+--force}
'';
};
drmi = pog {
name = "drmi";
version = "0.0.1";
description = "quickly remove images from your docker daemon!";
flags = [
_.flags.common.force
];
script = ''
${_.docker.di} | ${_.fzfqm} --header-lines=1 | ${_.docker.get_image} | ${_.xargs} -r ${_.d} rmi ''${force:+--force}
'';
};
_dex = pog {
name = "dex";
version = "0.0.1";
description = "a quick and easy way to exec into a docker pod!";
flags = [
{
name = "container";
description = "the container to exec into";
prompt = ''
${_.d} ps -a | ${_.fzfq} --header-lines=1 | ${_.k8s.get_id}
'';
promptError = "you must specify a container to exec into!";
}
];
script = ''
debug "''${GREEN}exec'ing into '$container'!''${RESET}"
${_.d} exec --interactive --tty "$container" sh -c "${_.globals.hacks.bash_or_sh}"
'';
};
dshell = pog {
name = "dshell";
version = "0.0.1";
description = "a quick and easy way to pop a shell on docker!";
flags = [
_.flags.docker.image
{
name = "port";
description = "a port to expose to the host";
}
{
name = "command";
description = "the command to run within this shell";
default = _.globals.hacks.bash_or_sh;
}
{
name = "nix";
description = "mount the /nix store as readonly in the container";
bool = true;
}
{
name = "mount";
description = "mount the current directory into the container";
bool = true;
}
{
name = "user";
description = "user to run as inside the container";
}
];
script = ''
debug "''${GREEN}running image '$image' docker!''${RESET}"
container_name="$(echo "''${USER:-user}-dshell-''$(${final.util-linux}/bin/uuidgen | ${_.head} -c 8)" | tr -cd '[:alnum:]-')"
# shellcheck disable=SC2086
${_.d} run \
--interactive \
--tty \
--rm \
--entrypoint sh \
''${port:+--publish $port:$port} \
''${nix:+--volume /nix:/nix:ro} \
''${mount:+--volume $(pwd):/cwd} \
''${user:+--user $user} \
--name "$container_name" \
"$image" \
-c "$command"
'';
};
dlog = pog {
name = "dlog";
version = "0.0.1";
description = "a quick and easy way to log one or more containers!";
flags = [
{
name = "container";
description = "the containers to tail logs from";
prompt = ''
${_.d} ps -a | ${_.fzfqm} --header-lines=1 | ${_.k8s.get_id}
'';
promptError = "you must specify one or more containers to log from!";
}
{
name = "since";
description = "Return logs newer than a relative duration like 52, 2m, or 3h";
default = "10m";
}
];
script = helpers: ''
# shellcheck disable=SC2086
${final.ahab}/bin/ahab --since "$since" $container
'';
};
dlint = pog {
name = "dlint";
version = "0.0.1";
description = "a prescriptive hadolint dockerfile linter config";
flags = [
{
name = "file";
description = "the dockerfile to analyze";
default = "./Dockerfile";
}
];
script = ''
${pkgs.hadolint}/bin/hadolint \
--ignore DL3008 \
--ignore DL3009 \
--ignore DL3028 \
--ignore DL3015 \
--ignore DL4006 \
"$file"
'';
};
dtools = docker_pog_scripts;
docker_pog_scripts = [
# dlint
_dex
da
dlog
drm
drmi
dshell
];
}