- Timestamp:
- Sep 6, 2019, 3:37:09 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb
r2429 r2436 1969 1969 my $keyfile = pb_ssh_get(1); 1970 1970 pb_mkdir_p("$ENV{'HOME'}/.abuild"); 1971 open(CONF,"> $ENV{'HOME'}/.abuild/abuild.conf") || cluck "Unable to create the abuild conf file" && next;1971 open(CONF,"> $ENV{'HOME'}/.abuild/abuild.conf") || (cluck "Unable to create the abuild conf file" && next); 1972 1972 print CONF "PACKAGER_PRIVKEY=\"$keyfile\"\n" if (defined $keyfile); 1973 1973 close(CONF); … … 2602 2602 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home 2603 2603 if ($cmt =~ /^VE/o) { 2604 $tdir =~ s|\$ENV.+\}/|| or cluck "for $cmt: $tdir must have \$ENV{'HOME'} in it or the remainder of the code won't work since some parts use relative pathing and others will try absolute. Use a symlink if necessary to place the real files in a different place than under your home directory" && return;2604 $tdir =~ s|\$ENV.+\}/|| or (cluck "for $cmt: $tdir must have \$ENV{'HOME'} in it or the remainder of the code won't work since some parts use relative pathing and others will try absolute. Use a symlink if necessary to place the real files in a different place than under your home directory" && return); 2605 2605 } else { 2606 2606 # process, ok if not present. … … 2692 2692 #$shcmd = "$cmd1 build $dockeropt->{$ENV{'PBPROJ'}} -t $tag{$pbstep+1} $context"; 2693 2693 } else { 2694 my $rmatend = ""; 2694 2695 # As we are in run phase use docker run. cmd will be completed below 2695 my$rmatend = "--rm" if ($pbdebug lt 1);2696 $rmatend = "--rm" if ($pbdebug lt 1); 2696 2697 $shcmd = "$cmd1 run $rmatend --cidfile=\"$cidfile\" --user $dkaccount --name $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}-$cmt"; 2697 2698 } … … 2884 2885 } 2885 2886 my $ts = "$ENV{'PBTMP'}/vebuild/".basename($pbscript2); 2886 open(DOCKER," > $ts") || cluck "Unable to create $ts" && return;2887 open(DOCKER," > $ts") || (cluck "Unable to create $ts" && return); 2887 2888 print DOCKER "#!/bin/bash\n"; 2888 2889 print DOCKER "# Put content from host to guest, copying to have the correct uid/gid and rights to do so\n"; … … 4308 4309 # Build all docker CTN required to build an app 4309 4310 sub pb_all_docker { 4310 my $action = shift; 4311 my $savproj = $ENV{'PBPROJ'}; 4312 my $pkg; 4313 my @pkg; 4314 if ($#ARGV == -1) { 4315 $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir); 4316 @pkgs = @$pkg; 4317 } else { 4318 @pkgs = @ARGV; 4319 } 4320 #pb_log(1,"Packages to print:".Dumper(@pkgs)."\n"); 4321 4322 # Get the list of all VE we need to work on 4323 my ($vm,$all); 4324 if (not defined $ENV{'PBV'}) { 4325 ($vm,$all) = pb_get2v("ve"); 4326 } else { 4327 @$vm = split(/,/,$ENV{'PBV'}); 4328 } 4329 4330 my $docrepo = pb_ve_docker_repo(); 4331 # TODO: parallelize 4332 foreach my $v (@$vm) { 4333 my $done = 0; 4334 my $lmsg = ""; 4335 my $lctn = ""; 4336 my $pbos = pb_distro_get_context($v); 4337 # Docker images are (for now !) regular and use distro:ver 4338 $pbimage = "$pbos->{'name'}".":$pbos->{'version'}"; 4339 # The two first steps need to be done with the pb project and using a stable pb version 4340 $ENV{'PBPROJ'} = $appname; 4341 $lctn = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"; 4342 my $found = pb_ve_docker_get_image($lctn); 4343 if (($pbforce == 1) || (not defined $found)) { 4344 # pb -p pb -m distro-ver-arch newve -i distro:ver 4345 ($pbforce == 1) ? $lmsg = "Forced" : $lmsg = "not found"; 4346 pb_log(0,"Docker container $lctn $lmsg, creating it\n"); 4347 pb_parallel_launchv(undef,"ve",undef,0,$pbimage); 4348 } 4349 $lctn = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}-pb"; 4350 $found = pb_ve_docker_get_image($lctn); 4351 if (($pbforce == 1) || (not defined $found)) { 4352 ($pbforce == 1) ? $lmsg = "Forced" : $lmsg = "not found"; 4353 pb_log(0,"Docker container $lctn $lmsg, creating it\n"); 4354 # pb -p pb -m distro-ver-arch setupve 4355 if ($savproj eq "pb") { 4356 pb_cms2build("SandBox") if ($action !~ /sbx2/); 4357 $done = 1; 4358 pb_setup2v("ve","SandBox"); 4359 } else { 4360 # Here we install in the CTN pb from upstream packages to have a stable version 4361 pb_setup2v("ve",undef,"pkg"); 4362 } 4363 } 4364 # Now back to our original project 4365 $ENV{'PBPROJ'} = $savproj; 4366 $lctn = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}-pb-$ENV{'PBPROJ'}"; 4367 $found = pb_ve_docker_get_image($lctn); 4368 if (($pbforce == 1) || (not defined $found)) { 4369 ($pbforce == 1) ? $lmsg = "Forced" : $lmsg = "not found"; 4370 pb_log(0,"Docker container $lctn $lmsg, creating it\n"); 4371 # pb -p pb -m distro-ver-arch prepve 4372 if ($savproj eq "pb") { 4373 pb_cms2build("SandBox") if ($action !~ /sbx2/); 4374 $done = 1; 4375 } 4376 pb_build2v("ve","prep"); 4377 } 4378 pb_log(0,"Instantiating a Docker container from $lctn\n"); 4379 if (($savproj ne "pb") || ($done == 0)) { 4311 4312 my $action = shift; 4313 my $savproj = $ENV{'PBPROJ'}; 4314 my $pkg; 4315 my @pkg; 4316 if ($#ARGV == -1) { 4317 $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir); 4318 @pkgs = @$pkg; 4319 } else { 4320 @pkgs = @ARGV; 4321 } 4322 #pb_log(1,"Packages to print:".Dumper(@pkgs)."\n"); 4323 4324 # Get the list of all VE we need to work on 4325 my ($vm,$all); 4326 if (not defined $ENV{'PBV'}) { 4327 ($vm,$all) = pb_get2v("ve"); 4328 } else { 4329 @$vm = split(/,/,$ENV{'PBV'}); 4330 } 4331 4332 # Adapt // mode to memory size 4333 $pbparallel = pb_set_parallel("ve"); 4334 4335 pb_log(2,"DEBUG: pb_all_docker(action: $action)\n"); 4336 my $docrepo = pb_ve_docker_repo(); 4337 4338 my ($vexist,$vpid) = (undef,undef); 4339 my $pm; 4340 my $all_ok = 1; 4341 if (defined $pbparallel) { 4342 $pm = new Parallel::ForkManager($pbparallel); 4343 4344 $pm->run_on_finish(sub { my ($pid, $code, $id, $signal, $dump) = @_; 4345 unless ($code == 0 && $signal == 0 && $dump == 0) { 4346 $all_ok = 0; 4347 pb_log(0,"ERROR: pid $pid failed\n"); 4348 pb_log(0,"code: $code - signal: $signal - dump: $dump\n"); 4349 } 4350 }); 4351 } 4352 4353 my $counter = 0; 4354 foreach my $v (@$vm) { 4355 $counter++; 4356 # Modulo 2 * pbparallel (to avoid synchronization problems) 4357 $counter = 1 if ((defined $pbparallel) && ($counter > 2 * $pbparallel)); 4358 $pm->start($counter) and next if (defined $pbparallel); 4359 4360 my $done = 0; 4361 my $lmsg = ""; 4362 my $lctn = ""; 4363 my $pbos = pb_distro_get_context($v); 4364 # Docker images are (for now !) regular and use distro:ver 4365 $pbimage = "$pbos->{'name'}".":$pbos->{'version'}"; 4366 # The two first steps need to be done with the pb project and using a stable pb version 4367 $ENV{'PBPROJ'} = $appname; 4368 $lctn = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"; 4369 my $found = pb_ve_docker_get_image($lctn); 4370 if (($pbforce == 1) || (not defined $found)) { 4371 # pb -p pb -m distro-ver-arch newve -i distro:ver 4372 ($pbforce == 1) ? $lmsg = "Forced" : $lmsg = "not found"; 4373 pb_log(0,"Docker container $lctn $lmsg, creating it\n"); 4374 pb_launchv(undef,"ve",$v,$action,0,$pbforce,undef,undef,$pbimage); 4375 } 4376 $lctn = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}-pb"; 4377 $found = pb_ve_docker_get_image($lctn); 4378 if (($pbforce == 1) || (not defined $found)) { 4379 ($pbforce == 1) ? $lmsg = "Forced" : $lmsg = "not found"; 4380 pb_log(0,"Docker container $lctn $lmsg, creating it\n"); 4381 # pb -p pb -m distro-ver-arch setupve 4382 if ($savproj eq "pb") { 4380 4383 pb_cms2build("SandBox") if ($action !~ /sbx2/); 4381 } 4382 pb_build2v("ve","build"); 4383 } 4384 $done = 1; 4385 pb_setup2v("ve","SandBox"); 4386 } else { 4387 # Here we install in the CTN pb from upstream packages to have a stable version 4388 pb_setup2v("ve",undef,"pkg"); 4389 } 4390 } 4391 # Now back to our original project 4392 $ENV{'PBPROJ'} = $savproj; 4393 $lctn = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}-pb-$ENV{'PBPROJ'}"; 4394 $found = pb_ve_docker_get_image($lctn); 4395 if (($pbforce == 1) || (not defined $found)) { 4396 ($pbforce == 1) ? $lmsg = "Forced" : $lmsg = "not found"; 4397 pb_log(0,"Docker container $lctn $lmsg, creating it\n"); 4398 # pb -p pb -m distro-ver-arch prepve 4399 if ($savproj eq "pb") { 4400 pb_cms2build("SandBox") if ($action !~ /sbx2/); 4401 $done = 1; 4402 } 4403 pb_build2v("ve","prep"); 4404 } 4405 pb_log(0,"Instantiating a Docker container from $lctn\n"); 4406 if (($savproj ne "pb") || ($done == 0)) { 4407 pb_cms2build("SandBox") if ($action !~ /sbx2/); 4408 } 4409 pb_build2v("ve","build"); 4410 $pm->finish if (defined $pbparallel); 4411 } 4412 $pm->wait_all_children if (defined $pbparallel); 4413 confess "Aborting, one or more of the children failed." if ((not $all_ok) && ($Global::pb_stop_on_error)); 4384 4414 } 4385 4415 … … 4993 5023 my $bdir; 4994 5024 4995 opendir($bdir,"$dir") || cluck "Unable to open directory $dir: $!" && return;5025 opendir($bdir,"$dir") || (cluck "Unable to open directory $dir: $!" && return); 4996 5026 foreach my $f (readdir($bdir)) { 4997 5027 next if ($f =~ /^\./); … … 5266 5296 cluck("No pbpassphrase nor pbpassfile defined, unable to handle GPG Release file\n"); 5267 5297 } else { 5268 open(PASS,"$ENV{'PBPASSFILE'}") || cluck("Unable to open $ENV{'PBPASSFILE'}\n") && return;5298 open(PASS,"$ENV{'PBPASSFILE'}") || (cluck("Unable to open $ENV{'PBPASSFILE'}\n") && return); 5269 5299 my $pass = <PASS>; 5270 5300 chomp($pass);
Note:
See TracChangeset
for help on using the changeset viewer.