[Bps-public-commit] r16271 - Shipwright/trunk/bin

alexmv at bestpractical.com alexmv at bestpractical.com
Fri Oct 10 17:01:03 EDT 2008


Author: alexmv
Date: Fri Oct 10 17:01:03 2008
New Revision: 16271

Modified:
   Shipwright/trunk/bin/jeos-build

Log:
 * Move final install point to /opt/install rather than /opt/shipwright
 * Fix path to /bin/rm
 * Don't compile with debugging CFLAGS
 * Attempt to use `sync` to ensure disk writes are done before we unmount
 * Update /etc/environment in built image
 * Use ->login to copy out and report the current state of the install

Modified: Shipwright/trunk/bin/jeos-build
==============================================================================
--- Shipwright/trunk/bin/jeos-build	(original)
+++ Shipwright/trunk/bin/jeos-build	Fri Oct 10 17:01:03 2008
@@ -6,7 +6,7 @@
 
 use Getopt::Long;
 
-my ($image, $store, $vessel, $base, $flags, $skiptest, $partial, $rcfile);
+my ($image, $store, $vessel, $base, $flags, $skiptest, $partial, $rcfile, $user, $pass);
 GetOptions(
     "image=s" => \$image,
     "store=s" => \$store,
@@ -16,6 +16,8 @@
     "skip-test" => \$skiptest,
     "partial" => \$partial,
     "rcfile=s" => \$rcfile,
+    "username=s" => \$user,
+    "password=s" => \$pass,
 ) or die "Option parsing failure";
 
 die "No image specified" unless $image;
@@ -48,11 +50,17 @@
 die "Disk is already mounted; please unmount before continuing.\n"
     if $mounted =~ m{$path/($image|$base)};
 
+# XXX: This used to be a tmpfile, but it exploded -- I don't recall
+# how right now.  For now, you need a "disk-image" directory to mount
+# it under.
+my $mountpoint = "disk-image";
+
 # Clone from image if base doesn't exist
 unless ( -e "$path/$base" ) {
     unless ( -e "$path/$image" ) {
         die "Can't find image in $path/$image to clone from";
     }
+    warn "Creating base '$base' from '$image'...\n";
     !system( '/usr/bin/rsync', "-az", "$path/$image/", "$path/$base/" )
         or die "rsync failed";
 }
@@ -67,15 +75,11 @@
 }
 
 # Mount the disk image
-# XXX: This used to be a tmpfile, but it exploded -- I don't recall
-# how right now.  For now, you need a "disk-image" directory to mount
-# it under.
-my $mountpoint = "disk-image";
 $vm->mount($mountpoint);
 
 # Copy files over
 warn "Installing source...\n";
-system( '/usr/bin/rm', '-rf', "$mountpoint/opt/build", "$mountpoint/opt/install" )
+system( '/bin/rm', '-rf', "$mountpoint/opt/build", "$mountpoint/opt/install" )
     if $partial;
 !system( '/usr/bin/svn', 'co', '-q', $vessel, "$mountpoint/opt/build" )
     or die "svn co failed";
@@ -86,13 +90,14 @@
 #!/bin/sh
 aptitude install build-essential autoconf libtool -y
 cd /opt/build/
-export CFLAGS="-ggdb -g3"
 ./bin/shipwright-builder --install-base /opt/install $flags $skiptest 2>&1 | tee /opt/build/complete.log 
 halt
 EOT
 close RC;
 
 # Unmount
+`sync`;
+sleep 5;
 $vm->unmount;
 
 # Start 'er up!
@@ -101,27 +106,50 @@
 
 # Wait for it to finish
 my $laststate = "";
+my $lastinstall = 0;
 {
     sleep 10;
     my $state = $vm->power_state;
-    warn ucfirst($state) . "...\n" if $laststate ne $state;
+    if ($laststate ne $state) {
+        warn ucfirst($state) . "...\n";
+        if ($state =~ /tools running/ and $laststate !~ /tools running/ and $user and $pass) {
+            warn "Logging in..\n";
+            $vm->login($user, $pass);
+        }
+    }
+    if ($state =~ /tools running/ and $user and $pass) {
+        require YAML;
+        eval {$vm->copy("/opt/install/installed.yml","installed.yml")};
+        unless ($@) {
+            my $ref = YAML::LoadFile("installed.yml");
+            if ($ref) {
+                warn "Installed " . scalar(@{$ref}) ." packages\n"
+                    if scalar(@{$ref}) != $lastinstall;
+                $lastinstall = scalar @{$ref};
+            }
+        }
+    }
     $laststate = $state;
-    redo unless $state =~ "powered off";
+    redo unless $state =~ /powered off/;
 }
-sleep 10;
+sleep 20;
 
 # Check if it succeeded
 $vm->mount($mountpoint);
 !system( "cp", "$mountpoint/opt/build/complete.log", "complete.log" )
     or warn "(Copy of log failed?)\n";
-!system( 'cp', $rcfile, "$mountpoint/etc/rc.local" )
-    or warn "(Copy of rc.local failed?)\n" if $rcfile;
+unlink("$mountpoint/etc/rc.local");
 die "Build failure!  See complete.log\n"
     unless -e "$mountpoint/opt/install/bin-wrapped";
+!system( 'cp', $rcfile, "$mountpoint/etc/rc.local" )
+    or warn "(Copy of rc.local failed?)\n" if $rcfile;
 
 # If we want a partial build, don't clone into a clean image, just
 # stop now
-exit if $partial;
+if ($partial) {
+    warn "Partial image build successful!\n";
+    exit;
+}
 
 # Copy out of the image
 warn "Successfully built!  Copying out of image...\n";
@@ -144,12 +172,20 @@
 $vm->mount($mountpoint);
 !system(
     "/usr/bin/rsync", "-az",
-    "installed-image/", "$mountpoint/opt/shipwright/"
+    "installed-image/", "$mountpoint/opt/install/"
 ) or die "rsync placement failed";
 !system( 'cp', $rcfile, "$mountpoint/etc/rc.local" )
     or die "run rc.init copy failed" if $rcfile;
 
+# Prepend the installed path to PATH
+my $PATH = do {local @ARGV = "$mountpoint/etc/environment"; $_ = <>; close ARGV; $_};
+$PATH =~ s/PATH="(.*)"\n?/$1/;
+open(ENV, ">", "$mountpoint/etc/environment") or die "Can't open environment for writing: $!";
+print ENV qq{PATH="/opt/install/bin:$PATH"\n};
+close ENV;
+
 # Unmount
+`sync`;
 $vm->unmount;
 
 # Snapshot in a clean state, then power it on to take it for a test ride
@@ -351,7 +387,26 @@
     return $snapHandle;
 }
 
+sub login {
+    my $self = shift;
+    my ($user, $password) = @_;
+    my $err = VMLoginInGuest( $$self, $user, $password, 0);
+    croak "VMware::Vix::VM->login: " . GetErrorText($err)
+        if $err != VIX_OK;
+    return 1;
+}
+
+sub copy {
+    my $self = shift;
+    my ($src, $dst) = @_;
+    my $err = VMCopyFileFromGuestToHost($$self, $src, $dst, 0, VIX_INVALID_HANDLE);
+    croak "VMware::Vix::VM->copy: " . GetErrorText($err)
+        if $err != VIX_OK;
+    return 1;
+}
+
 DESTROY {
     my $self = shift;
     $self->unmount;
+    ReleaseHandle($$self);
 }



More information about the Bps-public-commit mailing list