summaryrefslogtreecommitdiffstats
path: root/Rakefile
diff options
context:
space:
mode:
authoranonym <anonym@riseup.net>2016-02-17 13:32:54 +0100
committeranonym <anonym@riseup.net>2016-02-18 22:19:30 +0100
commit8c7a5cf131915d89ce2d9e07df38019016477d09 (patch)
treecb5339bcbc44663b5e5a01008b37a37539137cd1 /Rakefile
parent54523408de8d9d8916e67504187f43edf04f6542 (diff)
Support newer versions of Vagrant.
... than 1.4.x. Using the Vagrant internals just doesn't seem like a sustainable approach given how fast things move with Vagrant. Presumably the commandline interface is more stable. Newer versions of Vagrant has built-in support for verifying base box downloads so we can drop our monkey path. This effectively makes us dependant on such newer versions since Vagrant will fail with an error if we try to set e.g. config.vm.box_download_checksum when it is not supported, so we don't have to explicitly add a version check (even though that might be a good idea).
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile95
1 files changed, 31 insertions, 64 deletions
diff --git a/Rakefile b/Rakefile
index 56fc716..10d5d6f 100644
--- a/Rakefile
+++ b/Rakefile
@@ -18,14 +18,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+require 'open3'
require 'rbconfig'
-require 'rubygems'
-require 'vagrant'
require 'uri'
$:.unshift File.expand_path('../vagrant/lib', __FILE__)
require 'tails_build_settings'
-require 'vagrant_version'
# Path to the directory which holds our Vagrantfile
VAGRANT_PATH = File.expand_path('../vagrant', __FILE__)
@@ -42,58 +40,37 @@ EXTERNAL_HTTP_PROXY = ENV['http_proxy']
# In-VM proxy URL
INTERNEL_HTTP_PROXY = "http://#{VIRTUAL_MACHINE_HOSTNAME}:3142"
-def primary_vm
- env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
- if vagrant_old
- return env.primary_vm
- else
- name = env.primary_machine_name
- return env.machine(name, env.default_provider)
- end
-end
-
-def primary_vm_state
- if vagrant_old
- return primary_vm.state
- else
- return primary_vm.state.id
- end
+# Runs the vagrant command, letting stdout/stderr through, and returns
+# the command's exit status.
+def run_vagrant(*args)
+ Process.wait Kernel.spawn('vagrant', *args, :chdir => './vagrant')
+ $?.exitstatus
end
-def primary_vm_chan
- if vagrant_old
- return primary_vm.channel
- else
- return primary_vm.communicate
- end
+# Runs the vagrant command, not letting stdout/stderr through, and
+# returns [stdout, stderr, Process::Status].
+def capture_vagrant(*args)
+ Open3.capture3('vagrant', *args, :chdir => './vagrant')
end
-
-def vm_id
- if vagrant_old
- primary_vm.uuid
- else
- primary_vm.id
- end
+def current_vm_cpus
+ capture_vagrant('ssh', '-c', 'grep -c "^processor\s*:" /proc/cpuinfo').first.chomp.to_i
end
-def vm_driver
- if vagrant_old
- primary_vm.driver
+def vm_state
+ out, _, status = capture_vagrant('status')
+ status_line = out.split("\n")[2]
+ if status_line['not created']
+ return :not_created
+ elsif status_line['shutoff']
+ return :poweroff
+ elsif status_line['running']
+ return :running
else
- primary_vm.provider.driver
+ raise "could not determine VM state"
end
end
-def current_vm_cpus
- info = vm_driver.execute 'showvminfo', vm_id, '--machinereadable'
- $1.to_i if info =~ /^cpus=(\d+)/
-end
-
-def vm_running?
- primary_vm_state == :running
-end
-
def enough_free_host_memory_for_ram_build?
return false unless RbConfig::CONFIG['host_os'] =~ /linux/i
@@ -106,9 +83,7 @@ def enough_free_host_memory_for_ram_build?
end
def free_vm_memory
- primary_vm_chan.execute("free", :error_check => false) do |fd, data|
- return data.split[16].to_i
- end
+ capture_vagrant('ssh', '-c free').first.chomp.split[16].to_i
end
def enough_free_vm_memory_for_ram_build?
@@ -116,7 +91,7 @@ def enough_free_vm_memory_for_ram_build?
end
def enough_free_memory_for_ram_build?
- if vm_running?
+ if vm_state == :running
enough_free_vm_memory_for_ram_build?
else
enough_free_host_memory_for_ram_build?
@@ -269,11 +244,8 @@ task :build => ['parse_build_options', 'ensure_clean_repository', 'validate_http
end
exported_env = EXPORTED_VARIABLES.select { |k| ENV[k] }.
- collect { |k| "#{k}='#{ENV[k]}'" }.join(' ')
- status = primary_vm_chan.execute("#{exported_env} build-tails",
- :error_check => false) do |fd, data|
- (fd == :stdout ? $stdout : $stderr).write data
- end
+ collect { |k| "#{k}='#{ENV[k]}'" }.join(' ')
+ status = run_vagrant('ssh', '-c', "#{exported_env} build-tails")
# Move build products to the current directory
FileUtils.mv Dir.glob("#{VAGRANT_PATH}/tails-*"),
@@ -285,7 +257,7 @@ end
namespace :vm do
desc 'Start the build virtual machine'
task :up => ['parse_build_options', 'validate_http_proxy'] do
- case primary_vm_state
+ case vm_state
when :not_created
# Do not use non-existant in-VM proxy to download the basebox
if ENV['http_proxy'] == INTERNEL_HTTP_PROXY
@@ -315,31 +287,26 @@ namespace :vm do
END_OF_MESSAGE
end
- env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
- result = env.cli('up')
+ result = run_vagrant('up')
abort "'vagrant up' failed" unless result
-
ENV['http_proxy'] = INTERNEL_HTTP_PROXY if restore_internal_proxy
end
desc 'Stop the build virtual machine'
task :halt do
- env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
- result = env.cli('halt')
+ result = run_vagrant('halt')
abort "'vagrant halt' failed" unless result
end
desc 'Re-run virtual machine setup'
task :provision => ['parse_build_options', 'validate_http_proxy'] do
- env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
- result = env.cli('provision')
+ result = run_vagrant('provision')
abort "'vagrant provision' failed" unless result
end
desc 'Destroy build virtual machine (clean up all files)'
task :destroy do
- env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
- result = env.cli('destroy', '--force')
+ result = run_vagrant('destroy', '--force')
abort "'vagrant destroy' failed" unless result
end
end