Changeset 1907 in ProjectBuilder for devel/pb/bin/pb


Ignore:
Timestamp:
Oct 10, 2014, 11:32:12 AM (10 years ago)
Author:
Bruno Cornec
Message:
Fix some default initializations (
undef e.g.)
  • VE.pm doesn't need to have pbstep (use pbforce simply)
  • Fix sbx2setupve in a docker context
  • Add entries for prepve|vm|rm
  • Move sandbox management into send2target so that all files to process are managed here
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r1906 r1907  
    252252RM means Remote Machine, and could be a physical or Virtual one.
    253253This is one buildfarm integration for pb.
     254
     255=item B<prepvm>
     256
     257Prepare the VMs to have all requirements to build the project
     258
     259=item B<prepve>
     260
     261Prepare the VEs to have all requirements to build the project
     262
     263=item B<preprm>
     264
     265Prepare the RMs to have all requirements to build the project
    254266
    255267=item B<sbx2vm>
     
    855867} elsif ($action =~ /^build2vm$/) {
    856868    pb_build2v("vm","build");
     869} elsif ($action =~ /^preprm$/) {
     870    pb_build2v("rm","prep");
     871} elsif ($action =~ /^prepve$/) {
     872    pb_build2v("ve","prep");
     873} elsif ($action =~ /^prepvm$/) {
     874    pb_build2v("vm","prep");
    857875} elsif ($action =~ /^cms2rm$/) {
    858876    pb_cms2build("CMS");
     
    10001018sub pb_cms2build {
    10011019
    1002     my $param = shift || undef;
    1003     my $web = shift || undef;
     1020    my $param = shift;
     1021    my $web = shift;
    10041022
    10051023    my $pkg;
     
    15281546    }
    15291547    pb_log(0,"INFO: ------ Finished preparing build environment ------\n");
    1530     open(PKG,">> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to append to $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
    1531     print PKG "pbstep $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} = 2\n";
    1532     close(PKG);
    15331548}
    15341549
     
    15411556    my $pbos = pb_distro_get_context();
    15421557
    1543     # Check whether the preparation phase has already been done or not
    1544     my ($pbstep) = pb_distro_get_param($pbos,pb_conf_read_if("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbstep"));
    1545     pb_build2prep() if ((not defined $pbstep) || ($pbstep < 2));
    1546    
    15471558    # Get list of packages to build
    15481559    my $ptr = pb_get_pkg();
     
    19341945    print KEEP "$made\n";
    19351946    close(KEEP);
    1936     open(PKG,">> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to append to $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
    1937     print PKG "pbstep $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} = 3\n";
    1938     close(PKG);
    19391947    pb_distro_installdeps(undef,$pbos,$ret) if ($do_install);
    1940 }
    1941 
    1942 sub create_solaris_prototype {
    1943 
    1944     my $uidgid = "bin bin";
    1945     my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
    1946 
    1947     return if ($_ =~ /^$pkgdestdir$/);
    1948     if (-d $_) {
    1949         my $n = $File::Find::name;
    1950         $n =~ s~$pkgdestdir/~~;
    1951         print PROTO "d none $n 0755 $uidgid\n";
    1952     } elsif (-x $_) {
    1953         my $n = $File::Find::name;
    1954         $n =~ s~$pkgdestdir/~~;
    1955         print PROTO "f none $n 0755 $uidgid\n";
    1956     } elsif (-f $_) {
    1957         my $n = $File::Find::name;
    1958         $n =~ s~$pkgdestdir/~~;
    1959         print PROTO "f none $n 0644 $uidgid\n";
    1960     }
    19611948}
    19621949
     
    19751962
    19761963    my $cmt = shift;
    1977     my $pbscript = shift || undef;
    1978     my $v = shift || undef;
    1979     my $vexist = shift || 0;            # 0 is FALSE
    1980     my $vpid = shift || 0;              # 0 is FALSE
    1981     my $snapme = shift || 0;            # 0 is FALSE
    1982     my $pbstep = shift || 3;            # 3 is usage of container
    1983 
     1964    my $pbscript = shift;
     1965    my $v = shift;
     1966    my $vexist = shift;         # 0 is FALSE
     1967    my $vpid = shift;           # 0 is FALSE
     1968    my $snapme = shift;         # 0 is FALSE
     1969    my $pbstep = shift;         # 3 is usage of container
     1970
     1971    $vexist = 0 if (not defined $vexist);
     1972    $vpid = 0 if (not defined $vpid);
     1973    $snapme = 0 if (not defined $snapme);
     1974    $pbstep = 3 if (not defined $pbstep);
    19841975    pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vexist,$vpid)\n");
    19851976    my $host = "sshhost";
     
    20852076    }
    20862077
    2087     if ($cmt =~ /(V[EM]|RM)build/) {
     2078    if ($cmt =~ /(V[EM]|RM)(build|prep)/) {
    20882079        $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $pbscript{$v}";
    20892080    } elsif ($cmt =~ /(V[EM]|RM)Script/) {
     
    21612152    } elsif ($cmt eq "CPAN") {
    21622153        $tdir = "$remdir";
    2163     } elsif ($cmt =~ /(V[EM]|RM)(build|test)/) {
     2154    } elsif ($cmt =~ /(V[EM]|RM)(build|test|prep)/) {
    21642155        $tdir = $remdir."/$ENV{'PBPROJ'}/delivery";
    21652156        $bdir = $remdir."/$ENV{'PBPROJ'}/build";
     
    24232414    if ($cmt =~ /^VE/) {
    24242415        $tp = pb_path_expand($vepath->{$ENV{'PBPROJ'}});
     2416        $vetype = pb_ve_get_type($vetype);
    24252417        if ($vetype eq "docker") {
    24262418            $tpdir = "/";
     
    24282420            $tpdir = pb_path_expand("$tp/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
    24292421        }
    2430         $vetype = pb_ve_get_type($vetype);
    24312422        my $arch = pb_get_arch();
    24322423        if ($vetype eq "chroot") {
     
    25612552        $logres = "> ";
    25622553    }
     2554
     2555    if ($cmt =~ /SandBox/) {
     2556        # Install from sandbox mean using the result of the just passed sbx2build command
     2557        # Get content saved in cms2build
     2558        my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
     2559        my $pbextdir = pb_get_extdir();
     2560        confess "Unable to get package list" if (not defined $pkg);
     2561
     2562        # We consider 2 specific packages
     2563        my $vertag1 = $pkg->{"ProjectBuilder"};
     2564        my $vertag2 = $pkg->{"project-builder"};
     2565        # get the version of the current package - maybe different
     2566        pb_log(2,"Vertag1: $vertag1\n");
     2567        pb_log(2,"Vertag2: $vertag2\n");
     2568        my ($pbver1,$tmp1) = split(/-/,$vertag1);
     2569        my ($pbver2,$tmp2) = split(/-/,$vertag2);
     2570        if ($cmt =~ /VE/) {
     2571            # Copy inside the VE
     2572            if ($vetype ne "docker") {
     2573                copy("$ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz","$tpdir/tmp");
     2574                copy("$ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz","$tpdir/tmp");
     2575            } else {
     2576                copy("$ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz","$context");
     2577                copy("$ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz","$context");
     2578                print DOCKER "COPY ProjectBuilder-$pbver1$pbextdir.tar.gz /tmp/\n";
     2579                print DOCKER "COPY project-builder-$pbver2$pbextdir.tar.gz /tmp/\n";
     2580            }
     2581        } else {
     2582            pb_system("$cpcmd $ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz $ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz $mac:/tmp","Copying local project files to $vetype.");
     2583        }
     2584    }
     2585           
    25632586    # For docker everything is done in the Dockerfile
    25642587    if (($cmt =~ /^VE/) && ($vetype eq "docker") && ($pbstep < 3)) {
     
    25802603            pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
    25812604        } else {
    2582             print DOCKER "RUN sed -i '/requiretty/d' /etc/sudoers" if ($pbstep == 1);
     2605            print DOCKER "RUN sed -i '/requiretty/d' /etc/sudoers\n" if ($pbstep == 1);
    25832606        }
    25842607    }
     
    26152638    }
    26162639    # this is where we lanch the execution
    2617     pb_system("$shcmd","Executing pbscript on $cptarget if needed",$cmdverb);
     2640    my $ret = pb_system("$shcmd","Executing pbscript on $cptarget if needed",$cmdverb);
    26182641
    26192642    if ($cmt =~ /^(V[EM]|RM)build/) {
     
    27002723    }
    27012724    if (($cmt =~ /^VE/) && ($snapme != 0)) {
    2702         pb_ve_snap($pbos,$tp);
    27032725        if ($vetype eq "docker") {
    27042726            foreach my $f (split(/ +/,$src)) {
    27052727                unlink("$context/$f");
    27062728            }
     2729        } else {
     2730            pb_ve_snap($pbos,$tp);
    27072731        }
    27082732    }
     
    27142738my $vtype=shift;
    27152739my $pbstep=shift;   # Which step are we in (0: create, 1: setup pb, 2: prep pbproj, 3: use to build)
    2716 my $pbforce=shift || 0; # Force stop of VM. Default not.
    2717 my $snapme=shift || 0;  # Do we have to create a snapshot. Default not.
    2718 my $pbimage=shift || undef; # Which image to use to start the VM/VE
    2719 my $vm;
    2720 my $all;
     2740my $pbforce=shift;  # Force stop of VM. Default not.
     2741my $snapme=shift;   # Do we have to create a snapshot. Default not.
     2742my $pbimage=shift;  # Which image to use to start the VM/VE
     2743
     2744$pbforce = 0 if (not defined $pbforce);
     2745$snapme = 0 if (not defined $snapme);
    27212746
    27222747pb_log(2,"DEBUG: pb_script2v($vtype,$pbstep,$pbforce,$snapme)\n");
     
    27292754my $pbscript=shift;
    27302755my $vtype = shift;
    2731 my $action = shift;             # It an action is defined then use send2target
     2756my $action = shift;         # It an action is defined then use send2target
    27322757my $pbstep=shift;           # Which step are we in (0: create, 1: setup, 2: build 3: use)
    2733 my $pbforce=shift || 0;         # Force stop of VM. Default not.
    2734 my $snapme = shift || 0;        # By default do not snap a VM/VE/RM
    2735 my $usesnap = shift || 1;       # By default study the usage of the snapshot feature of VM/VE/RM   
    2736 my $pbimage=shift || undef;     # Which image to use to start the VM/VE
     2758my $pbforce=shift;          # Force stop of VM. Default not.
     2759my $snapme = shift;         # By default do not snap a VM/VE/RM
     2760my $usesnap = shift;        # By default study the usage of the snapshot feature of VM/VE/RM   
     2761my $pbimage=shift        # Which image to use to start the VM/VE
    27372762my $vm;
    27382763my $all;
     2764
     2765$pbforce = 0 if (not defined $pbforce);
     2766$snapme = 0 if (not defined $snapme);
     2767$usesnap = 1 if (not defined $usesnap);
    27392768
    27402769# Adapt // mode to memory size
     
    27772806    my $pbscript = $pbscript->{$v} if (defined $pbscript->{$v});
    27782807    $pbscript = $pbscript->{'default'} if (not defined $pbscript);
    2779     confess "No script defined so unable to launch it in $v" if (not defined $pbscript);
    27802808    ($vexist,$vpid) = pb_launchv($pbscript,$vtype,$v,$action,$pbstep,$pbforce,$snapme,$pbsnap,$pbimage);
    27812809   
     
    27952823my $pbscript=shift;
    27962824my $vtype = shift;
    2797 my $v = shift;                  # Only 1 VM/VE/RM treated here
    2798 my $action = shift;             # It an action is defined then use send2target
     2825my $v = shift;              # Only 1 VM/VE/RM treated here
     2826my $action = shift;         # It an action is defined then use send2target
    27992827my $pbstep=shift;           # Which step are we in (0: create, 1: setup, 2: build 3: use)
    2800 my $pbforce=shift || 0;         # Force stop of VM. Default not.
    2801 my $snapme = shift || 0;        # By default do not snap a VM/VE/RM
    2802 my $usesnap = shift || 1;       # By default study the usage of the snapshot feature of VM/VE/RM   
    2803 my $pbimage=shift || undef;     # Which image to use to start the VM/VE
     2828my $pbforce=shift;          # Force stop of VM. Default not.
     2829my $snapme = shift;         # By default do not snap a VM/VE/RM
     2830my $usesnap = shift;            # By default study the usage of the snapshot feature of VM/VE/RM   
     2831my $pbimage=shift        # Which image to use to start the VM/VE
    28042832my $vexist = undef;
    28052833my $vpid = undef;
     2834
     2835$pbforce = 0 if (not defined $pbforce);
     2836$snapme = 0 if (not defined $snapme);
     2837$usesnap = 1 if (not defined $usesnap);
    28062838
    28072839# Check that v exists
     
    28132845}
    28142846
    2815 pb_log(2,"DEBUG: pb_launchv(script,vtype,v,step,force,snapme,usesnap: $pbscript,$vtype,$v,$pbstep,$pbforce,$snapme,$usesnap)\n");
     2847pb_log(2,"DEBUG: pb_launchv(vtype,v,step,force,snapme,usesnap: $vtype,$v,$pbstep,$pbforce,$snapme,$usesnap)\n");
    28162848pb_log(2,"DEBUG: pb_launchv(pbimage: $pbimage)\n") if (defined $pbimage);
     2849pb_log(2,"DEBUG: pb_launchv(pbimage: $pbscript)\n") if (defined $pbscript);
    28172850pb_log(2,"DEBUG: pb_launchv(action: $action)\n") if (defined $action);
    28182851# Keep only the first VM in case many were given
     
    29673000    # Force the creation of the VE and no snapshot usable
    29683001    $vetype = pb_ve_get_type($vetype);
    2969     pb_ve_launch($v,$pbscript,$pbforce,$pbstep,$usesnap,$vetype,$pbimage);
     3002    pb_ve_launch($v,$pbstep,$usesnap,$vetype,$pbimage);
    29703003    $vexist = 0;
    29713004    $vpid = 0;
    29723005} else {
    2973     # RM here
    2974     # Get distro context
    2975     my $pbos = pb_distro_get_context($v);
    2976 
    29773006    # Get RM context
    29783007    my ($ptr,$rmpath) = pb_conf_get("rmtype","rmpath");
     
    30343063
    30353064my $vtype = shift;
    3036 my $action = shift || "build";   #build, test or prep
    3037 my $pbforce=shift || 0;         # Force stop of VM. Default not.
     3065my $action = shift;     #build, test or prep
     3066my $pbforce=shift;      # Force stop of VM. Default not.
     3067
     3068$action = "build" if (not defined $action);
     3069$pbforce = 0 if (not defined $pbforce);
    30383070
    30393071my $pbstep;
     
    31013133    print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
    31023134
    3103     if ($action eq "build") {
     3135    if (($action eq "build") || ($action eq "prep")) {
    31043136        print SCRIPT "# Preparation for pb\n";
    31053137        print SCRIPT "rm -f \$HOME/.pbrc\n";
     
    31093141
    31103142    # VE needs a good /proc, tolerate one being potentially left around after a failure
     3143    $vetype = pb_ve_get_type($vetype);
    31113144    if (($vtype eq "ve") && ($vetype ne "docker")) {
    31123145        print SCRIPT "[ -d /proc/1 ] || sudo /bin/mount -t proc /proc /proc\n";
     
    33583391
    33593392my $vtype = shift;
    3360 my $sbx = shift || undef;
     3393my $sbx = shift;
    33613394my $pbstep = 1;
    33623395
     
    34633496        # once this is done, we can do what we need on the VM/RM remotely
    34643497    } elsif ($vtype eq "ve") {
     3498        $vetype = pb_ve_get_type($vetype);
    34653499        if ($vetype ne "docker") {
    34663500            print SCRIPT << "EOF";
     
    37273761            my ($pbver1,$tmp1) = split(/-/,$vertag1);
    37283762            my ($pbver2,$tmp2) = split(/-/,$vertag2);
    3729             # Copy inside the VE
    3730             if ($vtype eq "ve") {
    3731                 my ($vepath) = pb_conf_get("vepath");
    3732                 copy("$ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz","$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/tmp");
    3733                 copy("$ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz","$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/tmp");
    3734             } else {
    3735                 pb_system("scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport $ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz $ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz root\@$vmhost->{$ENV{'PBPROJ'}}:/tmp","Copying local project files to $vtype.");
    3736             }
    37373763            $cmdget = "mv /tmp/ProjectBuilder-$pbver1$pbextdir.tar.gz ProjectBuilder-latest.tar.gz ; mv /tmp/project-builder-$pbver2$pbextdir.tar.gz project-builder-latest.tar.gz";
    37383764        } else {
     
    38513877# Launch the VM/VE/RM
    38523878pb_log(2,"DEBUG: before parallel launch, pbscript hash is:".Dumper(%pbscript)."\n");
    3853 pb_parallel_launchv(\%pbscript,$vtype,uc($vtype)."Script",$pbstep,$pbforce);
     3879pb_parallel_launchv(\%pbscript,$vtype,uc($vtype)."Script".$sbx,$pbstep,$pbforce);
    38543880return;
    38553881}
     
    38593885
    38603886my $vtype = shift;
    3861 my $pbstep = 3;
     3887my $pbstep = 2;
    38623888
    38633889my ($vm,$all) = pb_get2v($vtype);
     
    39233949EOF
    39243950    # VE needs a good /proc
     3951    $vetype = pb_ve_get_type($vetype);
    39253952    if (($vtype eq "ve") && ($vetype ne "docker")) {
    39263953        print SCRIPT "sudo /bin/mount -t proc /proc /proc\n";
     
    47604787}   
    47614788
    4762 sub pb_get_extdir () {
     4789sub pb_get_extdir {
    47634790
    47644791    # the pbrc file should contain it and whatever the key, we take it
     
    47764803}
    47774804
     4805# Unused now
     4806sub pb_keep_step {
     4807
     4808my $pbos = shift;
     4809my $pbstep = shift;
     4810
     4811$pbstep = 3 if (not defined $pbstep);
     4812
     4813my %h;
     4814my $h = \%h;
     4815$h = pb_conf_cache("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb",$h);
     4816$h->{'pbstep'}->{"$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"} = $pbstep;
     4817pb_conf_write("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb",$h);
     4818}
     4819
     4820sub create_solaris_prototype {
     4821
     4822    my $uidgid = "bin bin";
     4823    my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
     4824
     4825    return if ($_ =~ /^$pkgdestdir$/);
     4826    if (-d $_) {
     4827        my $n = $File::Find::name;
     4828        $n =~ s~$pkgdestdir/~~;
     4829        print PROTO "d none $n 0755 $uidgid\n";
     4830    } elsif (-x $_) {
     4831        my $n = $File::Find::name;
     4832        $n =~ s~$pkgdestdir/~~;
     4833        print PROTO "f none $n 0755 $uidgid\n";
     4834    } elsif (-f $_) {
     4835        my $n = $File::Find::name;
     4836        $n =~ s~$pkgdestdir/~~;
     4837        print PROTO "f none $n 0644 $uidgid\n";
     4838    }
     4839}
     4840
     4841
    477848421;
Note: See TracChangeset for help on using the changeset viewer.