summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Rakefile25
-rw-r--r--vagrant/Vagrantfile9
-rw-r--r--vagrant/lib/tails_build_settings.rb6
-rwxr-xr-xvagrant/provision/assets/build-tails24
4 files changed, 63 insertions, 1 deletions
diff --git a/Rakefile b/Rakefile
index c4c29a9..7c909d3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -28,11 +28,17 @@ require 'tails_build_settings'
VAGRANT_PATH = File.expand_path('../vagrant', __FILE__)
# Environment variables that will be exported to the build script
-EXPORTED_VARIABLES = ['http_proxy', 'MKSQUASHFS_OPTIONS']
+EXPORTED_VARIABLES = ['http_proxy', 'MKSQUASHFS_OPTIONS', 'TAILS_RAM_BUILD']
# Let's save the http_proxy set before playing with it
EXTERNAL_HTTP_PROXY = ENV['http_proxy']
+def current_vm_memory
+ env = Vagrant::Environment.new(:cwd => VAGRANT_PATH, :ui_class => Vagrant::UI::Basic)
+ uuid = env.primary_vm.uuid
+ info = env.primary_vm.driver.execute 'showvminfo', uuid, '--machinereadable'
+ $1.to_i if info =~ /^memory=(\d+)/
+end
task :parse_build_options do
options = ''
@@ -43,6 +49,11 @@ task :parse_build_options do
options += ENV['TAILS_BUILD_OPTIONS'] if ENV['TAILS_BUILD_OPTIONS']
options.split(' ').each do |opt|
case opt
+ # Memory build settings
+ when 'ram'
+ ENV['TAILS_RAM_BUILD'] = '1'
+ when 'noram'
+ ENV['TAILS_RAM_BUILD'] = nil
# HTTP proxy settings
when 'extproxy'
abort "No HTTP proxy set, but one is required by TAILS_BUILD_OPTIONS. Aborting." unless EXTERNAL_HTTP_PROXY
@@ -120,6 +131,18 @@ namespace :vm do
$ rake vm:halt
END_OF_MESSAGE
+ when :running
+ if ENV['TAILS_RAM_BUILD'] && current_vm_memory < VM_MEMORY_FOR_RAM_BUILDS
+ $stderr.puts <<-END_OF_MESSAGE.gsub(/^ /, '')
+
+ The virtual machine is not currently set with enough memory to
+ perform an in-memory build. Either remove the `ram` option from
+ the TAILS_BUILD_OPTIONS environment variable, or shut the
+ virtual machine down using `rake vm:halt` before trying again.
+
+ END_OF_MESSAGE
+ abort 'Not enough memory for the virtual machine to run an in-memory build. Aborting.'
+ end
end
result = env.cli('up')
abort "'vagrant up' failed" unless result
diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile
index cc035c9..8e9ee6c 100644
--- a/vagrant/Vagrantfile
+++ b/vagrant/Vagrantfile
@@ -20,6 +20,13 @@
# Monkey-patched Vagrant!
$:.unshift File.expand_path('../lib', __FILE__)
require 'vagrant_verified_download'
+require 'tails_build_settings'
+
+if ENV['TAILS_RAM_BUILD']
+ mem_size = VM_MEMORY_FOR_RAM_BUILDS
+else
+ mem_size = VM_MEMORY_FOR_DISK_BUILDS
+end
Vagrant::Config.run do |config|
config.vm.box = 'tails'
@@ -30,4 +37,6 @@ Vagrant::Config.run do |config|
config.vm.provision :shell, :inline => "http_proxy='#{ENV['http_proxy']}' /vagrant/provision/setup-tails-builder"
config.vm.share_folder 'amnesia', '/amnesia.git', '../.git'
+
+ config.vm.customize ['modifyvm', :id, '--memory', mem_size]
end
diff --git a/vagrant/lib/tails_build_settings.rb b/vagrant/lib/tails_build_settings.rb
index 714dfa2..c645ff9 100644
--- a/vagrant/lib/tails_build_settings.rb
+++ b/vagrant/lib/tails_build_settings.rb
@@ -19,3 +19,9 @@
# Hostname of the virtual machine (must be in /etc/hosts)
VIRTUAL_MACHINE_HOSTNAME = 'squeeze.vagrantup.com'
+
+# Virtual machine memory size for in-memory builds
+VM_MEMORY_FOR_RAM_BUILDS = 6 * 1024 + 512 # 6.5 GB
+
+# Virtual machine memory size for on-disk builds
+VM_MEMORY_FOR_DISK_BUILDS = 1024 # 1 GB
diff --git a/vagrant/provision/assets/build-tails b/vagrant/provision/assets/build-tails
index f491b5d..e6d1e8d 100755
--- a/vagrant/provision/assets/build-tails
+++ b/vagrant/provision/assets/build-tails
@@ -2,6 +2,8 @@
set -e
+TMPFS_SIZE=6 # GB
+
as_root_do() {
sudo \
${RSYNC_PROXY:+RSYNC_PROXY="$RSYNC_PROXY"} \
@@ -13,6 +15,17 @@ as_root_do() {
"$@"
}
+usable_memory() {
+ free | awk '/cache:/ { print $4 }'
+}
+
+if [ "$TAILS_RAM_BUILD" ]; then
+ if [ "$(usable_memory)" -lt $(($TMPFS_SIZE * 1024 * 1024)) ]; then
+ echo "Not enough memory available for an in-memory build. Aborting." >&2
+ exit 1
+ fi
+fi
+
REV="${1:-$(git --git-dir=/amnesia.git name-rev --name-only HEAD)}"
COMMIT="$(git --git-dir=/amnesia.git rev-parse --verify "$REV")"
@@ -24,6 +37,17 @@ git fetch origin
as_root_do git checkout --force "$REV"
as_root_do git reset --hard "$COMMIT"
as_root_do lb clean || true
+
+if [ "$TAILS_RAM_BUILD" ]; then
+ BUILD_DIR=$(mktemp -d /home/vagrant/tails-build.XXXXXXXX)
+ trap "cd / ; sudo umount '$BUILD_DIR' ; sudo rmdir '$BUILD_DIR'" EXIT
+ as_root_do mount -t tmpfs -o "noatime,size=${TMPFS_SIZE}G,mode=0770,uid=root,gid=vagrant" tmpfs "$BUILD_DIR"
+
+ as_root_do rsync -a /home/vagrant/amnesia/ "$BUILD_DIR"/
+
+ cd "$BUILD_DIR"
+fi
+
as_root_do lb config
as_root_do lb build