| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Conan::Deploy; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21559
|
use Carp; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
97
|
|
|
4
|
1
|
|
|
1
|
|
831
|
use File::Rsync; |
|
|
1
|
|
|
|
|
44203
|
|
|
|
1
|
|
|
|
|
625
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub __config { |
|
7
|
1
|
|
|
1
|
|
93
|
my @config_files = glob '/etc/conan.cfg ~/.conanrc'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
|
|
9
|
my %config_options; |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
12
|
for( @config_files ){ |
|
12
|
2
|
50
|
|
|
|
49
|
next unless -f $_; |
|
13
|
0
|
0
|
|
|
|
0
|
print "D: Parsing [$_]\n" if -f $_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
0
|
my $fd; |
|
16
|
0
|
|
|
|
|
0
|
open $fd, "<$_"; |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
0
|
next unless $fd; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
my @lines = <$fd>; |
|
21
|
0
|
|
|
|
|
0
|
chomp for @lines; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
s/#.*// for @lines; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
@lines = grep { /^\S/ } @lines; |
|
|
0
|
|
|
|
|
0
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
0
|
my %r = map { ($1,$2) if /^(\S+)=(\S+)/ } @lines; |
|
|
0
|
|
|
|
|
0
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
for ( keys %r ){ |
|
30
|
0
|
|
|
|
|
0
|
$config_options{"$_"} = $r{"$_"}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
1
|
|
|
|
|
16
|
return %config_options; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
|
37
|
1
|
|
|
1
|
1
|
17597
|
my $class = shift; |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
29
|
my %config_options = __config @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
14
|
my $args = { |
|
42
|
|
|
|
|
|
|
%config_options, |
|
43
|
|
|
|
|
|
|
@_, |
|
44
|
|
|
|
|
|
|
}; |
|
45
|
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
9
|
return bless $args => $class; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Call for the "promot image" call |
|
50
|
|
|
|
|
|
|
sub promote_image { |
|
51
|
1
|
|
|
1
|
1
|
1077
|
my $self = shift; |
|
52
|
1
|
|
|
|
|
7
|
my $image = shift; |
|
53
|
1
|
|
|
|
|
2
|
my $orig_image = $image; |
|
54
|
|
|
|
|
|
|
|
|
55
|
1
|
50
|
|
|
|
5
|
unless( defined $self->{srcimagebase} ){ |
|
56
|
0
|
|
|
|
|
0
|
croak "Must supply a srcimagebase to the Conan::Deploy constructor"; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
50
|
|
|
|
31
|
unless( -d "$self->{srcimagebase}" ){ |
|
60
|
0
|
|
|
|
|
0
|
croak "$self->{srcimagebase} doesn't exist"; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
4
|
unless( $self->{targetimagebase} ){ |
|
64
|
0
|
|
|
|
|
0
|
croak "Must supply a targetimagebase to the Conan::Deploy constructor"; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
23
|
unless( -d "$self->{targetimagebase}" ){ |
|
69
|
0
|
|
|
|
|
0
|
croak "$self->{targetimagebase} doesn't exist"; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Check if the source image has a / in it |
|
73
|
1
|
50
|
|
|
|
14
|
unless( $image =~ /\// ){ |
|
74
|
1
|
|
|
|
|
94
|
$image = $self->{srcimagebase} . "/" . $image; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
50
|
33
|
|
|
42
|
unless( -d $image || -f $image ){ |
|
78
|
0
|
|
|
|
|
0
|
croak "$image doesn't exist"; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
303
|
printf "D: Copying [%s] to [%s]\n", $image, $self->{targetimagebase}; |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
40
|
my $obj = File::Rsync->new( { archive => 1, compress => 1 } ); |
|
84
|
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
540
|
$obj->exec( { src => $image, dest => $self->{targetimagebase} } ) or croak "rsync failed"; |
|
86
|
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
52572
|
$self->md5( $orig_image ); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub md5 { |
|
91
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
|
92
|
1
|
|
|
|
|
6
|
my $image = shift; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub md5dir { |
|
95
|
2
|
|
|
2
|
0
|
7
|
my ($base, $image) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
2
|
|
|
|
|
8
|
my $cmd = 'find ' . $base . "/" . $image . " -type f | xargs md5sum"; |
|
98
|
2
|
|
|
|
|
588
|
print "D: Running [$cmd]\n"; |
|
99
|
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
7833
|
open $fd, "$cmd |"; |
|
101
|
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
25397
|
my @lines = <$fd>; |
|
103
|
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
111
|
close $fd; |
|
105
|
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
50
|
chomp for @lines; |
|
107
|
|
|
|
|
|
|
|
|
108
|
1
|
|
|
1
|
|
923
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
10026
|
|
|
|
1
|
|
|
|
|
244
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
120
|
s/\s+$base\// / for @lines; |
|
111
|
2
|
|
|
|
|
40
|
s/\s+$image/ / for @lines; |
|
112
|
|
|
|
|
|
|
|
|
113
|
2
|
50
|
|
|
|
17
|
my %r = map { ($2,$1) if /^(\S+)\s+(\S+)/ } @lines; |
|
|
4
|
|
|
|
|
124
|
|
|
114
|
2
|
|
|
|
|
28
|
return %r; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
8
|
my %t = md5dir( $self->{targetimagebase}, $image ); |
|
118
|
1
|
|
|
|
|
16
|
my %s = md5dir( $self->{srcimagebase}, $image ); |
|
119
|
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
18
|
for my $file ( keys %s ){ |
|
121
|
|
|
|
|
|
|
# Check that the md5s match |
|
122
|
2
|
50
|
|
|
|
19
|
croak "Mismatch between target and source on [$file]" |
|
123
|
|
|
|
|
|
|
if( $t{"$file"} ne $s{"$file"} ); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
1
|
|
|
|
|
397
|
return 1; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |