From 2678209e94dfbcc22e4fb7520caa5eff9ff2b15b Mon Sep 17 00:00:00 2001
From: Gregory Haynes <greg@greghaynes.net>
Date: Tue, 16 Feb 2016 07:55:19 +0000
Subject: [PATCH] Don't cache debootstrap rootfs by default

By default we create a tarball of any debootstrap rootfs we create. For
the majority of use cases this is a large performance hit for no
benefit. Lets make this an opt-in feature.

Change-Id: I58fc485aacacaa17243bf9ce760ed91256d1f182
---
 elements/debootstrap/README.rst            | 5 +++++
 elements/debootstrap/root.d/08-debootstrap | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/elements/debootstrap/README.rst b/elements/debootstrap/README.rst
index cc584e8fc..da244dda2 100644
--- a/elements/debootstrap/README.rst
+++ b/elements/debootstrap/README.rst
@@ -25,6 +25,11 @@ pass extra arguments to the debootstrap command used to create the
 base filesystem image. If --keyring is is used in `DIB_DEBOOTSTRAP_EXTRA_ARGS`,
 it will override `DIB_APT_KEYRING` if that is used as well.
 
+The `DIB_DEBOOTSTRAP_CACHE` variable can be used to cache the created root
+filesystem. By default this is 0 (disabled) and any other value enables this.
+If run in offline mode then the most recently cached rootfs is used instead of
+being built.
+
 -------------------
 Note on ARM systems
 -------------------
diff --git a/elements/debootstrap/root.d/08-debootstrap b/elements/debootstrap/root.d/08-debootstrap
index bf8e69bdb..3ccaa7e78 100755
--- a/elements/debootstrap/root.d/08-debootstrap
+++ b/elements/debootstrap/root.d/08-debootstrap
@@ -72,7 +72,9 @@ else
         ${DIB_DEBIAN_DEBOOTSTRAP_SCRIPT:-}"
 
     echo Caching debootstrap result in $DEBOOTSTRAP_TARBALL
-    sudo tar --numeric-owner -C $TARGET_ROOT -zcf $DEBOOTSTRAP_TARBALL --exclude='./tmp/*' .
+    if [ "${DIB_DEBOOTSTRAP_CACHE:-0}" != "0" ]; then
+        sudo tar --numeric-owner -C $TARGET_ROOT -zcf $DEBOOTSTRAP_TARBALL --exclude='./tmp/*' .
+    fi
 fi
 
 sudo rm -f ${TARGET_ROOT}/.extra_settings