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