summaryrefslogtreecommitdiffstats
path: root/Rakefile
diff options
context:
space:
mode:
authorTails developers <amnesia@boum.org>2012-05-13 09:15:13 +0200
committerTails developers <amnesia@boum.org>2012-05-16 12:53:16 +0200
commitaa541fd824c8f73417d07f472f0514bce296e284 (patch)
treee86a3d2092403e729fcc2ef2cd73e2b312225fd6 /Rakefile
parent703e118c80a355b8c43e927b83b6ef785f96d7ef (diff)
vagrant: Add task to create our squeeze basebox
As we use Veewee to automate the creation of the basebox, we are forced to back up on the "do not execute Vagrant manually" stance. This is due to the fact that Veewee is quite hackish and itself calls `vagrant` directly. So we move our monkey-patching from the Rakefile to the Vagrantfile itself. In order to support an HTTP proxy, the `preseed.cfg` file that Veewee need is created beforehands in another Rake task. Proxies bound to localhost will result in a failure and an explicit error messages. Note: it is unfortunately not possible to use `definitions.rb` to add `mirror/http/proxy` to the installer command-line. As the defined proxy is set by network-preesed, it will prevent the installer from retrieving the preseed file provided by Veewee on a local interface.
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile58
1 files changed, 55 insertions, 3 deletions
diff --git a/Rakefile b/Rakefile
index ccef996..0f67a9c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -20,9 +20,6 @@
require 'rubygems'
require 'vagrant'
-# Add Vagrant (monkey-)patch
-require 'vagrant/lib/vagrant_verified_download'
-
# Path to the directory which holds our Vagrantfile
VAGRANT_PATH = File.expand_path('../vagrant', __FILE__)
@@ -79,3 +76,58 @@ namespace :vm do
abort "'vagrant destroy' failed" unless result
end
end
+
+namespace :basebox do
+ task :create_preseed_cfg do
+ require 'erb'
+ require 'uri'
+
+ if ENV['http_proxy']
+ proxy_host = URI.parse(ENV['http_proxy']).host
+
+ if ['localhost', '[::1]'].include?(proxy_host) || proxy_host.start_with?('127.0.0.')
+ abort 'Using an HTTP proxy listening on the loopback is doomed to fail.'
+ end
+
+ $stderr.puts "Building basebox using HTTP proxy: #{ENV['http_proxy']}"
+ else
+ $stderr.puts "No HTTP proxy set to build basebox"
+ end
+
+ preseed_cfg_path = File.expand_path('../vagrant/definitions/squeeze/preseed.cfg', __FILE__)
+ template = ERB.new(File.read("#{preseed_cfg_path}.erb"))
+ File.open(preseed_cfg_path, 'w') do |f|
+ f.write template.result
+ end
+ end
+
+ desc 'Create virtual machine template (a.k.a. basebox)'
+ task :create_basebox => [:create_preseed_cfg] do
+ # veewee is pretty stupid regarding path handling
+ Dir.chdir(VAGRANT_PATH) do
+ require 'veewee'
+
+ # Veewee assumes a separate process for each task. So we mimic that.
+
+ env = Vagrant::Environment.new(:ui_class => Vagrant::UI::Basic)
+
+ Process.fork do
+ env.cli('basebox', 'build', 'squeeze')
+ end
+ Process.wait
+ abort "Building the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
+
+ Process.fork do
+ env.cli('basebox', 'validate', 'squeeze')
+ end
+ Process.wait
+ abort "Validating the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
+
+ Process.fork do
+ env.cli('basebox', 'export', 'squeeze')
+ end
+ Process.wait
+ abort "Exporting the basebox failed (exit code: #{$?.exitstatus})." if $?.exitstatus != 0
+ end
+ end
+end