Add docker output support

We can already produce tarballs, which is the input format docker import
expects. This makes it trivial to add docker as an output format.

Co-Authored-By: Dan Prince <dprince@redhat.com>

Change-Id: Ib60db3b717d33d4cf3181d70fe0ffbfa86fd5d02
This commit is contained in:
Monty Taylor 2015-06-07 16:44:10 -04:00 committed by Gregory Haynes
parent 7aab6c63c2
commit 1187f9d5df
3 changed files with 46 additions and 13 deletions

View File

@ -45,7 +45,7 @@ function show_options () {
echo "Options:" echo "Options:"
echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)" echo " -a i386|amd64|armhf -- set the architecture of the image(default amd64)"
echo " -o imagename -- set the imagename of the output image file(default image)" echo " -o imagename -- set the imagename of the output image file(default image)"
echo " -t qcow2,tar,vhd,raw -- set the image types of the output image files (default qcow2)" echo " -t qcow2,tar,vhd,docker,raw -- set the image types of the output image files (default qcow2)"
echo " File types should be comma separated. VHD outputting requires the vhd-util" echo " File types should be comma separated. VHD outputting requires the vhd-util"
echo " executable be in your PATH." echo " executable be in your PATH."
echo " -x -- turn on tracing" echo " -x -- turn on tracing"
@ -71,6 +71,7 @@ function show_options () {
echo " Defaults to 'ramdisk'. Should be set to 'dracut-ramdisk' for platforms such" echo " Defaults to 'ramdisk'. Should be set to 'dracut-ramdisk' for platforms such"
echo " as RHEL and CentOS that do not package busybox." echo " as RHEL and CentOS that do not package busybox."
echo " --install-type -- specify the default installation type. Defaults to 'source'. Set to 'package' to use package based installations by default." echo " --install-type -- specify the default installation type. Defaults to 'source'. Set to 'package' to use package based installations by default."
echo " --docker-target -- specify the repo and tag to use if the output type is docker. Defaults to the value of output imagename"
if [ "$IS_RAMDISK" == "0" ]; then if [ "$IS_RAMDISK" == "0" ]; then
echo " -n skip the default inclusion of the 'base' element" echo " -n skip the default inclusion of the 'base' element"
echo " -p package[,package,package] -- list of packages to install in the image" echo " -p package[,package,package] -- list of packages to install in the image"
@ -102,7 +103,8 @@ COMPRESS_IMAGE="true"
export DIB_ROOT_LABEL="" export DIB_ROOT_LABEL=""
DIB_DEFAULT_INSTALLTYPE=${DIB_DEFAULT_INSTALLTYPE:-"source"} DIB_DEFAULT_INSTALLTYPE=${DIB_DEFAULT_INSTALLTYPE:-"source"}
MKFS_OPTS="" MKFS_OPTS=""
TEMP=`getopt -o a:ho:t:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize:,mkfs-options:,qemu-img-options:,ramdisk-element:,root-label:,install-type: -n $SCRIPTNAME -- "$@"` DOCKER_TARGET=""
TEMP=`getopt -o a:ho:t:xucnp: -l no-tmpfs,offline,help,min-tmpfs:,image-size:,image-cache:,max-online-resize:,mkfs-options:,qemu-img-options:,ramdisk-element:,root-label:,install-type:,docker-target: -n $SCRIPTNAME -- "$@"`
if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi if [ $? -ne 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential! # Note the quotes around `$TEMP': they are essential!
@ -130,6 +132,7 @@ while true ; do
--root-label) export DIB_ROOT_LABEL=$2; shift 2;; --root-label) export DIB_ROOT_LABEL=$2; shift 2;;
--ramdisk-element) RAMDISK_ELEMENT=$2; shift 2;; --ramdisk-element) RAMDISK_ELEMENT=$2; shift 2;;
--install-type) DIB_DEFAULT_INSTALLTYPE=$2; shift 2;; --install-type) DIB_DEFAULT_INSTALLTYPE=$2; shift 2;;
--docker-target) export DOCKER_TARGET=$2; shift 2 ;;
--) shift ; break ;; --) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;; *) echo "Internal error!" ; exit 1 ;;
esac esac
@ -179,6 +182,16 @@ for X in ${!IMAGE_TYPES[@]}; do
exit 1 exit 1
fi fi
;; ;;
docker)
if [ -z "$(which docker)" ]; then
echo "docker output format specified but no docker executable found."
exit 1
fi
if [ -z "$DOCKER_TARGET" ]; then
echo "Please set --docker-target."
exit 1
fi
;;
esac esac
done done
@ -271,6 +284,11 @@ for X in ${!IMAGE_TYPES[@]} ; do
--exclude ./proc --xattrs --xattrs-include=\* . --exclude ./proc --xattrs --xattrs-include=\* .
sudo chown $USER: $IMAGE_NAME.tar sudo chown $USER: $IMAGE_NAME.tar
unset IMAGE_TYPES[$X] unset IMAGE_TYPES[$X]
elif [ "${IMAGE_TYPES[$X]}" == "docker" ]; then
sudo tar -C ${TMP_BUILD_DIR}/mnt -cf - --exclude ./sys \
--exclude ./proc --xattrs --xattrs-include=\* . \
| docker import - $DOCKER_TARGET
unset IMAGE_TYPES[$X]
fi fi
done done

View File

@ -5,11 +5,13 @@ set -o pipefail
source $(dirname $0)/test_functions.bash source $(dirname $0)/test_functions.bash
test_formats="tar raw qcow2" test_formats="tar raw qcow2 docker"
if [ -z "$(which qemu-img)" ]; then for binary in qemu-img docker ; do
echo "Warning: No qemu-img binary found, cowardly refusing to run tests." if [ -z "$(which $binary)" ]; then
exit 0 echo "Warning: No $binary binary found, cowardly refusing to run tests."
fi exit 0
fi
done
for format in '' $test_formats; do for format in '' $test_formats; do
build_test_image $format build_test_image $format

View File

@ -12,25 +12,38 @@ function build_test_image() {
format="qcow2" format="qcow2"
fi fi
dest_dir=$(mktemp -d) dest_dir=$(mktemp -d)
base_dest=$(basename $dest_dir)
trap "rm -rf $dest_dir" EXIT trap "rm -rf $dest_dir" EXIT
trap "docker rmi $base_dest/image" EXIT
ELEMENTS_PATH=$DIB_ELEMENTS:$TEST_ELEMENTS \ ELEMENTS_PATH=$DIB_ELEMENTS:$TEST_ELEMENTS \
$DIB_CMD -x $type_arg -o $dest_dir/image -n fake-os $DIB_CMD -x $type_arg --docker-target=$base_dest/image \
-o $dest_dir/image -n fake-os
format=$(echo $format | tr ',' ' ') format=$(echo $format | tr ',' ' ')
for format in $format; do for format in $format; do
img_path="$dest_dir/image.$format" if [ $format != 'docker' ]; then
if ! [ -f "$img_path" ]; then img_path="$dest_dir/image.$format"
echo "Error: No image with name $img_path found!" if ! [ -f "$img_path" ]; then
exit 1 echo "Error: No image with name $img_path found!"
exit 1
else
echo "Found image $img_path."
fi
else else
echo "Found image $img_path." if ! docker image | grep $base_dest/image ; then
echo "Error: No docker image with name $base_dest/image found!"
exit 1
else
echo "Found docker image $base_dest/image"
fi
fi fi
done done
trap EXIT trap EXIT
rm -rf $dest_dir rm -rf $dest_dir
docker rmi $base_dest/image
} }
function run_element_test() { function run_element_test() {