line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Docker::Image; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
100612
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
115
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
94
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1475
|
use Time::HiRes 'sleep'; |
|
3
|
|
|
|
|
3487
|
|
|
3
|
|
|
|
|
16
|
|
7
|
3
|
|
|
3
|
|
2596
|
use Data::Util ':check'; |
|
3
|
|
|
|
|
2649
|
|
|
3
|
|
|
|
|
649
|
|
8
|
3
|
|
|
3
|
|
1178
|
use Class::Load qw/try_load_class/; |
|
3
|
|
|
|
|
65171
|
|
|
3
|
|
|
|
|
208
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
989
|
use Test::Docker::Image::Utility qw(docker); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
192
|
|
11
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
12
|
3
|
|
|
|
|
21
|
ro => [qw/tag container_ports container_id/], |
13
|
3
|
|
|
3
|
|
1855
|
); |
|
3
|
|
|
|
|
3108
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
6
|
|
|
6
|
1
|
12097
|
my $class = shift; |
19
|
6
|
50
|
|
|
|
65
|
my %args = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
20
|
|
|
|
|
|
|
|
21
|
6
|
|
100
|
|
|
36
|
my $boot_class = delete $args{boot} || 'Test::Docker::Image::Boot'; |
22
|
|
|
|
|
|
|
|
23
|
6
|
100
|
|
|
|
23
|
try_load_class( $boot_class ) or die "failed to load $boot_class"; |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
352
|
my $image_tag = delete $args{tag}; |
26
|
5
|
100
|
|
|
|
31
|
die "tag argument is required" unless $image_tag; |
27
|
|
|
|
|
|
|
|
28
|
4
|
100
|
|
|
|
65
|
die "container_ports argument must be ArrayRef" |
29
|
|
|
|
|
|
|
unless is_array_ref $args{container_ports}; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
5
|
my @ports = map { ('-p', $_) } @{ $args{container_ports} }; |
|
3
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
5
|
|
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
9
|
my $boot = $boot_class->new; |
34
|
2
|
|
|
|
|
7
|
my $container_id = $boot->docker_run(\@ports, $image_tag); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# wait to launch the container |
37
|
2
|
|
50
|
|
|
1002557
|
sleep $args{sleep_sec} || 0.5; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
44
|
my $self = bless { |
40
|
|
|
|
|
|
|
tag => $image_tag, |
41
|
|
|
|
|
|
|
container_ports => $args{container_ports}, |
42
|
|
|
|
|
|
|
container_id => $container_id, |
43
|
|
|
|
|
|
|
boot => $boot, |
44
|
|
|
|
|
|
|
boot_class => $boot_class, |
45
|
|
|
|
|
|
|
}, $class; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
21
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub port { |
51
|
1
|
|
|
1
|
1
|
8
|
my ($self, $container_port) = @_; |
52
|
1
|
|
|
|
|
12
|
return $self->{boot}->docker_port($self->container_id, $container_port); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub host { |
56
|
0
|
|
|
0
|
1
|
|
$_[0]->{boot}->host; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub DESTROY { |
60
|
0
|
|
|
0
|
|
|
my $self = shift; |
61
|
0
|
|
|
|
|
|
for my $subcommand ( qw/kill rm/ ) { |
62
|
0
|
|
|
|
|
|
docker($subcommand, $self->container_id); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |