summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Rakefile11
-rwxr-xr-xvagrant/provision/assets/build-tails37
2 files changed, 47 insertions, 1 deletions
diff --git a/Rakefile b/Rakefile
index 9a4f4b6..3c9fe33 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
@@ -32,7 +33,7 @@ VAGRANT_PATH = File.expand_path('../vagrant', __FILE__)
STABLE_BRANCH_NAMES = ['stable', 'testing']
# Environment variables that will be exported to the build script
-EXPORTED_VARIABLES = ['http_proxy', 'MKSQUASHFS_OPTIONS', 'TAILS_RAM_BUILD', 'TAILS_CLEAN_BUILD']
+EXPORTED_VARIABLES = ['http_proxy', 'MKSQUASHFS_OPTIONS', 'TAILS_RAM_BUILD', 'TAILS_CLEAN_BUILD', 'TAILS_BOOTSTRAP_CACHE']
# Let's save the http_proxy set before playing with it
EXTERNAL_HTTP_PROXY = ENV['http_proxy']
@@ -89,6 +90,9 @@ task :parse_build_options do
# Use in-VM proxy unless an external proxy is set
options += 'vmproxy ' unless EXTERNAL_HTTP_PROXY
+ # Use bootstrap cache by default
+ options += 'cache '
+
# Default to fast compression on development branches
options += 'gzipcomp ' unless stable_branch?
@@ -105,6 +109,11 @@ task :parse_build_options do
ENV['TAILS_RAM_BUILD'] = '1'
when 'noram'
ENV['TAILS_RAM_BUILD'] = nil
+ # Bootstrap cache settings
+ when 'cache'
+ ENV['TAILS_BOOTSTRAP_CACHE'] = '1'
+ when 'nocache'
+ ENV['TAILS_BOOTSTRAP_CACHE'] = nil
# HTTP proxy settings
when 'extproxy'
abort "No HTTP proxy set, but one is required by TAILS_BUILD_OPTIONS. Aborting." unless EXTERNAL_HTTP_PROXY
diff --git a/vagrant/provision/assets/build-tails b/vagrant/provision/assets/build-tails
index 4547734..8c3e274 100755
--- a/vagrant/provision/assets/build-tails
+++ b/vagrant/provision/assets/build-tails
@@ -20,6 +20,15 @@ usable_memory() {
free -b | awk '/cache:/ { print $4 }'
}
+bootstrap_stage_is_ok() {
+ [ -d "$1" ] || return 1
+ [ "$(sudo du -sm $1 | cut -f1)" -ge 100 ] || return 1
+ for dir in bin dev etc lib proc root sbin sys usr var; do
+ [ -d "$1/$dir" ] || return 1
+ done
+ return 0
+}
+
cleanup() {
cd /
mounts=$(mount | grep -E "^[^[:space:]]+ on $BUILD_DIR" | \
@@ -51,6 +60,9 @@ as_root_do git reset --hard "$COMMIT"
if [ "$TAILS_CLEAN_BUILD" ]; then
as_root_do lb clean --all
+ for dir in /var/cache/stages_bootstrap /var/cache/packages_bootstrap; do
+ [ -d "$dir" ] && sudo rm -rf $dir
+ done
fi
as_root_do ./build-wiki
@@ -65,6 +77,31 @@ fi
cd "$BUILD_DIR"
as_root_do lb config
+
+if [ "$TAILS_BOOTSTRAP_CACHE" ]; then
+ sudo mkdir -p "$BUILD_DIR"/cache/packages_bootstrap
+ sudo mkdir -p /var/cache/packages_bootstrap
+ sudo mount --bind /var/cache/packages_bootstrap \
+ "$BUILD_DIR"/cache/packages_bootstrap
+
+ if bootstrap_stage_is_ok /var/cache/stages_bootstrap; then
+ # restore bootstrap stage and make live-build use it
+ sudo mkdir -p "$BUILD_DIR"/cache/stages_bootstrap
+ sudo mount --bind /var/cache/stages_bootstrap \
+ "$BUILD_DIR"/cache/stages_bootstrap
+ sudo touch "$BUILD_DIR"/.stage/bootstrap
+ sudo touch "$BUILD_DIR"/.stage/bootstrap_cache.save
+ fi
+fi
+
as_root_do lb build
mv -f tails-* /vagrant
+
+if [ "$TAILS_BOOTSTRAP_CACHE" ] && \
+ ! sudo umount "$BUILD_DIR"/cache/stages_bootstrap 2>/dev/null; then
+ # the cached bootstrap stage wasn't used (maybe it hadn't been
+ # cached yet?) so we we save the good one from the current build.
+ sudo rsync -a --delete "$BUILD_DIR"/cache/stages_bootstrap/ \
+ /var/cache/stages_bootstrap
+fi