Changeset 1903 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/VE.pm
- Timestamp:
- Oct 8, 2014, 1:35:10 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/lib/ProjectBuilder/VE.pm
r1902 r1903 16 16 use Carp 'confess'; 17 17 use English; 18 use File::Basename; 18 19 use ProjectBuilder::Version; 19 20 use ProjectBuilder::Base; … … 31 32 32 33 our @ISA = qw(Exporter); 33 our @EXPORT = qw(pb_ve_launch pb_ve_snap );34 our @EXPORT = qw(pb_ve_launch pb_ve_snap pb_ve_get_type pb_ve_docker_repo pb_ve_docker_get_image); 34 35 35 36 ($VERSION,$REVISION) = pb_version_init(); … … 66 67 sub pb_ve_launch { 67 68 68 my $v = shift || undef; 69 my $pbforce = shift || 0; # By default do not rebuild VE 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 69 my $v = shift; 70 my $pbscript = shift; 71 my $pbforce = shift; 72 my $pbstep= shift; # Which step are we in (0: create, 1: setup, 2: build, 3: use) 73 my $locsnap = shift; 74 my $vetype = shift; 75 my $pbimage = shift; 73 76 74 77 my $dockerregistry = undef; 75 78 my $docrepo = undef; # By default no repository for docker available 76 79 80 pb_log(2,"Entering pb_ve_launch at step $pbstep\n"); 77 81 # Get distro context 78 82 my $pbos = pb_distro_get_context($v); 79 83 80 # Get VE context 81 if (not defined $vetype) { 82 my ($ptr) = pb_conf_get("vetype"); 83 $vetype = $ptr->{$ENV{'PBPROJ'}}; 84 } 85 confess "No vetype defined for $ENV{PBPROJ}" unless (defined $vetype); 86 pb_log(1, "Using vetype $vetype for $ENV{PBPROJ}\n"); 84 $vetype = pb_ve_get_type($vetype); 87 85 my ($vepath) = pb_conf_get("vepath"); 88 86 … … 114 112 if ($EFFECTIVE_USER_ID != 0) { 115 113 $sudocmd ="sudo "; 116 foreach my $proxy (qw/http_proxy ftp_proxy/) {114 foreach my $proxy (qw/http_proxy ftp_proxy/) { 117 115 if (defined $ENV{$proxy}) { 118 116 open(CMD,"sudo sh -c 'echo \$$proxy' |") or die "can't run sudo sh?: $!"; … … 132 130 if (((((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) && ($vetype ne "docker")) 133 131 # For docker we may have a reference image that we'll use 134 || (( (not defined $pbimage) || ($pbimage eq "")) && ($vetype eq "docker"))) {132 || (($vetype eq "docker") && ($pbstep == 0))) { 135 133 136 134 my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype"); … … 275 273 ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i))) && 276 274 ($locsnap eq 1) && 275 ($vetype ne "docker") && 277 276 (! -d "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}")) { 278 277 my $cmd1 = pb_check_req("rm",0); … … 281 280 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'}"); 282 281 } 283 284 # Fix modes to allow access to the VE for pb user 285 my $command = pb_check_req("chmod",0); 286 pb_system("$sudocmd $command 755 $root/$pbos->{'name'} $root/$pbos->{'name'}/$pbos->{'version'} $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}","Fixing permissions"); 282 283 if ($vetype ne "docker") { 284 # Fix modes to allow access to the VE for pb user 285 my $command = pb_check_req("chmod",0); 286 pb_system("$sudocmd $command 755 $root/$pbos->{'name'} $root/$pbos->{'name'}/$pbos->{'version'} $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}","Fixing permissions"); 287 } 287 288 288 289 # 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 # Need sudo to be able to create all files correctly 297 pb_system("$sudocmd $cmd1 import - $docrepo:$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} < $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz"); 298 pb_system("$cmd1 push $docrepo:$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"); 299 #} else { 300 } 290 if (($vetype eq "docker") && ($pbstep == 0)) { 291 $docrepo = pb_ve_docker_repo($dockerregistry->{$ENV{'PBPROJ'}}); 292 my $cmd1 = pb_check_req("docker",0); 293 # step 0 : nothing at creation -> tag n-v-a (made below) 294 295 # Snaphot the VE to serve as an input for docker 296 pb_ve_snap($pbos,$root); 297 # Create the docker image from the previous bootstrap 298 # Need sudo to be able to create all files correctly 299 # TODO: check before that the image doesn't already exist in the docker registry 300 my $pbimage = "$docrepo:$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"; 301 pb_system("$sudocmd $cmd1 import - $pbimage < $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz"); 302 pb_system("$cmd1 push $pbimage"); 301 303 } 302 304 … … 376 378 } 377 379 380 sub pb_ve_docker_get_image { 381 382 my $pbimage = shift || undef; 383 my $found = 0; 384 385 die "Unable to handle an undef docker image" if (not defined $pbimage); 386 387 # Check that this docker image exists 388 my $cmd1 = pb_check_req("docker",0); 389 open(CMD, "$cmd1 images |") || die "Unable to get docker image list"; 390 my ($repo, $tag, $id, $dummy); 391 while (<CMD>) { 392 ($repo, $tag, $id, $dummy) = split(/\s+/,$_,4); 393 $found = $id if ("$repo:$tag" eq $pbimage); 394 } 395 close(CMD); 396 return($found); 397 } 398 sub pb_ve_get_type { 399 400 my $vetype = shift || undef; 401 402 # Get VE context 403 if (not defined $vetype) { 404 my ($ptr) = pb_conf_get("vetype"); 405 $vetype = $ptr->{$ENV{'PBPROJ'}}; 406 } 407 confess "No vetype defined for $ENV{PBPROJ}" unless (defined $vetype); 408 pb_log(1, "Using vetype $vetype for $ENV{PBPROJ}\n"); 409 return($vetype); 410 } 411 412 378 413 =head1 WEB SITES 379 414
Note:
See TracChangeset
for help on using the changeset viewer.