diff --git a/bin/disk-image-create b/bin/disk-image-create index 8b607603..8cc1628d 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -48,6 +48,7 @@ function show_options () { echo " -x -- turn on tracing" echo " -u -- uncompressed; do not compress the image - larger but faster" echo " -c -- clear environment before starting work" + echo " --image-cache directory -- location for cached images (~/.cache/image-create)" echo " --min-tmpfs size -- minimum size in GB needed in tmpfs to build the image" echo " --no-tmpfs -- do not use tmpfs to speed image build" echo " --offline -- do not update cached resources" @@ -78,6 +79,7 @@ while true ; do -c) shift ; export CLEAR_ENV=1;; -n) shift; export SKIP_BASE="1";; -p) IFS="," read -a INSTALL_PACKAGES <<< "$2"; export INSTALL_PACKAGES ; shift 2 ;; + --image-cache) export DIB_IMAGE_CACHE=$2; shift 2;; --min-tmpfs) export DIB_MIN_TMPFS=$2; shift 2;; --no-tmpfs) shift; export DIB_NO_TMPFS=1;; --offline) shift; export DIB_OFFLINE=1;; @@ -86,6 +88,8 @@ while true ; do esac done +export DIB_IMAGE_CACHE=${DIB_IMAGE_CACHE:-~/.cache/image-create} + if [ "$CLEAR_ENV" = "1" -a "$HOME" != "" ]; then echo "Re-execing to clear environment." echo "(note this will prevent much of the local_config element from working)" diff --git a/elements/fedora/root.d/10-fedora-cloud-image b/elements/fedora/root.d/10-fedora-cloud-image index 6be721a3..089c1458 100755 --- a/elements/fedora/root.d/10-fedora-cloud-image +++ b/elements/fedora/root.d/10-fedora-cloud-image @@ -9,21 +9,20 @@ if [ 'amd64' = "$ARCH" ] ; then ARCH="x86_64" fi -IMG_PATH=~/.cache/image-create DIB_RELEASE=${DIB_RELEASE:-latest} DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud.fedoraproject.org} BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-fedora-$DIB_RELEASE.$ARCH.qcow2} BASE_IMAGE_TAR=$DIB_RELEASE-Cloud-$ARCH-latest.tgz -CACHED_TAR=$IMG_PATH/$BASE_IMAGE_TAR +CACHED_TAR=$DIB_IMAGE_CACHE/$BASE_IMAGE_TAR if [ -n "$DIB_OFFLINE" -a -f "$CACHED_TAR" ] ; then echo "Not checking freshness of cached $CACHED_TAR." else echo "Fetching Base Image" - $TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $IMG_PATH/$BASE_IMAGE_FILE + $TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE if [ ! -f $CACHED_TAR -o \ - $IMG_PATH/$BASE_IMAGE_FILE -nt $CACHED_TAR ] ; then + $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE -nt $CACHED_TAR ] ; then echo "Repacking base image as tarball." WORKING=$(mktemp -d) EACTION="rm -r $WORKING" @@ -31,7 +30,7 @@ else echo "Working in $WORKING" RAW_FILE=$(basename $BASE_IMAGE_FILE) RAW_FILE=${RAW_FILE#.qcow2}.raw - qemu-img convert -f qcow2 -O raw $IMG_PATH/$BASE_IMAGE_FILE $WORKING/$RAW_FILE + qemu-img convert -f qcow2 -O raw $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE $WORKING/$RAW_FILE # WARNING: The mattdm image has the root filesystem on the second # partition (p2). If he changes the image the MAGIC_BIT # might also need to change. @@ -56,9 +55,9 @@ else trap "$EACTION" EXIT # Chroot in so that we get the correct uid/gid sudo chroot $WORKING/mnt bin/tar -cz . > $WORKING/tmp.tar - mv $WORKING/tmp.tar $IMG_PATH/$BASE_IMAGE_TAR + mv $WORKING/tmp.tar $DIB_IMAGE_CACHE/$BASE_IMAGE_TAR fi fi # Extract the base image -sudo tar -C $TARGET_ROOT -xzf $IMG_PATH/$BASE_IMAGE_TAR +sudo tar -C $TARGET_ROOT -xzf $DIB_IMAGE_CACHE/$BASE_IMAGE_TAR sudo rmdir $TARGET_ROOT/lost+found diff --git a/elements/rhel/root.d/10-rhel-cloud-image b/elements/rhel/root.d/10-rhel-cloud-image index bfeee889..b50494ea 100755 --- a/elements/rhel/root.d/10-rhel-cloud-image +++ b/elements/rhel/root.d/10-rhel-cloud-image @@ -9,28 +9,27 @@ if [ 'amd64' = "$ARCH" ] ; then ARCH="x86_64" fi -IMG_PATH=~/.cache/image-create DIB_RELEASE=${DIB_RELEASE:-latest} DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://rhn.redhat.com} BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-rhel-server-x86_64-kvm-6.4_20130130.0-4.qcow2} BASE_IMAGE_TAR=$DIB_RELEASE-rhel-server-$ARCH-latest.tgz -CACHED_TAR=$IMG_PATH/$BASE_IMAGE_TAR +CACHED_TAR=$DIB_IMAGE_CACHE/$BASE_IMAGE_TAR if [ -n "$DIB_OFFLINE" -a -f "$CACHED_TAR" ] ; then echo "Not checking freshness of cached $CACHED_TAR." else echo "Fetching Base Image" - $TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $IMG_PATH/$BASE_IMAGE_FILE + $TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE if [ ! -f $CACHED_TAR -o \ - $IMG_PATH/$BASE_IMAGE_FILE -nt $CACHED_TAR ] ; then + $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE -nt $CACHED_TAR ] ; then echo "Repacking base image as tarball." WORKING=$(mktemp -d) EACTION="rm -r $WORKING" trap "$EACTION" EXIT RAW_FILE=$(basename $BASE_IMAGE_FILE) RAW_FILE=${RAW_FILE#.qcow2}.raw - qemu-img convert -f qcow2 -O raw $IMG_PATH/$BASE_IMAGE_FILE $WORKING/$RAW_FILE + qemu-img convert -f qcow2 -O raw $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE $WORKING/$RAW_FILE MAGIC_BIT=p1 # NOTE: On RHEL, partprobe of /dev/loop0 does not create /dev/loop0p2, # while kpartx at least creates /dev/mapper/loop0p2. @@ -49,9 +48,9 @@ else trap "$EACTION" EXIT # Chroot in so that we get the correct uid/gid sudo chroot $WORKING/mnt bin/tar -cz . > $WORKING/tmp.tar - mv $WORKING/tmp.tar $IMG_PATH/$BASE_IMAGE_TAR + mv $WORKING/tmp.tar $DIB_IMAGE_CACHE/$BASE_IMAGE_TAR fi fi # Extract the base image -sudo tar -C $TARGET_ROOT -xzf $IMG_PATH/$BASE_IMAGE_TAR +sudo tar -C $TARGET_ROOT -xzf $DIB_IMAGE_CACHE/$BASE_IMAGE_TAR sudo rmdir $TARGET_ROOT/lost+found diff --git a/elements/ubuntu/root.d/10-cache-ubuntu-tarball b/elements/ubuntu/root.d/10-cache-ubuntu-tarball index c190fb69..23593d4d 100755 --- a/elements/ubuntu/root.d/10-cache-ubuntu-tarball +++ b/elements/ubuntu/root.d/10-cache-ubuntu-tarball @@ -8,23 +8,22 @@ set -eu shopt -s extglob -IMG_PATH=~/.cache/image-create DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud-images.ubuntu.com/} DIB_RELEASE=${DIB_RELEASE:-raring} BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-$DIB_RELEASE-server-cloudimg-$ARCH-root.tar.gz} SHA256SUMS=${SHA256SUMS:-https://${DIB_CLOUD_IMAGES##http?(s)://}/$DIB_RELEASE/current/SHA256SUMS} -CACHED_FILE=$IMG_PATH/$BASE_IMAGE_FILE +CACHED_FILE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE if [ -n "$DIB_OFFLINE" -a -f "$CACHED_FILE" ] ; then echo "Not checking freshness of cached $CACHED_FILE." else echo "Fetching Base Image" - $TMP_HOOKS_PATH/bin/cache-url $SHA256SUMS $IMG_PATH/SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH + $TMP_HOOKS_PATH/bin/cache-url $SHA256SUMS $DIB_IMAGE_CACHE/SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH $TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$DIB_RELEASE/current/$BASE_IMAGE_FILE $CACHED_FILE - pushd $IMG_PATH + pushd $DIB_IMAGE_CACHE grep "$BASE_IMAGE_FILE" SHA256SUMS.ubuntu.$DIB_RELEASE.$ARCH | sha256sum --check - popd fi # Extract the base image -sudo tar -C $TARGET_ROOT -xzf $IMG_PATH/$BASE_IMAGE_FILE +sudo tar -C $TARGET_ROOT -xzf $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE sudo rmdir $TARGET_ROOT/lost+found