1 | #!/usr/bin/perl -w |
---|
2 | # |
---|
3 | # Common functions for virtual environment |
---|
4 | # |
---|
5 | # Copyright B. Cornec 2007-2016 |
---|
6 | # Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard |
---|
7 | # Provided under the GPL v2 |
---|
8 | # |
---|
9 | # $Id$ |
---|
10 | # |
---|
11 | |
---|
12 | package ProjectBuilder::VE; |
---|
13 | |
---|
14 | use strict; |
---|
15 | use Data::Dumper; |
---|
16 | use Carp 'confess'; |
---|
17 | use English; |
---|
18 | use File::Basename; |
---|
19 | use ProjectBuilder::Version; |
---|
20 | use ProjectBuilder::Base; |
---|
21 | use ProjectBuilder::Conf; |
---|
22 | use ProjectBuilder::Distribution; |
---|
23 | |
---|
24 | # Global vars |
---|
25 | # Inherit from the "Exporter" module which handles exporting functions. |
---|
26 | |
---|
27 | use vars qw($VERSION $REVISION @ISA @EXPORT); |
---|
28 | use Exporter; |
---|
29 | |
---|
30 | # Export, by default, all the functions into the namespace of |
---|
31 | # any code which uses this module. |
---|
32 | |
---|
33 | our @ISA = qw(Exporter); |
---|
34 | our @EXPORT = qw(pb_ve_launch pb_ve_snap pb_ve_get_type pb_ve_docker_repo pb_ve_docker_get_image); |
---|
35 | |
---|
36 | ($VERSION,$REVISION) = pb_version_init(); |
---|
37 | |
---|
38 | =pod |
---|
39 | |
---|
40 | =head1 NAME |
---|
41 | |
---|
42 | ProjectBuilder::VE, part of the project-builder.org - module dealing with Virtual Environment |
---|
43 | |
---|
44 | =head1 DESCRIPTION |
---|
45 | |
---|
46 | This modules provides functions to deal with Virtual Environements (VE), aka chroot/containers. |
---|
47 | |
---|
48 | =head1 SYNOPSIS |
---|
49 | |
---|
50 | use ProjectBuilder::VE; |
---|
51 | |
---|
52 | # |
---|
53 | # Return information on the running distro |
---|
54 | # |
---|
55 | my $pbos = pb_ve_launch(); |
---|
56 | |
---|
57 | =head1 USAGE |
---|
58 | |
---|
59 | =over 4 |
---|
60 | |
---|
61 | =item B<pb_ve_launch> |
---|
62 | |
---|
63 | This function launches a VE, creating it if necessary using multiple external potential tools. |
---|
64 | |
---|
65 | =cut |
---|
66 | |
---|
67 | sub pb_ve_launch { |
---|
68 | |
---|
69 | my $v = shift; |
---|
70 | my $pbforce = shift; # Which step are we in (0: create, 1: setup, 2: build, 3: use) |
---|
71 | my $locsnap = shift; |
---|
72 | my $vetype = shift; |
---|
73 | my $pbimage = shift; |
---|
74 | |
---|
75 | my $docrepo = ""; # By default no repository for docker available |
---|
76 | |
---|
77 | pb_log(2,"Entering pb_ve_launch at step $pbforce for type $vetype\n"); |
---|
78 | # Get distro context |
---|
79 | my $pbos = pb_distro_get_context($v); |
---|
80 | |
---|
81 | $vetype = pb_ve_get_type($vetype); |
---|
82 | my ($vepath) = pb_conf_get("vepath"); |
---|
83 | |
---|
84 | if ($vetype eq "docker") { |
---|
85 | $docrepo = pb_ve_docker_repo(); |
---|
86 | } |
---|
87 | |
---|
88 | # Architecture consistency |
---|
89 | my $arch = pb_get_arch(); |
---|
90 | if ($arch ne $pbos->{'arch'}) { |
---|
91 | die "Unable to launch a VE of architecture $pbos->{'arch'} on a $arch platform" unless (($pbos->{'arch'} =~ /i?86/o) && ($arch eq "x86_64")); |
---|
92 | } |
---|
93 | |
---|
94 | # If we are already root (from pbmkbm e.g.) don't use sudo, just call the command |
---|
95 | my $sudocmd=""; |
---|
96 | if ($EFFECTIVE_USER_ID != 0) { |
---|
97 | $sudocmd ="sudo "; |
---|
98 | foreach my $proxy (qw/http_proxy ftp_proxy/) { |
---|
99 | if (defined $ENV{$proxy}) { |
---|
100 | open(CMD,"sudo sh -c 'echo \$$proxy' |") or die "can't run sudo sh?: $!"; |
---|
101 | $_ = <CMD>; |
---|
102 | chomp(); |
---|
103 | die "sudo not passing through env var $proxy; '$ENV{$proxy}' != '$_'\nAdd line Defaults:`whoami` env_keep += \"$proxy\" to sudoers file?" unless $_ eq $ENV{$proxy}; |
---|
104 | close(CMD); |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | # Handle cross arch on Intel based platforms |
---|
110 | $sudocmd = "setarch i386 $sudocmd" if (($pbos->{'arch'} =~ /i[3456]86/) && ($arch eq 'x86_64')); |
---|
111 | |
---|
112 | my $root = pb_path_expand($vepath->{$ENV{PBPROJ}}); |
---|
113 | |
---|
114 | if (($vetype eq "chroot") || ($vetype eq "schroot") || ($vetype eq "docker")) { |
---|
115 | |
---|
116 | # We need to avoid umask propagation to the VE |
---|
117 | umask 0022; |
---|
118 | |
---|
119 | # We can probably only get those params now we have the distro context |
---|
120 | my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv"); |
---|
121 | |
---|
122 | if (((((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 0)) && ($vetype ne "docker")) |
---|
123 | # For docker we may have a reference image that we'll use |
---|
124 | || (($vetype eq "docker") && ($pbforce == 0) && ((not defined $pbimage) || ($pbimage eq "")))) { |
---|
125 | |
---|
126 | my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype"); |
---|
127 | my ($rbsopt1) = pb_conf_get_if("rbsopt"); |
---|
128 | |
---|
129 | # We have to rebuild the chroot |
---|
130 | if ($pbos->{'type'} eq "rpm") { |
---|
131 | |
---|
132 | # Which tool is used |
---|
133 | my $verpmstyle = $verpmtype->{$ENV{'PBPROJ'}}; |
---|
134 | die "No verpmtype defined for $ENV{PBPROJ}" unless (defined $verpmstyle); |
---|
135 | |
---|
136 | # Get potential rbs option |
---|
137 | my $rbsopt = ""; |
---|
138 | if (defined $rbsopt1) { |
---|
139 | if (defined $rbsopt1->{$verpmstyle}) { |
---|
140 | $rbsopt = $rbsopt1->{$verpmstyle}; |
---|
141 | } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) { |
---|
142 | $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}}; |
---|
143 | } else { |
---|
144 | $rbsopt = ""; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | my $postinstall = pb_ve_get_postinstall($pbos,$rbspi,$verpmstyle); |
---|
149 | if ($verpmstyle eq "rinse") { |
---|
150 | # Need to reshape the mirrors generated with local before-post-install script |
---|
151 | my $b4post = "--before-post-install "; |
---|
152 | my $postparam = pb_distro_get_param($pbos,$rbsb4pi); |
---|
153 | if ($postparam eq "") { |
---|
154 | $b4post = ""; |
---|
155 | } else { |
---|
156 | $b4post .= $postparam; |
---|
157 | } |
---|
158 | |
---|
159 | # Need to reshape the package list for pb |
---|
160 | my $addpkgs; |
---|
161 | $postparam = ""; |
---|
162 | $postparam .= pb_distro_get_param($pbos,$osmindep); |
---|
163 | if ($postparam eq "") { |
---|
164 | $addpkgs = ""; |
---|
165 | } else { |
---|
166 | my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis"; |
---|
167 | open(PKG,"> $pkgfile") || die "Unable to create $pkgfile"; |
---|
168 | foreach my $p (split(/,/,$postparam)) { |
---|
169 | print PKG "$p\n"; |
---|
170 | } |
---|
171 | close(PKG); |
---|
172 | $addpkgs = "--add-pkg-list $pkgfile"; |
---|
173 | } |
---|
174 | |
---|
175 | my $rinseverb = ""; |
---|
176 | $rinseverb = "--verbose" if ($pbdebug gt 0); |
---|
177 | my ($rbsconf) = pb_conf_get("rbsconf"); |
---|
178 | |
---|
179 | my $command = pb_check_req("rinse",0); |
---|
180 | pb_system("$sudocmd $command --directory \"$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}\" --arch \"$pbos->{'arch'}\" --distribution \"$pbos->{'name'}-$pbos->{'version'}\" --config \"$rbsconf->{$ENV{'PBPROJ'}}\" $b4post $postinstall $rbsopt $addpkgs $rinseverb","Creating the rinse VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose"); |
---|
181 | } elsif ($verpmstyle eq "rpmbootstrap") { |
---|
182 | my $rbsverb = ""; |
---|
183 | foreach my $i (1..$pbdebug) { |
---|
184 | $rbsverb .= " -v"; |
---|
185 | } |
---|
186 | my $addpkgs = ""; |
---|
187 | my $postparam = ""; |
---|
188 | $postparam .= pb_distro_get_param($pbos,$osmindep); |
---|
189 | if ($postparam eq "") { |
---|
190 | $addpkgs = ""; |
---|
191 | } else { |
---|
192 | $addpkgs = "-a $postparam"; |
---|
193 | } |
---|
194 | my $command = pb_check_req("rpmbootstrap",0); |
---|
195 | pb_system("$sudocmd $command $rbsopt $postinstall $addpkgs $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} $rbsverb","Creating the rpmbootstrap VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose"); |
---|
196 | pb_system("$sudocmd /bin/umount $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/proc","Umounting stale /proc","mayfail") if (-f "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/proc/cpuinfo"); |
---|
197 | } elsif ($verpmstyle eq "mock") { |
---|
198 | my ($rbsconf) = pb_conf_get("rbsconf"); |
---|
199 | my $command = pb_check_req("mock",0); |
---|
200 | pb_system("$sudocmd $command --init --resultdir=\"/tmp\" --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v $rbsopt","Creating the mock VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})"); |
---|
201 | # Once setup we need to install some packages, the pb account, ... |
---|
202 | pb_system("$sudocmd $command --install --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE"); |
---|
203 | } else { |
---|
204 | die "Unknown verpmtype type $verpmstyle. Report to dev team"; |
---|
205 | } |
---|
206 | } elsif ($pbos->{'type'} eq "deb") { |
---|
207 | my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}}; |
---|
208 | |
---|
209 | my $codename = pb_distro_get_param($pbos,$oscodename); |
---|
210 | my $postparam = ""; |
---|
211 | my $addpkgs; |
---|
212 | $postparam .= pb_distro_get_param($pbos,$osmindep); |
---|
213 | if ($postparam eq "") { |
---|
214 | $addpkgs = ""; |
---|
215 | } else { |
---|
216 | $addpkgs = "--include $postparam"; |
---|
217 | } |
---|
218 | my $debmir = ""; |
---|
219 | $debmir .= pb_distro_get_param($pbos,$rbsmirrorsrv); |
---|
220 | |
---|
221 | # Get potential rbs option |
---|
222 | my $rbsopt = ""; |
---|
223 | if (defined $rbsopt1) { |
---|
224 | if (defined $rbsopt1->{$vedebstyle}) { |
---|
225 | $rbsopt = $rbsopt1->{$vedebstyle}; |
---|
226 | } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) { |
---|
227 | $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}}; |
---|
228 | } else { |
---|
229 | $rbsopt = ""; |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | # debootstrap works with amd64 not x86_64 |
---|
234 | my $debarch = $pbos->{'arch'}; |
---|
235 | $debarch = "amd64" if ($pbos->{'arch'} eq "x86_64"); |
---|
236 | if ($vedebstyle eq "debootstrap") { |
---|
237 | my $dbsverb = ""; |
---|
238 | $dbsverb = "--verbose" if ($pbdebug gt 0); |
---|
239 | |
---|
240 | # Some perl modules are in Universe on Ubuntu |
---|
241 | $rbsopt .= " --components=main,universe" if ($pbos->{'name'} eq "ubuntu"); |
---|
242 | |
---|
243 | my $cmd1 = pb_check_req("mkdir",0); |
---|
244 | my $cmd2 = pb_check_req("debootstrap",0); |
---|
245 | pb_system("$sudocmd $cmd1 -p $root/$pbos->{name}/$pbos->{version}/$pbos->{arch} ; $sudocmd $cmd2 $dbsverb $rbsopt --arch=$debarch $addpkgs $codename \"$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}\" $debmir","Creating the debootstrap VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose"); |
---|
246 | # debootstrap doesn't create an /etc/hosts file |
---|
247 | if (! -f "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/etc/hosts" ) { |
---|
248 | my $cmd = pb_check_req("cp",0); |
---|
249 | pb_system("$sudocmd $cmd /etc/hosts $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/etc/hosts"); |
---|
250 | } |
---|
251 | } else { |
---|
252 | die "Unknown vedebtype type $vedebstyle. Report to dev team"; |
---|
253 | } |
---|
254 | } elsif ($pbos->{'type'} eq "ebuild") { |
---|
255 | die "Please teach the dev team how to build gentoo chroot"; |
---|
256 | } else { |
---|
257 | die "Unknown distribution type $pbos->{'type'}. Report to dev team"; |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | # Test if an existing snapshot exists and use it if appropriate |
---|
262 | # And also use it if no local extracted VE is present |
---|
263 | if ((-f "$root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz") && |
---|
264 | (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) || |
---|
265 | ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i))) && |
---|
266 | ($locsnap eq 1) && |
---|
267 | ($vetype ne "docker") && |
---|
268 | (! -d "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}")) { |
---|
269 | my $cmd1 = pb_check_req("rm",0); |
---|
270 | my $cmd2 = pb_check_req("mkdir",0); |
---|
271 | my $cmd3 = pb_check_req("tar",0); |
---|
272 | pb_system("$sudocmd $cmd1 -rf $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} ; $sudocmd $cmd2 -p $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} ; $sudocmd $cmd3 xz -C $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} -f $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz","Extracting snapshot of $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz under $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}"); |
---|
273 | } |
---|
274 | |
---|
275 | if ($vetype ne "docker") { |
---|
276 | # Fix modes to allow access to the VE for pb user |
---|
277 | my $command = pb_check_req("chmod",0); |
---|
278 | pb_system("$sudocmd $command 755 $root/$pbos->{'name'} $root/$pbos->{'name'}/$pbos->{'version'} $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}","Fixing permissions"); |
---|
279 | } |
---|
280 | |
---|
281 | # If docker, create the image and remove the now temp dir except if we had one already |
---|
282 | if (($vetype eq "docker") && ($pbforce == 0)) { |
---|
283 | my $cmd1 = pb_check_req("docker",0); |
---|
284 | # step 0 : nothing at creation -> tag n-v-a (made below) |
---|
285 | |
---|
286 | if ((not defined $pbimage) || ($pbimage eq "")) { |
---|
287 | # Snaphot the VE to serve as an input for docker |
---|
288 | pb_ve_snap($pbos,$root); |
---|
289 | # Create the docker image from the previous bootstrap |
---|
290 | # Need sudo to be able to create all files correctly |
---|
291 | # TODO: check before that the image doesn't already exist in the docker registry |
---|
292 | |
---|
293 | my $pbimage = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"; |
---|
294 | pb_system("$sudocmd $cmd1 import - $pbimage < $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz"); |
---|
295 | pb_system("$cmd1 push $pbimage"); |
---|
296 | } else { |
---|
297 | # If we pass a parameter to -i, this is the name of an existing upstream image for that distro-ver-arch |
---|
298 | # That container should then be setup correctly which may not be the case yet |
---|
299 | # |
---|
300 | # We can probably only get those params now we have the distro context |
---|
301 | my ($osmindep) = pb_conf_get_if("osmindep"); |
---|
302 | my $pkgs = pb_distro_get_param($pbos,$osmindep); |
---|
303 | $pkgs =~ s/,/ /g; |
---|
304 | my $tmpd = "$ENV{'PBTMP'}/Dockerfile"; |
---|
305 | open(DOCKER, "> $tmpd") || die "Unable to create the docker file $tmpd"; |
---|
306 | print DOCKER "FROM $pbimage\n"; |
---|
307 | print DOCKER "MAINTAINER project-builder.org aka pb\n"; |
---|
308 | print DIOCKER "ENV ftp_proxy $ENV{ftp_proxy}\n" if (defined $ENV{ftp_proxy}); |
---|
309 | print DIOCKER "ENV http_proxy $ENV{http_proxy}\n" if (defined $ENV{http_proxy}); |
---|
310 | # We are root in that container so no need to sudo, which is present potentially |
---|
311 | my $cmd2 = $pbos->{'install'}; |
---|
312 | $cmd2 =~ s/sudo //g; |
---|
313 | print DOCKER "RUN $cmd2 $pkgs\n"; |
---|
314 | close(DOCKER); |
---|
315 | pb_system("cd $ENV{'PBTMP'} ; $sudocmd $cmd1 build -t $docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} .","Installing dependencies $pkgs in Docker container $docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"); |
---|
316 | unlink($tmpd); |
---|
317 | } |
---|
318 | } |
---|
319 | |
---|
320 | # Nothing more to do for VE. No real launch |
---|
321 | } else { |
---|
322 | die "VE of type $vetype not supported. Report to the dev team"; |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | # |
---|
327 | # Return the postinstall line if needed |
---|
328 | # |
---|
329 | |
---|
330 | sub pb_ve_get_postinstall { |
---|
331 | |
---|
332 | my $pbos = shift; |
---|
333 | my $rbspi = shift; |
---|
334 | my $vestyle = shift; |
---|
335 | my $post = ""; |
---|
336 | |
---|
337 | # Do we have a local post-install script |
---|
338 | if ($vestyle eq "rinse") { |
---|
339 | $post = "--post-install "; |
---|
340 | } elsif ($vestyle eq "rpmbootstrap") { |
---|
341 | $post = "-s "; |
---|
342 | } |
---|
343 | |
---|
344 | my $postparam = pb_distro_get_param($pbos,$rbspi); |
---|
345 | if ($postparam eq "") { |
---|
346 | $post = ""; |
---|
347 | } else { |
---|
348 | $post .= $postparam; |
---|
349 | } |
---|
350 | return($post); |
---|
351 | } |
---|
352 | |
---|
353 | # Snapshot the VE |
---|
354 | sub pb_ve_snap { |
---|
355 | |
---|
356 | my $pbos = shift; |
---|
357 | my $root = shift; |
---|
358 | my $tpdir = "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}"; |
---|
359 | pb_system("sudo tar cz -C $tpdir -f $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz .","Creating a snapshot of $tpdir"); |
---|
360 | } |
---|
361 | |
---|
362 | # Returns the docker registry to interact with |
---|
363 | sub pb_ve_docker_registry { |
---|
364 | |
---|
365 | my $dockerreg = shift; |
---|
366 | my $wget = pb_check_req("wget",0); |
---|
367 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($dockerreg); |
---|
368 | my $docreg = $scheme."://"; |
---|
369 | $docreg .= $account."@" if ((defined $account) && ($account ne "")); |
---|
370 | $docreg .= $host; |
---|
371 | $docreg .= ":$port" if ((defined $port) && ($port ne "")); |
---|
372 | open(FD,"$wget $docreg -q -O -|") || die "Unable to talk to the docker registry $docreg"; |
---|
373 | my $found = undef; |
---|
374 | while (<FD>) { |
---|
375 | $found = 1 if (/docker-registry/); |
---|
376 | } |
---|
377 | close(FD); |
---|
378 | die "No correct docker-registry answering at $docreg. Please check your configuration" if (not defined $found); |
---|
379 | # |
---|
380 | return($docreg); |
---|
381 | } |
---|
382 | |
---|
383 | sub pb_ve_docker_get_image { |
---|
384 | |
---|
385 | my $pbimage = shift; |
---|
386 | my $found = 0; |
---|
387 | |
---|
388 | die "Unable to handle an undef docker image" if (not defined $pbimage); |
---|
389 | |
---|
390 | # Check that this docker image exists |
---|
391 | my $cmd1 = pb_check_req("docker",0); |
---|
392 | open(CMD, "$cmd1 images |") || die "Unable to get docker image list"; |
---|
393 | my ($repo, $tag, $id, $dummy); |
---|
394 | while (<CMD>) { |
---|
395 | ($repo, $tag, $id, $dummy) = split(/\s+/,$_,4); |
---|
396 | $found = $id if ("$repo:$tag" eq $pbimage); |
---|
397 | } |
---|
398 | close(CMD); |
---|
399 | return($found); |
---|
400 | } |
---|
401 | |
---|
402 | sub pb_ve_get_type { |
---|
403 | |
---|
404 | my $vetype = shift; |
---|
405 | |
---|
406 | # Get VE context |
---|
407 | if (not defined $vetype) { |
---|
408 | my ($ptr) = pb_conf_get("vetype"); |
---|
409 | $vetype = $ptr->{$ENV{'PBPROJ'}}; |
---|
410 | } |
---|
411 | confess "No vetype defined for $ENV{PBPROJ}" unless (defined $vetype); |
---|
412 | pb_log(1, "Using vetype $vetype for $ENV{PBPROJ}\n"); |
---|
413 | return($vetype); |
---|
414 | } |
---|
415 | |
---|
416 | # Returns the docker repository to interact with |
---|
417 | sub pb_ve_docker_repo { |
---|
418 | |
---|
419 | my $docrepo = ""; |
---|
420 | # Check acces to registry |
---|
421 | my ($dockerregistry) = pb_conf_get_if("dockerregistry"); |
---|
422 | if ((defined $dockerregistry) && (defined $dockerregistry->{$ENV{'PBPROJ'}})) { |
---|
423 | pb_ve_docker_registry($dockerregistry->{$ENV{'PBPROJ'}}); |
---|
424 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($dockerregistry->{$ENV{'PBPROJ'}}).":"; |
---|
425 | $docrepo .= $host; |
---|
426 | $docrepo .= ":$port" if ((defined $port) && ($port ne "")); |
---|
427 | $docrepo .= "$path"; |
---|
428 | } else { |
---|
429 | my ($dockerrepository) = pb_conf_get("dockerrepository"); |
---|
430 | $docrepo = $dockerrepository->{$ENV{'PBPROJ'}}.":"; |
---|
431 | } |
---|
432 | pb_log(1,"Using Docker Repository $docrepo\n"); |
---|
433 | return($docrepo); |
---|
434 | } |
---|
435 | |
---|
436 | |
---|
437 | =head1 WEB SITES |
---|
438 | |
---|
439 | The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>. |
---|
440 | |
---|
441 | =head1 USER MAILING LIST |
---|
442 | |
---|
443 | None exists for the moment. |
---|
444 | |
---|
445 | =head1 AUTHORS |
---|
446 | |
---|
447 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>. |
---|
448 | |
---|
449 | =head1 COPYRIGHT |
---|
450 | |
---|
451 | Project-Builder.org is distributed under the GPL v2.0 license |
---|
452 | described in the file C<COPYING> included with the distribution. |
---|
453 | |
---|
454 | =cut |
---|
455 | |
---|
456 | |
---|
457 | 1; |
---|