[1348] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # Common functions for virtual environment
|
---|
[1528] | 4 | #
|
---|
[2488] | 5 | # Copyright B. Cornec 2007-today
|
---|
[1528] | 6 | # Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
|
---|
| 7 | # Provided under the GPL v2
|
---|
[1348] | 8 | #
|
---|
| 9 | # $Id$
|
---|
| 10 | #
|
---|
| 11 |
|
---|
| 12 | package ProjectBuilder::VE;
|
---|
| 13 |
|
---|
| 14 | use strict;
|
---|
| 15 | use Data::Dumper;
|
---|
[1506] | 16 | use Carp 'confess';
|
---|
[1348] | 17 | use English;
|
---|
[1903] | 18 | use File::Basename;
|
---|
[1348] | 19 | use ProjectBuilder::Version;
|
---|
| 20 | use ProjectBuilder::Base;
|
---|
| 21 | use ProjectBuilder::Conf;
|
---|
[1350] | 22 | use ProjectBuilder::Distribution;
|
---|
[1348] | 23 |
|
---|
| 24 | # Global vars
|
---|
| 25 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 26 |
|
---|
| 27 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
| 28 | use Exporter;
|
---|
| 29 |
|
---|
| 30 | # Export, by default, all the functions into the namespace of
|
---|
| 31 | # any code which uses this module.
|
---|
| 32 |
|
---|
| 33 | our @ISA = qw(Exporter);
|
---|
[2104] | 34 | our @EXPORT = qw(pb_ve_launch pb_ve_snap pb_ve_get_type pb_ve_docker_repo pb_ve_docker_get_image);
|
---|
[1348] | 35 |
|
---|
[2498] | 36 | our ($VERSION,$REVISION,$PBCONFVER) = pb_version_init();
|
---|
[1348] | 37 |
|
---|
| 38 | =pod
|
---|
| 39 |
|
---|
| 40 | =head1 NAME
|
---|
| 41 |
|
---|
| 42 | ProjectBuilder::VE, part of the project-builder.org - module dealing with Virtual Environment
|
---|
| 43 |
|
---|
| 44 | =head1 DESCRIPTION
|
---|
| 45 |
|
---|
[1900] | 46 | This modules provides functions to deal with Virtual Environements (VE), aka chroot/containers.
|
---|
[1348] | 47 |
|
---|
| 48 | =head1 SYNOPSIS
|
---|
| 49 |
|
---|
| 50 | use ProjectBuilder::VE;
|
---|
| 51 |
|
---|
| 52 | #
|
---|
| 53 | # Return information on the running distro
|
---|
| 54 | #
|
---|
| 55 | my $pbos = pb_ve_launch();
|
---|
| 56 |
|
---|
| 57 | =head1 USAGE
|
---|
| 58 |
|
---|
| 59 | =over 4
|
---|
| 60 |
|
---|
| 61 | =item B<pb_ve_launch>
|
---|
| 62 |
|
---|
[2690] | 63 | This function launches a VE, creating it (if necessary) using multiple external potential tools.
|
---|
[1348] | 64 |
|
---|
| 65 | =cut
|
---|
| 66 |
|
---|
| 67 | sub pb_ve_launch {
|
---|
| 68 |
|
---|
[1903] | 69 | my $v = shift;
|
---|
[2428] | 70 | my $pbstep = shift; # Which step are we in (0: create, 1: setup, 2: build, 3: use)
|
---|
[1903] | 71 | my $locsnap = shift;
|
---|
| 72 | my $vetype = shift;
|
---|
| 73 | my $pbimage = shift;
|
---|
[1348] | 74 |
|
---|
[2003] | 75 | my $docrepo = ""; # By default no repository for docker available
|
---|
[1900] | 76 |
|
---|
[2428] | 77 | pb_log(2,"Entering pb_ve_launch at step $pbstep for type $vetype\n");
|
---|
[1348] | 78 | # Get distro context
|
---|
| 79 | my $pbos = pb_distro_get_context($v);
|
---|
| 80 |
|
---|
[1903] | 81 | $vetype = pb_ve_get_type($vetype);
|
---|
[1900] | 82 | my ($vepath) = pb_conf_get("vepath");
|
---|
[1506] | 83 |
|
---|
[1966] | 84 | if ($vetype eq "docker") {
|
---|
[2104] | 85 | $docrepo = pb_ve_docker_repo();
|
---|
[1966] | 86 | }
|
---|
| 87 |
|
---|
[1967] | 88 | # Architecture consistency
|
---|
| 89 | my $arch = pb_get_arch();
|
---|
| 90 | if ($arch ne $pbos->{'arch'}) {
|
---|
| 91 | die "Unable to launch a VE of architecture $pbos->{'arch'} on a $arch platform" unless (($pbos->{'arch'} =~ /i?86/o) && ($arch eq "x86_64"));
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | # If we are already root (from pbmkbm e.g.) don't use sudo, just call the command
|
---|
| 95 | my $sudocmd="";
|
---|
| 96 | if ($EFFECTIVE_USER_ID != 0) {
|
---|
| 97 | $sudocmd ="sudo ";
|
---|
[2234] | 98 | foreach my $proxy (qw/http_proxy https_proxy ftp_proxy/) {
|
---|
[1967] | 99 | if (defined $ENV{$proxy}) {
|
---|
| 100 | open(CMD,"sudo sh -c 'echo \$$proxy' |") or die "can't run sudo sh?: $!";
|
---|
| 101 | $_ = <CMD>;
|
---|
| 102 | chomp();
|
---|
| 103 | die "sudo not passing through env var $proxy; '$ENV{$proxy}' != '$_'\nAdd line Defaults:`whoami` env_keep += \"$proxy\" to sudoers file?" unless $_ eq $ENV{$proxy};
|
---|
| 104 | close(CMD);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | # Handle cross arch on Intel based platforms
|
---|
| 110 | $sudocmd = "setarch i386 $sudocmd" if (($pbos->{'arch'} =~ /i[3456]86/) && ($arch eq 'x86_64'));
|
---|
| 111 |
|
---|
[2317] | 112 | confess "No vepath value defined, please add one to your project yml file" if ((not defined $vepath) or (not defined $vepath->{$ENV{'PBPROJ'}}));
|
---|
[2287] | 113 | my $root = pb_path_expand($vepath->{$ENV{'PBPROJ'}});
|
---|
[1967] | 114 |
|
---|
[1900] | 115 | if (($vetype eq "chroot") || ($vetype eq "schroot") || ($vetype eq "docker")) {
|
---|
[1348] | 116 |
|
---|
[1352] | 117 | # We need to avoid umask propagation to the VE
|
---|
| 118 | umask 0022;
|
---|
[1348] | 119 |
|
---|
[1352] | 120 | # We can probably only get those params now we have the distro context
|
---|
[2488] | 121 | my ($vesnap,$verebuild) = pb_conf_get_if("vesnap","verebuild");
|
---|
[1348] | 122 |
|
---|
[2428] | 123 | if (((((defined $verebuild) && (defined $verebuild->{$ENV{'PBPROJ'}}) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbstep == 0)) && ($vetype ne "docker"))
|
---|
[1900] | 124 | # For docker we may have a reference image that we'll use
|
---|
[2428] | 125 | || (($vetype eq "docker") && ($pbstep == 0) && ((not defined $pbimage) || ($pbimage eq "")))) {
|
---|
[1900] | 126 |
|
---|
[1352] | 127 | my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype");
|
---|
| 128 | my ($rbsopt1) = pb_conf_get_if("rbsopt");
|
---|
| 129 |
|
---|
[1348] | 130 | # We have to rebuild the chroot
|
---|
| 131 | if ($pbos->{'type'} eq "rpm") {
|
---|
| 132 |
|
---|
| 133 | # Which tool is used
|
---|
| 134 | my $verpmstyle = $verpmtype->{$ENV{'PBPROJ'}};
|
---|
[2287] | 135 | die "No verpmtype defined for $ENV{'PBPROJ'}" unless (defined $verpmstyle);
|
---|
[1348] | 136 |
|
---|
| 137 | # Get potential rbs option
|
---|
| 138 | my $rbsopt = "";
|
---|
| 139 | if (defined $rbsopt1) {
|
---|
| 140 | if (defined $rbsopt1->{$verpmstyle}) {
|
---|
| 141 | $rbsopt = $rbsopt1->{$verpmstyle};
|
---|
| 142 | } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
|
---|
| 143 | $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
|
---|
| 144 | } else {
|
---|
| 145 | $rbsopt = "";
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[2488] | 149 | my $postinstall = pb_ve_get_postinstall($pbos,$verpmstyle);
|
---|
[1348] | 150 | if ($verpmstyle eq "rinse") {
|
---|
| 151 | # Need to reshape the mirrors generated with local before-post-install script
|
---|
| 152 | my $b4post = "--before-post-install ";
|
---|
[2488] | 153 | my $postparam = pb_distro_get_if($pbos,"rbsb4pi");
|
---|
[1348] | 154 | if ($postparam eq "") {
|
---|
| 155 | $b4post = "";
|
---|
| 156 | } else {
|
---|
| 157 | $b4post .= $postparam;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | # Need to reshape the package list for pb
|
---|
| 161 | my $addpkgs;
|
---|
| 162 | $postparam = "";
|
---|
[2488] | 163 | $postparam .= pb_distro_get_if($pbos,"osmindep");
|
---|
[1348] | 164 | if ($postparam eq "") {
|
---|
| 165 | $addpkgs = "";
|
---|
| 166 | } else {
|
---|
| 167 | my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis";
|
---|
| 168 | open(PKG,"> $pkgfile") || die "Unable to create $pkgfile";
|
---|
| 169 | foreach my $p (split(/,/,$postparam)) {
|
---|
| 170 | print PKG "$p\n";
|
---|
| 171 | }
|
---|
| 172 | close(PKG);
|
---|
| 173 | $addpkgs = "--add-pkg-list $pkgfile";
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | my $rinseverb = "";
|
---|
| 177 | $rinseverb = "--verbose" if ($pbdebug gt 0);
|
---|
| 178 | my ($rbsconf) = pb_conf_get("rbsconf");
|
---|
| 179 |
|
---|
| 180 | my $command = pb_check_req("rinse",0);
|
---|
[1506] | 181 | pb_system("$sudocmd $command --directory \"$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}\" --arch \"$pbos->{'arch'}\" --distribution \"$pbos->{'name'}-$pbos->{'version'}\" --config \"$rbsconf->{$ENV{'PBPROJ'}}\" $b4post $postinstall $rbsopt $addpkgs $rinseverb","Creating the rinse VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose");
|
---|
[1348] | 182 | } elsif ($verpmstyle eq "rpmbootstrap") {
|
---|
| 183 | my $rbsverb = "";
|
---|
| 184 | foreach my $i (1..$pbdebug) {
|
---|
| 185 | $rbsverb .= " -v";
|
---|
| 186 | }
|
---|
| 187 | my $addpkgs = "";
|
---|
| 188 | my $postparam = "";
|
---|
[2488] | 189 | $postparam .= pb_distro_get_if($pbos,"osmindep");
|
---|
[1348] | 190 | if ($postparam eq "") {
|
---|
| 191 | $addpkgs = "";
|
---|
| 192 | } else {
|
---|
| 193 | $addpkgs = "-a $postparam";
|
---|
| 194 | }
|
---|
| 195 | my $command = pb_check_req("rpmbootstrap",0);
|
---|
| 196 | pb_system("$sudocmd $command $rbsopt $postinstall $addpkgs $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} $rbsverb","Creating the rpmbootstrap VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose");
|
---|
[1596] | 197 | pb_system("$sudocmd /bin/umount $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/proc","Umounting stale /proc","mayfail") if (-f "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/proc/cpuinfo");
|
---|
[1348] | 198 | } elsif ($verpmstyle eq "mock") {
|
---|
| 199 | my ($rbsconf) = pb_conf_get("rbsconf");
|
---|
| 200 | my $command = pb_check_req("mock",0);
|
---|
| 201 | pb_system("$sudocmd $command --init --resultdir=\"/tmp\" --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v $rbsopt","Creating the mock VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})");
|
---|
| 202 | # Once setup we need to install some packages, the pb account, ...
|
---|
| 203 | pb_system("$sudocmd $command --install --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
|
---|
| 204 | } else {
|
---|
| 205 | die "Unknown verpmtype type $verpmstyle. Report to dev team";
|
---|
| 206 | }
|
---|
| 207 | } elsif ($pbos->{'type'} eq "deb") {
|
---|
| 208 | my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}};
|
---|
| 209 |
|
---|
[2488] | 210 | my $codename = pb_distro_get_if($pbos,"oscodename");
|
---|
[1348] | 211 | my $postparam = "";
|
---|
| 212 | my $addpkgs;
|
---|
[2488] | 213 | $postparam .= pb_distro_get_if($pbos,"osmindep");
|
---|
[1348] | 214 | if ($postparam eq "") {
|
---|
| 215 | $addpkgs = "";
|
---|
| 216 | } else {
|
---|
| 217 | $addpkgs = "--include $postparam";
|
---|
| 218 | }
|
---|
| 219 | my $debmir = "";
|
---|
[2488] | 220 | $debmir .= pb_distro_get_if($pbos,"rbsmirrorsrv");
|
---|
[1348] | 221 |
|
---|
| 222 | # Get potential rbs option
|
---|
| 223 | my $rbsopt = "";
|
---|
| 224 | if (defined $rbsopt1) {
|
---|
| 225 | if (defined $rbsopt1->{$vedebstyle}) {
|
---|
| 226 | $rbsopt = $rbsopt1->{$vedebstyle};
|
---|
| 227 | } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
|
---|
| 228 | $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
|
---|
| 229 | } else {
|
---|
| 230 | $rbsopt = "";
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | # debootstrap works with amd64 not x86_64
|
---|
| 235 | my $debarch = $pbos->{'arch'};
|
---|
| 236 | $debarch = "amd64" if ($pbos->{'arch'} eq "x86_64");
|
---|
| 237 | if ($vedebstyle eq "debootstrap") {
|
---|
| 238 | my $dbsverb = "";
|
---|
| 239 | $dbsverb = "--verbose" if ($pbdebug gt 0);
|
---|
| 240 |
|
---|
| 241 | # Some perl modules are in Universe on Ubuntu
|
---|
| 242 | $rbsopt .= " --components=main,universe" if ($pbos->{'name'} eq "ubuntu");
|
---|
| 243 |
|
---|
[1588] | 244 | my $cmd1 = pb_check_req("mkdir",0);
|
---|
| 245 | my $cmd2 = pb_check_req("debootstrap",0);
|
---|
| 246 | pb_system("$sudocmd $cmd1 -p $root/$pbos->{name}/$pbos->{version}/$pbos->{arch} ; $sudocmd $cmd2 $dbsverb $rbsopt --arch=$debarch $addpkgs $codename \"$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}\" $debmir","Creating the debootstrap VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose");
|
---|
[1348] | 247 | # debootstrap doesn't create an /etc/hosts file
|
---|
[1506] | 248 | if (! -f "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/etc/hosts" ) {
|
---|
[1588] | 249 | my $cmd = pb_check_req("cp",0);
|
---|
| 250 | pb_system("$sudocmd $cmd /etc/hosts $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/etc/hosts");
|
---|
[1348] | 251 | }
|
---|
| 252 | } else {
|
---|
| 253 | die "Unknown vedebtype type $vedebstyle. Report to dev team";
|
---|
| 254 | }
|
---|
| 255 | } elsif ($pbos->{'type'} eq "ebuild") {
|
---|
| 256 | die "Please teach the dev team how to build gentoo chroot";
|
---|
[2333] | 257 | } elsif ($pbos->{'type'} eq "apk") {
|
---|
| 258 | die "Please teach the dev team how to build alpine chroot";
|
---|
[1348] | 259 | } else {
|
---|
| 260 | die "Unknown distribution type $pbos->{'type'}. Report to dev team";
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | # Test if an existing snapshot exists and use it if appropriate
|
---|
[1900] | 265 | # And also use it if no local extracted VE is present
|
---|
[1506] | 266 | if ((-f "$root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz") &&
|
---|
[1348] | 267 | (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) ||
|
---|
[1646] | 268 | ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i))) &&
|
---|
| 269 | ($locsnap eq 1) &&
|
---|
[1903] | 270 | ($vetype ne "docker") &&
|
---|
[1646] | 271 | (! -d "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}")) {
|
---|
[1588] | 272 | my $cmd1 = pb_check_req("rm",0);
|
---|
| 273 | my $cmd2 = pb_check_req("mkdir",0);
|
---|
| 274 | my $cmd3 = pb_check_req("tar",0);
|
---|
| 275 | 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'}");
|
---|
[1348] | 276 | }
|
---|
[1597] | 277 |
|
---|
[1903] | 278 | if ($vetype ne "docker") {
|
---|
| 279 | # Fix modes to allow access to the VE for pb user
|
---|
| 280 | my $command = pb_check_req("chmod",0);
|
---|
| 281 | pb_system("$sudocmd $command 755 $root/$pbos->{'name'} $root/$pbos->{'name'}/$pbos->{'version'} $root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}","Fixing permissions");
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[1900] | 284 | # If docker, create the image and remove the now temp dir except if we had one already
|
---|
[2428] | 285 | if (($vetype eq "docker") && ($pbstep == 0)) {
|
---|
[1903] | 286 | my $cmd1 = pb_check_req("docker",0);
|
---|
| 287 | # step 0 : nothing at creation -> tag n-v-a (made below)
|
---|
| 288 |
|
---|
[1966] | 289 | if ((not defined $pbimage) || ($pbimage eq "")) {
|
---|
| 290 | # Snaphot the VE to serve as an input for docker
|
---|
| 291 | pb_ve_snap($pbos,$root);
|
---|
| 292 | # Create the docker image from the previous bootstrap
|
---|
| 293 | # Need sudo to be able to create all files correctly
|
---|
| 294 | # TODO: check before that the image doesn't already exist in the docker registry
|
---|
| 295 |
|
---|
[2003] | 296 | my $pbimage = "$docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[1966] | 297 | pb_system("$sudocmd $cmd1 import - $pbimage < $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz");
|
---|
| 298 | pb_system("$cmd1 push $pbimage");
|
---|
| 299 | } else {
|
---|
| 300 | # If we pass a parameter to -i, this is the name of an existing upstream image for that distro-ver-arch
|
---|
[1967] | 301 | # That container should then be setup correctly which may not be the case yet
|
---|
| 302 | #
|
---|
| 303 | # We can probably only get those params now we have the distro context
|
---|
[2488] | 304 | my $pkgs = pb_distro_get_if($pbos,"osmindep");
|
---|
[1967] | 305 | $pkgs =~ s/,/ /g;
|
---|
| 306 | my $tmpd = "$ENV{'PBTMP'}/Dockerfile";
|
---|
| 307 | open(DOCKER, "> $tmpd") || die "Unable to create the docker file $tmpd";
|
---|
| 308 | print DOCKER "FROM $pbimage\n";
|
---|
| 309 | print DOCKER "MAINTAINER project-builder.org aka pb\n";
|
---|
[2287] | 310 | print DOCKER "ENV ftp_proxy $ENV{'ftp_proxy'}\n" if (defined $ENV{'ftp_proxy'});
|
---|
| 311 | print DOCKER "ENV http_proxy $ENV{'http_proxy'}\n" if (defined $ENV{'http_proxy'});
|
---|
| 312 | print DOCKER "ENV https_proxy $ENV{'https_proxy'}\n" if (defined $ENV{'https_proxy'});
|
---|
[1967] | 313 | # We are root in that container so no need to sudo, which is present potentially
|
---|
| 314 | my $cmd2 = $pbos->{'install'};
|
---|
| 315 | $cmd2 =~ s/sudo //g;
|
---|
| 316 | print DOCKER "RUN $cmd2 $pkgs\n";
|
---|
| 317 | close(DOCKER);
|
---|
[2003] | 318 | pb_system("cd $ENV{'PBTMP'} ; $sudocmd $cmd1 build -t $docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} .","Installing dependencies $pkgs in Docker container $docrepo$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}");
|
---|
[1967] | 319 | unlink($tmpd);
|
---|
[1966] | 320 | }
|
---|
[1900] | 321 | }
|
---|
| 322 |
|
---|
[1348] | 323 | # Nothing more to do for VE. No real launch
|
---|
| 324 | } else {
|
---|
| 325 | die "VE of type $vetype not supported. Report to the dev team";
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | #
|
---|
| 330 | # Return the postinstall line if needed
|
---|
| 331 | #
|
---|
| 332 |
|
---|
| 333 | sub pb_ve_get_postinstall {
|
---|
| 334 |
|
---|
| 335 | my $pbos = shift;
|
---|
| 336 | my $vestyle = shift;
|
---|
| 337 | my $post = "";
|
---|
| 338 |
|
---|
| 339 | # Do we have a local post-install script
|
---|
| 340 | if ($vestyle eq "rinse") {
|
---|
| 341 | $post = "--post-install ";
|
---|
| 342 | } elsif ($vestyle eq "rpmbootstrap") {
|
---|
| 343 | $post = "-s ";
|
---|
| 344 | }
|
---|
| 345 |
|
---|
[2488] | 346 | my $postparam = pb_distro_get_if($pbos,"rbspi");
|
---|
[1348] | 347 | if ($postparam eq "") {
|
---|
| 348 | $post = "";
|
---|
| 349 | } else {
|
---|
| 350 | $post .= $postparam;
|
---|
| 351 | }
|
---|
| 352 | return($post);
|
---|
| 353 | }
|
---|
| 354 |
|
---|
[1900] | 355 | # Snapshot the VE
|
---|
| 356 | sub pb_ve_snap {
|
---|
[1348] | 357 |
|
---|
[1900] | 358 | my $pbos = shift;
|
---|
| 359 | my $root = shift;
|
---|
| 360 | my $tpdir = "$root/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}";
|
---|
| 361 | pb_system("sudo tar cz -C $tpdir -f $root/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz .","Creating a snapshot of $tpdir");
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | # Returns the docker registry to interact with
|
---|
| 365 | sub pb_ve_docker_registry {
|
---|
| 366 |
|
---|
[1907] | 367 | my $dockerreg = shift;
|
---|
[1900] | 368 | my $wget = pb_check_req("wget",0);
|
---|
| 369 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($dockerreg);
|
---|
| 370 | my $docreg = $scheme."://";
|
---|
| 371 | $docreg .= $account."@" if ((defined $account) && ($account ne ""));
|
---|
| 372 | $docreg .= $host;
|
---|
| 373 | $docreg .= ":$port" if ((defined $port) && ($port ne ""));
|
---|
| 374 | open(FD,"$wget $docreg -q -O -|") || die "Unable to talk to the docker registry $docreg";
|
---|
| 375 | my $found = undef;
|
---|
| 376 | while (<FD>) {
|
---|
| 377 | $found = 1 if (/docker-registry/);
|
---|
| 378 | }
|
---|
| 379 | close(FD);
|
---|
| 380 | die "No correct docker-registry answering at $docreg. Please check your configuration" if (not defined $found);
|
---|
| 381 | #
|
---|
| 382 | return($docreg);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[1903] | 385 | sub pb_ve_docker_get_image {
|
---|
| 386 |
|
---|
[1907] | 387 | my $pbimage = shift;
|
---|
[2157] | 388 | my $found =undef;
|
---|
[1903] | 389 |
|
---|
| 390 | die "Unable to handle an undef docker image" if (not defined $pbimage);
|
---|
| 391 |
|
---|
| 392 | # Check that this docker image exists
|
---|
| 393 | my $cmd1 = pb_check_req("docker",0);
|
---|
| 394 | open(CMD, "$cmd1 images |") || die "Unable to get docker image list";
|
---|
| 395 | my ($repo, $tag, $id, $dummy);
|
---|
| 396 | while (<CMD>) {
|
---|
| 397 | ($repo, $tag, $id, $dummy) = split(/\s+/,$_,4);
|
---|
| 398 | $found = $id if ("$repo:$tag" eq $pbimage);
|
---|
| 399 | }
|
---|
| 400 | close(CMD);
|
---|
| 401 | return($found);
|
---|
| 402 | }
|
---|
[1966] | 403 |
|
---|
[1903] | 404 | sub pb_ve_get_type {
|
---|
| 405 |
|
---|
[1907] | 406 | my $vetype = shift;
|
---|
[1903] | 407 |
|
---|
| 408 | # Get VE context
|
---|
| 409 | if (not defined $vetype) {
|
---|
| 410 | my ($ptr) = pb_conf_get("vetype");
|
---|
| 411 | $vetype = $ptr->{$ENV{'PBPROJ'}};
|
---|
| 412 | }
|
---|
[2287] | 413 | confess "No vetype defined for $ENV{'PBPROJ'}" unless (defined $vetype);
|
---|
| 414 | pb_log(1, "Using vetype $vetype for $ENV{'PBPROJ'}\n");
|
---|
[1903] | 415 | return($vetype);
|
---|
| 416 | }
|
---|
| 417 |
|
---|
[2104] | 418 | # Returns the docker repository to interact with
|
---|
| 419 | sub pb_ve_docker_repo {
|
---|
[1903] | 420 |
|
---|
[2092] | 421 | my $docrepo = "";
|
---|
| 422 | # Check acces to registry
|
---|
| 423 | my ($dockerregistry) = pb_conf_get_if("dockerregistry");
|
---|
| 424 | if ((defined $dockerregistry) && (defined $dockerregistry->{$ENV{'PBPROJ'}})) {
|
---|
| 425 | pb_ve_docker_registry($dockerregistry->{$ENV{'PBPROJ'}});
|
---|
[2104] | 426 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($dockerregistry->{$ENV{'PBPROJ'}}).":";
|
---|
| 427 | $docrepo .= $host;
|
---|
| 428 | $docrepo .= ":$port" if ((defined $port) && ($port ne ""));
|
---|
| 429 | $docrepo .= "$path";
|
---|
[2092] | 430 | } else {
|
---|
| 431 | my ($dockerrepository) = pb_conf_get("dockerrepository");
|
---|
| 432 | $docrepo = $dockerrepository->{$ENV{'PBPROJ'}}.":";
|
---|
| 433 | }
|
---|
| 434 | pb_log(1,"Using Docker Repository $docrepo\n");
|
---|
| 435 | return($docrepo);
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 |
|
---|
[1348] | 439 | =head1 WEB SITES
|
---|
| 440 |
|
---|
| 441 | The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
| 442 |
|
---|
| 443 | =head1 USER MAILING LIST
|
---|
| 444 |
|
---|
| 445 | None exists for the moment.
|
---|
| 446 |
|
---|
| 447 | =head1 AUTHORS
|
---|
| 448 |
|
---|
| 449 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 450 |
|
---|
| 451 | =head1 COPYRIGHT
|
---|
| 452 |
|
---|
| 453 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 454 | described in the file C<COPYING> included with the distribution.
|
---|
| 455 |
|
---|
| 456 | =cut
|
---|
| 457 |
|
---|
| 458 |
|
---|
| 459 | 1;
|
---|