line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# system::docker Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::System::Docker; |
7
|
1
|
|
|
1
|
|
628
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
506
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable jail) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
name => [ qw(name) ], |
20
|
|
|
|
|
|
|
username => [ qw(username) ], |
21
|
|
|
|
|
|
|
password => [ qw(password) ], |
22
|
|
|
|
|
|
|
email => [ qw(email) ], |
23
|
|
|
|
|
|
|
force => [ qw(0|1) ], |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
attributes_default => { |
26
|
|
|
|
|
|
|
force => 1, |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
commands => { |
29
|
|
|
|
|
|
|
install => [ ], # Inherited |
30
|
|
|
|
|
|
|
build => [ qw(name directory) ], |
31
|
|
|
|
|
|
|
search => [ qw(name) ], |
32
|
|
|
|
|
|
|
get_image_id => [ qw(name) ], |
33
|
|
|
|
|
|
|
list => [ ], |
34
|
|
|
|
|
|
|
start => [ qw(name|$name_list) ], |
35
|
|
|
|
|
|
|
stop => [ qw(name|$name_list) ], |
36
|
|
|
|
|
|
|
restart => [ qw(name|$name_list) ], |
37
|
|
|
|
|
|
|
create => [ qw(name ip_address) ], |
38
|
|
|
|
|
|
|
backup => [ qw(name|$name_list) ], |
39
|
|
|
|
|
|
|
restore => [ qw(name ip_address archive_tar_gz) ], |
40
|
|
|
|
|
|
|
delete => [ qw(name) ], |
41
|
|
|
|
|
|
|
update => [ ], |
42
|
|
|
|
|
|
|
execute => [ qw(name command) ], |
43
|
|
|
|
|
|
|
console => [ qw(name) ], |
44
|
|
|
|
|
|
|
login => [ qw(email|OPTIONAL username|OPTIONAL password|OPTIONAL) ], |
45
|
|
|
|
|
|
|
push => [ qw(name) ], |
46
|
|
|
|
|
|
|
tag => [ qw(id tag) ], |
47
|
|
|
|
|
|
|
pull => [ qw(name) ], |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
# Have to be optional because of install Command |
50
|
|
|
|
|
|
|
optional_binaries => { |
51
|
|
|
|
|
|
|
'docker' => [ ], |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
require_binaries => { |
54
|
|
|
|
|
|
|
'wget' => [ ], |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
need_packages => { |
57
|
|
|
|
|
|
|
ubuntu => [ qw(wget) ], |
58
|
|
|
|
|
|
|
debian => [ qw(wget) ], |
59
|
|
|
|
|
|
|
kali => [ qw(wget) ], |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub brik_init { |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if (! $self->brik_has_binary("docker")) { |
68
|
0
|
|
|
|
|
|
$self->log->warning("brik_init: you have to execute install Command now"); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $self->SUPER::brik_init; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub install { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $self->SUPER::execute("wget -qO- https://get.docker.com/ | sh"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub build { |
81
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
82
|
0
|
|
|
|
|
|
my ($name, $directory) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('build', $name) or return; |
85
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('build', $directory) or return; |
86
|
0
|
0
|
|
|
|
|
$self->brik_help_run_directory_not_found('build', $directory) or return; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $cmd = "docker build -t $name $directory"; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub search { |
94
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
95
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('search', $jail_name) or return; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $cmd = "docker search $jail_name"; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub execute { |
105
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
106
|
0
|
|
|
|
|
|
my ($jail_name, $command) = @_; |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('execute', $jail_name) or return; |
109
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('execute', $command) or return; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $self->console($jail_name, $command); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub get_image_id { |
115
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
116
|
0
|
|
|
|
|
|
my ($name) = @_; |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('get_image_id', $name) or return; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
my $lines = $self->list or return; |
121
|
0
|
|
|
|
|
|
for my $line (@$lines) { |
122
|
0
|
|
|
|
|
|
my @toks = split(/\s+/, $line); |
123
|
0
|
0
|
|
|
|
|
if ($toks[0] eq $name) { |
124
|
0
|
|
|
|
|
|
return $toks[2]; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return 'undef'; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub list { |
132
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $cmd = "docker images"; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $self->capture($cmd); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub stop { |
140
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my ($name) = @_; |
142
|
|
|
|
|
|
|
|
143
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('stop', $name) or return; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my $cmd = "docker stop $name"; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub start { |
151
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
152
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('start', $jail_name) or return; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $cmd = "TODO"; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub restart { |
162
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
163
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('restart', $jail_name) or return; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $cmd = "TODO"; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub create { |
173
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
174
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('create', $jail_name) or return; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my $cmd = "docker pull $jail_name"; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub backup { |
184
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
185
|
0
|
|
|
|
|
|
my ($jail_name) = @_; |
186
|
|
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('backup', $jail_name) or return; |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
my $cmd = "TODO"; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub restore { |
195
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
196
|
0
|
|
|
|
|
|
my ($jail_name, $archive_tar_gz) = @_; |
197
|
|
|
|
|
|
|
|
198
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('restore', $jail_name) or return; |
199
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('restore', $archive_tar_gz) or return; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
my $cmd = "TODO"; |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub delete { |
207
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
208
|
0
|
|
|
|
|
|
my ($name) = @_; |
209
|
|
|
|
|
|
|
|
210
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('delete', $name) or return; |
211
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
my $cmd = "docker rmi -f $name"; |
213
|
0
|
0
|
|
|
|
|
$self->SUPER::execute($cmd) or return; |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
return $name; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub update { |
219
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# XXX: needed? |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
return 1; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub console { |
227
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
228
|
0
|
|
|
|
|
|
my ($name, $shell) = @_; |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
0
|
|
|
|
$shell ||= '/bin/bash'; |
231
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('console', $name) or return; |
232
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
my $cmd = "docker run -it $name '$shell'"; |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub login { |
239
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
240
|
0
|
|
|
|
|
|
my ($email, $username, $password) = @_; |
241
|
|
|
|
|
|
|
|
242
|
0
|
|
0
|
|
|
|
$email ||= $self->email; |
243
|
0
|
|
0
|
|
|
|
$username ||= $self->username; |
244
|
0
|
|
0
|
|
|
|
$password ||= $self->password; |
245
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('login', $email) or return; |
246
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('login', $username) or return; |
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
|
my $cmd = "docker login --username=$username --email=$email"; |
249
|
0
|
0
|
|
|
|
|
if ($password) { |
250
|
0
|
|
|
|
|
|
$cmd .= " --password=$password"; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub push { |
257
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
258
|
0
|
|
|
|
|
|
my ($name) = @_; |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
0
|
|
|
|
$name ||= $self->name; |
261
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('push', $name) or return; |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
my $cmd = "docker push $name"; |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub tag { |
269
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
270
|
0
|
|
|
|
|
|
my ($id, $tag) = @_; |
271
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('tag', $id) or return; |
273
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('tag', $tag) or return; |
274
|
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
|
my $cmd = "docker tag $id $tag"; |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub pull { |
281
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
282
|
0
|
|
|
|
|
|
my ($name) = @_; |
283
|
|
|
|
|
|
|
|
284
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('pull', $name) or return; |
285
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
my $cmd = "docker pull $name"; |
287
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
|
return $self->SUPER::execute($cmd); |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
1; |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
__END__ |