Changeset 1903 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/VE.pm


Ignore:
Timestamp:
Oct 8, 2014, 1:35:10 PM (10 years ago)
Author:
Bruno Cornec
Message:
  • Add entries for osrepo for mageia/mandriva distros to allow setupve to work for these distributions without resorting to sbx2setupve
  • pbkeep now managed in pb_temp_init to avoid removing the temps dir when debugging
  • Add functions pb_ve_docker_get_image and pb_ve_get_type
  • lots of interfaces changes to allow support of docker, including script names. May break other non docker features
  • both newve and setupve work with docker now.
  • manages public keys for urpmi distriutions
  • Adds function pb_parallel_launchv. Now pb_launchv is single V
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/VE.pm

    r1902 r1903  
    1616use Carp 'confess';
    1717use English;
     18use File::Basename;
    1819use ProjectBuilder::Version;
    1920use ProjectBuilder::Base;
     
    3132 
    3233our @ISA = qw(Exporter);
    33 our @EXPORT = qw(pb_ve_launch pb_ve_snap);
     34our @EXPORT = qw(pb_ve_launch pb_ve_snap pb_ve_get_type pb_ve_docker_repo pb_ve_docker_get_image);
    3435
    3536($VERSION,$REVISION) = pb_version_init();
     
    6667sub pb_ve_launch {
    6768
    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
     69my $v = shift;
     70my $pbscript = shift;
     71my $pbforce = shift;   
     72my $pbstep= shift;          # Which step are we in (0: create, 1: setup, 2: build, 3: use)
     73my $locsnap = shift;
     74my $vetype = shift;
     75my $pbimage = shift;
    7376
    7477my $dockerregistry = undef;
    7578my $docrepo = undef;            # By default no repository for docker available
    7679
     80pb_log(2,"Entering pb_ve_launch at step $pbstep\n");
    7781# Get distro context
    7882my $pbos = pb_distro_get_context($v);
    7983
    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);
    8785my ($vepath) = pb_conf_get("vepath");
    8886
     
    114112    if ($EFFECTIVE_USER_ID != 0) {
    115113        $sudocmd ="sudo ";
    116     foreach my $proxy (qw/http_proxy ftp_proxy/) {
     114        foreach my $proxy (qw/http_proxy ftp_proxy/) {
    117115            if (defined $ENV{$proxy}) {
    118116                open(CMD,"sudo sh -c 'echo \$$proxy' |") or die "can't run sudo sh?: $!";
     
    132130    if (((((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) && ($vetype ne "docker"))
    133131        # 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))) {
    135133
    136134        my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype");
     
    275273        ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i))) &&
    276274        ($locsnap eq 1) &&
     275        ($vetype ne "docker") &&
    277276        (! -d "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}")) {
    278277            my $cmd1 = pb_check_req("rm",0);
     
    281280            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'}");
    282281    }
    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    }
    287288
    288289    # 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");
    301303    }
    302304
     
    376378}
    377379
     380sub pb_ve_docker_get_image {
     381
     382my $pbimage = shift || undef;
     383my $found = 0;
     384
     385die "Unable to handle an undef docker image" if (not defined $pbimage);
     386
     387# Check that this docker image exists
     388my $cmd1 = pb_check_req("docker",0);
     389open(CMD, "$cmd1 images |") || die "Unable to get docker image list";
     390my ($repo, $tag, $id, $dummy);
     391while (<CMD>) {
     392    ($repo, $tag, $id, $dummy) = split(/\s+/,$_,4);
     393    $found = $id if ("$repo:$tag" eq $pbimage);
     394}
     395close(CMD);
     396return($found);
     397}
     398sub pb_ve_get_type {
     399
     400my $vetype = shift || undef;
     401
     402# Get VE context
     403if (not defined $vetype) {
     404    my ($ptr) = pb_conf_get("vetype");
     405    $vetype = $ptr->{$ENV{'PBPROJ'}};
     406}
     407confess "No vetype defined for $ENV{PBPROJ}" unless (defined $vetype);
     408pb_log(1, "Using vetype $vetype for $ENV{PBPROJ}\n");
     409return($vetype);
     410}
     411
     412
    378413=head1 WEB SITES
    379414
Note: See TracChangeset for help on using the changeset viewer.