Continued use of Vagrant within the TAILS distribution build: Using rake to invoke Vagrant::Environment in Vagrant 1.7

24 views
Skip to first unread message

Adam Burns

unread,
Jul 6, 2015, 8:16:12 AM7/6/15
to vagra...@googlegroups.com

I am investigating whether there is a quick fix to update the TAILS distribution build system to continue using Vagrant.

(see https://labs.riseup.net/code/issues/8086 )

It currently uses a rake to invoke Vagrant::Environment, but this *seemingly* only works with now ancient versions of Vagrant.

I am fairly new to ruby and rake, gems and rvm

This post suggests this is impossible to do with, say, the RPM or Deb version supplied on the current Vagrant site rather than older version gems.

I have tried various methods to learn about ruby paths and inserting new require paths into the Rakefile explicitly, but would very much appreciate pointers or advice over this issue to save time and keep the TAILS devs using Vagrant as their tool of choice!

AdThanksvance


Adam Burns

unread,
Jul 19, 2015, 5:00:31 AM7/19/15
to vagra...@googlegroups.com

I finally got the TAILS Rakefile to call Vagrant 1.7.3 (installed from RPM) with the following (ugly) diffs:

+$LOAD_PATH.unshift File.expand_path('/opt/vagrant/embedded/gems/gems/vagrant-1.7.3/lib/', __FILE__)
+$LOAD_PATH.unshift File.expand_path('/opt/vagrant/embedded/gems/gems/hashicorp-checkpoint-0.1.4/lib', __FILE__)
+$LOAD_PATH.unshift File.expand_path('/opt/vagrant/embedded/gems/gems/log4r-1.1.10/lib', __FILE__)
+$LOAD_PATH.unshift File.expand_path('/opt/vagrant/embedded/gems/gems/childprocess-0.5.5/lib', __FILE__)
+$LOAD_PATH.unshift File.expand_path('/opt/vagrant/embedded/gems/gems/erubis-2.7.0/lib', __FILE__)


Could someone help a ruby/rake n00b with the proper way to add a recursive search path  for require?

Many Thanks!

Adam Burns

unread,
Jul 27, 2015, 7:46:35 AM7/27/15
to Vagrant, adam....@gmail.com

So I discovered one way to achieve this (though probably not optimal at all ...) using LoadError so that if the dated vagrant gem is uninstalled, the Rakefile will add the [deb,rpm] package paths and attempt again.

Comments/Alternate suggestions more than welcome ...


+
 require 'rbconfig'
 require 'rubygems'
-require 'vagrant'
+begin
+  require 'vagrant'
+rescue LoadError
+  VAGRANT_PKG_REQ_PREFIX = "/opt/vagrant/embedded/gems/gems/"
+  puts "vagrant library require files from gem not found, attempting
vagrant [deb,rpm] package require paths under #{VAGRANT_PKG_REQ_PREFIX}"
+  Dir.glob("#{VAGRANT_PKG_REQ_PREFIX}*/lib").each do |pkg_req_dir|
+    $LOAD_PATH.unshift File.expand_path("#{pkg_req_dir}", __FILE__)
+  end
+  # attempt to load vagrant library again, this time failing by terminating
+  require 'vagrant'
+end
 require 'uri'
Reply all
Reply to author
Forward
0 new messages