From eca59b2e973c1957f5b905daf7d8e64860a719e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Sat, 31 May 2014 15:50:52 +0200 Subject: [PATCH] dpkg: local cache for .deb files With this patch, /var/cache/apt/archives directory content is preserved. The directory is actually a bind mount of the ~/.cache/image-create/apt/$DISTRO_NAME directory, much like what we do for ccache. You can use DIB_APT_LOCAL_CACHE=0 to disable this behavior. This trivial change improve performance A LOT (>30%), even if a local HTTP proxy because: - there is no need to copy again and again the same files - we avoid network latency The patch has been tested with Debian and Ubuntu with every elements from the tripleo-image-elements repository, the final size of the cache directory is about 700MB per distribution subdirectory. Change-Id: I4fab499493f734c7c546d4d23b1a98f0e7523a39 --- elements/dpkg/README.md | 13 ++++++++++--- elements/dpkg/post-install.d/99-clean-up-cache | 4 +++- elements/dpkg/root.d/99-shared_apt_cache | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100755 elements/dpkg/root.d/99-shared_apt_cache diff --git a/elements/dpkg/README.md b/elements/dpkg/README.md index b204d425d..76f73ee49 100644 --- a/elements/dpkg/README.md +++ b/elements/dpkg/README.md @@ -7,6 +7,13 @@ can be used by any dpkg based element. The dpkg specific version of install-packages is also kept here. -If an extra or updated apt key is needed then define DIB\_ADD\_APT\_KEYS with -the path to a folder. Any key files inside will be added to the key ring before -any apt-get commands take place. +### Environment Variables ### + +* DIB\_ADD\_APT\_KEYS: If an extra or updated apt key is needed then define + DIB\_ADD\_APT\_KEYS with the path to a folder. Any key files inside will be + added to the key ring before any apt-get commands take place. +* DIB\_APT\_LOCAL\_CACHE: You can use this variable to disable the internal cache + of the /var/cache/apt/archives directory by setting it to 0. The default is to bind + mount the ~/.cache/image-create/apt/$DISTRO_NAME directory in + /var/cache/apt/archives, this to cache the .deb files downloaded during the image + creation. diff --git a/elements/dpkg/post-install.d/99-clean-up-cache b/elements/dpkg/post-install.d/99-clean-up-cache index 8046c8a0e..487c34744 100755 --- a/elements/dpkg/post-install.d/99-clean-up-cache +++ b/elements/dpkg/post-install.d/99-clean-up-cache @@ -4,4 +4,6 @@ set -eu set -o pipefail -apt-get clean +if ! mount | grep /var/cache/apt/archives; then + apt-get clean +fi diff --git a/elements/dpkg/root.d/99-shared_apt_cache b/elements/dpkg/root.d/99-shared_apt_cache new file mode 100755 index 000000000..049efc4be --- /dev/null +++ b/elements/dpkg/root.d/99-shared_apt_cache @@ -0,0 +1,16 @@ +#!/bin/bash + +set -eu +set -o pipefail + +DIB_APT_LOCAL_CACHE=${DIB_APT_LOCAL_CACHE:-1} + +if [ $DIB_APT_LOCAL_CACHE = "0" ]; then + exit 0 +fi + +apt_cache_dir=$HOME/.cache/image-create/apt/$DISTRO_NAME +if [ ! -d $apt_cache_dir ]; then + mkdir -p $apt_cache_dir +fi +sudo mount --bind $apt_cache_dir $TARGET_ROOT/var/cache/apt/archives