Merge "Add ability to use local cloud image"

This commit is contained in:
Jenkins 2014-01-30 15:51:45 +00:00 committed by Gerrit Code Review
commit 97c7e8fd5e
4 changed files with 52 additions and 20 deletions

View File

@ -6,3 +6,8 @@ Overrides:
use the environment variable DIB\_CLOUD\_IMAGES use the environment variable DIB\_CLOUD\_IMAGES
* To download a non-default release of Fedora cloud images, use the * To download a non-default release of Fedora cloud images, use the
environment variable DIB\_RELEASE environment variable DIB\_RELEASE
* Alternatively, set DIB\_LOCAL\_IMAGE to the local path of a qcow2 cloud
image. This is useful in that you can use a customized or previously built
cloud image from diskimage-builder as input. The cloud image does not have
to have been build by diskimage-builder. It should be a full disk image,
not just a filesystem image.

View File

@ -0,0 +1,5 @@
#!/bin/bash
set -eux
rm -rf /tmp/grub

View File

@ -13,7 +13,7 @@ find /tmp/yum/$basearch -regex ".*/grub2-[0-9].*\.rpm" -exec rm -f {} \;
install-packages -d grub2 install-packages -d grub2
# Copy grub2 rpm out of mounted yum cache for install during finalise # Copy grub2 rpm out of mounted yum cache for install during finalise
mkdir /tmp/grub mkdir -p /tmp/grub
cp $(find /tmp/yum/$basearch -regex ".*/grub2-[0-9].*\.rpm") /tmp/grub cp $(find /tmp/yum/$basearch -regex ".*/grub2-[0-9].*\.rpm") /tmp/grub
echo "rpm -i /tmp/grub/*.rpm" > /tmp/grub/install echo "rpm -i /tmp/grub/*.rpm" > /tmp/grub/install

View File

@ -9,32 +9,50 @@ if [ 'amd64' = "$ARCH" ] ; then
ARCH="x86_64" ARCH="x86_64"
fi fi
DIB_RELEASE=${DIB_RELEASE:-20} DIB_LOCAL_IMAGE=${DIB_LOCAL_IMAGE:-""}
DIB_CLOUD_IMAGES=${DIB_CLOUD_IMAGES:-http://cloud.fedoraproject.org}
BASE_IMAGE_FILE=${BASE_IMAGE_FILE:-fedora-$DIB_RELEASE.$ARCH.qcow2} if [ -n "$DIB_LOCAL_IMAGE" ]; then
BASE_IMAGE_TAR=$DIB_RELEASE-Cloud-$ARCH-$DIB_RELEASE.tgz IMAGE_LOCATION=$DIB_LOCAL_IMAGE
# No need to copy a local image into the cache directory, so just specify
# the cached path as the original path.
CACHED_IMAGE=$IMAGE_LOCATION
BASE_IMAGE_FILE=`basename $DIB_LOCAL_IMAGE`
BASE_IMAGE_TAR=$BASE_IMAGE_FILE.tgz
else
DIB_RELEASE=${DIB_RELEASE:-20}
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-$DIB_RELEASE.tgz
IMAGE_LOCATION=$DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE
CACHED_IMAGE=$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
fi
CACHED_TAR=$DIB_IMAGE_CACHE/$BASE_IMAGE_TAR CACHED_TAR=$DIB_IMAGE_CACHE/$BASE_IMAGE_TAR
if [ -n "$DIB_OFFLINE" -a -f "$CACHED_TAR" ] ; then if [ -n "$DIB_OFFLINE" -a -f "$CACHED_TAR" ] ; then
echo "Not checking freshness of cached $CACHED_TAR." echo "Not checking freshness of cached $CACHED_TAR."
else else
echo "Fetching Base Image"
# There seems to be some bad Fedora mirrors returning http 404's for the cloud image. if [ -z "$DIB_LOCAL_IMAGE" ]; then
# If the image fails to download due to a 404 we retry once. echo "Fetching Base Image"
set +e
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE
RV=$?
set -e
if [ "$RV" == "44" ] ; then # There seems to be some bad Fedora mirrors returning http 404's for the cloud image.
$TMP_HOOKS_PATH/bin/cache-url $DIB_CLOUD_IMAGES/$BASE_IMAGE_FILE $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE # If the image fails to download due to a 404 we retry once.
elif [ "$RV" != "0" ] ; then set +e
exit 1 $TMP_HOOKS_PATH/bin/cache-url $IMAGE_LOCATION $CACHED_IMAGE
RV=$?
set -e
if [ "$RV" == "44" ] ; then
$TMP_HOOKS_PATH/bin/cache-url $IMAGE_LOCATION $CACHED_IMAGE
elif [ "$RV" != "0" ] ; then
exit 1
fi
fi fi
if [ ! -f $CACHED_TAR -o \ if [ ! -f $CACHED_TAR -o \
$DIB_IMAGE_CACHE/$BASE_IMAGE_FILE -nt $CACHED_TAR ] ; then $CACHED_IMAGE -nt $CACHED_TAR ] ; then
echo "Repacking base image as tarball." echo "Repacking base image as tarball."
WORKING=$(mktemp -d) WORKING=$(mktemp -d)
EACTION="rm -r $WORKING" EACTION="rm -r $WORKING"
@ -42,7 +60,7 @@ else
echo "Working in $WORKING" echo "Working in $WORKING"
RAW_FILE=$(basename $BASE_IMAGE_FILE) RAW_FILE=$(basename $BASE_IMAGE_FILE)
RAW_FILE=${RAW_FILE#.qcow2}.raw RAW_FILE=${RAW_FILE#.qcow2}.raw
qemu-img convert -f qcow2 -O raw $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE $WORKING/$RAW_FILE qemu-img convert -f qcow2 -O raw $CACHED_IMAGE $WORKING/$RAW_FILE
# WARNING: The mattdm image has the root filesystem on the second # WARNING: The mattdm image has the root filesystem on the second
# partition (p2). If he changes the image the MAGIC_BIT # partition (p2). If he changes the image the MAGIC_BIT
# might also need to change. # might also need to change.
@ -70,12 +88,16 @@ else
trap "$EACTION" EXIT trap "$EACTION" EXIT
# Chroot in so that we get the correct uid/gid # Chroot in so that we get the correct uid/gid
sudo chroot $WORKING/mnt bin/tar -cz . > $WORKING/tmp.tar sudo chroot $WORKING/mnt bin/tar -cz . > $WORKING/tmp.tar
mv $WORKING/tmp.tar $DIB_IMAGE_CACHE/$BASE_IMAGE_TAR mv $WORKING/tmp.tar $CACHED_TAR
else
echo "Using cached tar from $CACHED_TAR"
fi fi
fi fi
# Extract the base image (use --numeric-owner to avoid UID/GID mismatch between # Extract the base image (use --numeric-owner to avoid UID/GID mismatch between
# image tarball and host OS e.g. when building Fedora image on an openSUSE host) # image tarball and host OS e.g. when building Fedora image on an openSUSE host)
sudo tar -C $TARGET_ROOT --numeric-owner -xzf $DIB_IMAGE_CACHE/$BASE_IMAGE_TAR echo "Extracting base root image from $CACHED_TAR"
sudo tar -C $TARGET_ROOT --numeric-owner -xzf $CACHED_TAR
if [ -e "$TARGET_ROOT/lost+found" ]; then if [ -e "$TARGET_ROOT/lost+found" ]; then
sudo rmdir $TARGET_ROOT/lost+found sudo rmdir $TARGET_ROOT/lost+found
fi fi