Changeset 1900 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/VE.pm
- Timestamp:
- Sep 30, 2014, 10:08:03 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/lib/ProjectBuilder/VE.pm
r1646 r1900 31 31 32 32 our @ISA = qw(Exporter); 33 our @EXPORT = qw(pb_ve_launch );33 our @EXPORT = qw(pb_ve_launch pb_ve_snap); 34 34 35 35 ($VERSION,$REVISION) = pb_version_init(); … … 43 43 =head1 DESCRIPTION 44 44 45 This modules provides functions to deal with Virtual Environements (VE), aka chroot .45 This modules provides functions to deal with Virtual Environements (VE), aka chroot/containers. 46 46 47 47 =head1 SYNOPSIS … … 60 60 =item B<pb_ve_launch> 61 61 62 This function launch a VE, creating it if necessary using multiple external potential tools.62 This function launches a VE, creating it if necessary using multiple external potential tools. 63 63 64 64 =cut … … 69 69 my $pbforce = shift || 0; # By default do not rebuild VE 70 70 my $locsnap = shift || 0; # By default do not snap VE 71 my $vetype = shift || undef; # By default no image 72 my $pbimage = shift || undef; # By default no image 73 74 my $dockerregistry = undef; 75 my $docrepo = undef; # By default no repository for docker available 71 76 72 77 # Get distro context … … 74 79 75 80 # Get VE context 76 my ($ptr,$vepath) = pb_conf_get("vetype","vepath"); 77 my $vetype = $ptr->{$ENV{'PBPROJ'}}; 78 81 if (not defined $vetype) { 82 my ($ptr) = pb_conf_get("vetype"); 83 $vetype = $ptr->{$ENV{'PBPROJ'}}; 84 } 79 85 confess "No vetype defined for $ENV{PBPROJ}" unless (defined $vetype); 80 86 pb_log(1, "Using vetype $vetype for $ENV{PBPROJ}\n"); 81 82 if (($vetype eq "chroot") || ($vetype eq "schroot")) { 87 my ($vepath) = pb_conf_get("vepath"); 88 89 if (($vetype eq "chroot") || ($vetype eq "schroot") || ($vetype eq "docker")) { 83 90 84 91 # We need to avoid umask propagation to the VE … … 87 94 # We can probably only get those params now we have the distro context 88 95 my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv"); 96 if ($vetype eq "docker") { 97 # Check acces to registry 98 ($dockerregistry) = pb_conf_get("dockerregistry"); 99 if ((defined $dockerregistry) && (defined $dockerregistry->{$ENV{'PBPROJ'}})) { 100 pb_ve_docker_registry($dockerregistry->{$ENV{'PBPROJ'}}); 101 } else { 102 die "When using docker you need to declare a dockerregistry parameter. Read the man page" 103 } 104 } 89 105 90 106 # Architecture consistency … … 98 114 if ($EFFECTIVE_USER_ID != 0) { 99 115 $sudocmd ="sudo "; 100 116 foreach my $proxy (qw/http_proxy ftp_proxy/) { 101 117 if (defined $ENV{$proxy}) { 102 118 open(CMD,"sudo sh -c 'echo \$$proxy' |") or die "can't run sudo sh?: $!"; … … 113 129 114 130 my $root = pb_path_expand($vepath->{$ENV{PBPROJ}}); 115 if (((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) { 131 132 if (((((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) && ($vetype ne "docker")) 133 # For docker we may have a reference image that we'll use 134 || (((not defined $pbimage) || ($pbimage eq "")) && ($vetype eq "docker"))) { 135 116 136 my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype"); 117 137 my ($rbsopt1) = pb_conf_get_if("rbsopt"); … … 250 270 251 271 # Test if an existing snapshot exists and use it if appropriate 252 # And also use it of no local extracted VE is present272 # And also use it if no local extracted VE is present 253 273 if ((-f "$root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz") && 254 274 (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) || … … 266 286 pb_system("$sudocmd $command 755 $root/$pbos->{'name'} $root/$pbos->{'name'}/$pbos->{'version'} $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}","Fixing permissions"); 267 287 288 # If docker, create the image and remove the now temp dir except if we had one already 289 if ($vetype eq "docker") { 290 if ((not defined $pbimage) || ($pbimage eq "")) { 291 # Snaphot the VE to serve as an input for docker 292 pb_ve_snap($pbos,$root); 293 # Create the docker image from the previous bootstrap 294 my $cmd1 = pb_check_req("docker",0); 295 $docrepo = pb_ve_docker_repo($dockerregistry->{$ENV{'PBPROJ'}}); 296 pb_system("$cmd1 import - $docrepo:$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} < $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz"); 297 pb_system("$cmd1 push $docrepo:$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"); 298 #} else { 299 } 300 } 301 268 302 # Nothing more to do for VE. No real launch 269 303 } else { … … 299 333 } 300 334 335 # Snapshot the VE 336 sub pb_ve_snap { 337 338 my $pbos = shift; 339 my $root = shift; 340 my $tpdir = "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}"; 341 pb_system("sudo tar cz -C $tpdir -f $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz .","Creating a snapshot of $tpdir"); 342 } 343 344 # Returns the docker registry to interact with 345 sub pb_ve_docker_registry { 346 347 my $dockerreg = shift || undef; 348 my $wget = pb_check_req("wget",0); 349 my ($scheme, $account, $host, $port, $path) = pb_get_uri($dockerreg); 350 my $docreg = $scheme."://"; 351 $docreg .= $account."@" if ((defined $account) && ($account ne "")); 352 $docreg .= $host; 353 $docreg .= ":$port" if ((defined $port) && ($port ne "")); 354 open(FD,"$wget $docreg -q -O -|") || die "Unable to talk to the docker registry $docreg"; 355 my $found = undef; 356 while (<FD>) { 357 $found = 1 if (/docker-registry/); 358 } 359 close(FD); 360 die "No correct docker-registry answering at $docreg. Please check your configuration" if (not defined $found); 361 # 362 return($docreg); 363 } 364 365 # Returns the docker repository to interact with 366 sub pb_ve_docker_repo { 367 368 my $dockerreg = shift || undef; 369 my $docrepo = ""; 370 my ($scheme, $account, $host, $port, $path) = pb_get_uri($dockerreg); 371 $docrepo .= $host; 372 $docrepo .= ":$port" if ((defined $port) && ($port ne "")); 373 $docrepo .= "$path"; 374 return($docrepo); 375 } 301 376 302 377 =head1 WEB SITES
Note:
See TracChangeset
for help on using the changeset viewer.