Changeset 2436 in ProjectBuilder


Ignore:
Timestamp:
Sep 6, 2019, 3:37:09 PM (5 years ago)
Author:
Bruno Cornec
Message:

force explicit analysis of boolean and when using cluck and more fixes to pb_all_docker

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r2429 r2436  
    19691969            my $keyfile = pb_ssh_get(1);
    19701970            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);
    19721972            print CONF "PACKAGER_PRIVKEY=\"$keyfile\"\n" if (defined $keyfile);
    19731973            close(CONF);
     
    26022602    # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
    26032603    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);
    26052605    } else {
    26062606        # process, ok if not present.
     
    26922692                #$shcmd = "$cmd1 build $dockeropt->{$ENV{'PBPROJ'}} -t $tag{$pbstep+1} $context";
    26932693            } else {
     2694                my $rmatend = "";
    26942695                # 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);
    26962697                $shcmd = "$cmd1 run $rmatend --cidfile=\"$cidfile\" --user $dkaccount --name $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}-$cmt";
    26972698            }
     
    28842885        }
    28852886        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);
    28872888        print DOCKER "#!/bin/bash\n";
    28882889        print DOCKER "# Put content from host to guest, copying to have the correct uid/gid and rights to do so\n";
     
    43084309# Build all docker CTN required to build an app
    43094310sub 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
     4312my $action = shift;
     4313my $savproj = $ENV{'PBPROJ'};
     4314my $pkg;
     4315my @pkg;
     4316if ($#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
     4325my ($vm,$all);
     4326if (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
     4335pb_log(2,"DEBUG: pb_all_docker(action: $action)\n");
     4336my $docrepo = pb_ve_docker_repo();
     4337
     4338my ($vexist,$vpid) = (undef,undef);
     4339my $pm;
     4340my $all_ok = 1;
     4341if (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
     4353my $counter = 0;
     4354foreach 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") {
    43804383            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);
     4413confess "Aborting, one or more of the children failed." if ((not $all_ok) && ($Global::pb_stop_on_error));
    43844414}
    43854415
     
    49935023my $bdir;
    49945024
    4995 opendir($bdir,"$dir") || cluck "Unable to open directory $dir: $!" && return;
     5025opendir($bdir,"$dir") || (cluck "Unable to open directory $dir: $!" && return);
    49965026foreach my $f (readdir($bdir)) {
    49975027    next if ($f =~ /^\./);
     
    52665296        cluck("No pbpassphrase nor pbpassfile defined, unable to handle GPG Release file\n");
    52675297    } 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);
    52695299        my $pass = <PASS>;
    52705300        chomp($pass);
Note: See TracChangeset for help on using the changeset viewer.