chiark / gitweb /
Stop using vagrant-snap
authorCiaran Gultnieks <ciaran@ciarang.com>
Mon, 20 May 2013 11:19:47 +0000 (12:19 +0100)
committerCiaran Gultnieks <ciaran@ciarang.com>
Mon, 20 May 2013 13:28:33 +0000 (14:28 +0100)
a) too unreliable, b) doesn't work at all with various vagrant and
ruby versions

docs/fdroid.texi
fdroidserver/build.py

index 6b85175a53ed4f2dbe703b04422a0c8a42db48ca..a9a1713457a0e28febe91998868fa99ef1b16cdd 100644 (file)
@@ -112,12 +112,10 @@ If you intend to use the 'Build Server' system, for secure and clean builds
 @item
 VirtualBox (debian package virtualbox-ose)
 @item
-Ruby (debian package ruby)
+Ruby (debian packages ruby and rubygems)
 @item
 Vagrant (gem install vagrant)
 @item
-Vagrant-snap (gem install vagrant-snap)
-@item
 Paramiko (debian package python-paramiko)
 @end itemize
 
index 0c474179072d7c5547a7e4825044b6f6254d8710..14155031e624f9225cbfecd6ee404235721e28c9 100644 (file)
@@ -25,6 +25,7 @@ import re
 import tarfile
 import traceback
 import time
+import json
 from optparse import OptionParser
 
 import common
@@ -32,6 +33,12 @@ from common import BuildException
 from common import VCSException
 
 
+def get_builder_vm_id():
+    with open(os.path.join('builder', '.vagrant')) as vf:
+        v = json.load(vf)
+    return v['active']['default']
+
+
 # Note that 'force' here also implies test mode.
 def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
     """Do a build on the build server."""
@@ -44,7 +51,7 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
         print "Checking for valid existing build server"
         if os.path.exists(os.path.join('builder', 'Vagrantfile')):
             print "...directory exists"
-            p = subprocess.Popen(['vagrant', 'snap', 'list'],
+            p = subprocess.Popen(['VBoxManage', 'snapshot', get_builder_vm_id(), 'list', '--details'],
                 cwd='builder', stdout=subprocess.PIPE)
             output = p.communicate()[0]
             if output.find('fdroidclean') != -1:
@@ -55,11 +62,11 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
                 if output.find('running') != -1:
                     print "...suspending"
                     subprocess.call(['vagrant', 'suspend'], cwd='builder')
-                if subprocess.call(['vagrant', 'snap', 'go', 'fdroidclean'],
+                if subprocess.call(['VBoxManage', 'snapshot', get_builder_vm_id(), 'restore', 'fdroidclean'],
                     cwd='builder') == 0:
-                    #if subprocess.call(['vagrant', 'up'], cwd='builder') != 0:
-                    #    raise BuildException("Failed to start build server")
                     print "...reset to snapshot - server is valid"
+                    if subprocess.call(['vagrant', 'up'], cwd='builder') != 0:
+                        raise BuildException("Failed to start build server")
                     vm_ok = True
                 else:
                     print "...failed to reset to snapshot"
@@ -74,12 +81,12 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
             subprocess.call(['vagrant', 'destroy', '-f'], cwd='builder')
             shutil.rmtree('builder')
         os.mkdir('builder')
-        vf = open('builder/Vagrantfile', 'w')
-        vf.write('Vagrant::Config.run do |config|\n')
-        vf.write('config.vm.box = "buildserver"\n')
-        vf.write('config.vm.customize ["modifyvm", :id, "--memory", "768"]\n')
-        vf.write('end\n')
-        vf.close()
+        with open('builder/Vagrantfile', 'w') as vf:
+            vf.write('Vagrant::Config.run do |config|\n')
+            vf.write('config.vm.box = "buildserver"\n')
+            vf.write('config.vm.customize ["modifyvm", :id, "--memory", "768"]\n')
+            vf.write('end\n')
+
         print "Starting new build server"
         if subprocess.call(['vagrant', 'up'], cwd='builder') != 0:
             raise BuildException("Failed to start build server")
@@ -97,20 +104,24 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
         sshconfig = sshconfig.lookup(vagranthost)
         sshs = ssh.SSHClient()
         sshs.set_missing_host_key_policy(ssh.AutoAddPolicy())
+        idfile = sshconfig['identityfile']
+        if idfile.startswith('"') and idfile.endswith('"'):
+            idfile = idfile[1:-1]
         sshs.connect(sshconfig['hostname'], username=sshconfig['user'],
             port=int(sshconfig['port']), timeout=300, look_for_keys=False,
-            key_filename=sshconfig['identityfile'])
+            key_filename=idfile)
         sshs.close()
 
         print "Saving clean state of new build server"
-        if subprocess.call(['vagrant', 'snap', 'take', '-n', 'fdroidclean'],
+        subprocess.call(['vagrant', 'suspend'], cwd='builder')
+        if subprocess.call(['VBoxManage', 'snapshot', get_builder_vm_id(), 'take', 'fdroidclean'],
                 cwd='builder') != 0:
             raise BuildException("Failed to take snapshot")
         print "Restarting new build server"
         if subprocess.call(['vagrant', 'up'], cwd='builder') != 0:
             raise BuildException("Failed to start build server")
         # Make sure it worked...
-        p = subprocess.Popen(['vagrant', 'snap', 'list'],
+        p = subprocess.Popen(['VBoxManage', 'snapshot', get_builder_vm_id(), 'list', '--details'],
             cwd='builder', stdout=subprocess.PIPE)
         output = p.communicate()[0]
         if output.find('fdroidclean') == -1:
@@ -135,9 +146,12 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
         print "Connecting to virtual machine..."
         sshs = ssh.SSHClient()
         sshs.set_missing_host_key_policy(ssh.AutoAddPolicy())
+        idfile = sshconfig['identityfile']
+        if idfile.startswith('"') and idfile.endswith('"'):
+            idfile = idfile[1:-1]
         sshs.connect(sshconfig['hostname'], username=sshconfig['user'],
             port=int(sshconfig['port']), timeout=300, look_for_keys=False,
-            key_filename=sshconfig['identityfile'])
+            key_filename=idfile)
 
         # Get an SFTP connection...
         ftp = sshs.open_sftp()