Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct VMDK sizes when building OVA #1831

Merged
merged 3 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions installer/build/bootable/build-disks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,18 @@ function convert() {
}

function usage() {
echo "Usage: $0 -p package-location -a [create|export] 1>&2"
echo "Usage: $0 -p package-location -a [create|export] -i NAME -s SIZE -r ROOT [-i NAME -s SIZE -r ROOT]..."
echo " -p package-location the working directory to use"
echo " -a action the action to perform (create or export)"
echo " -i name the name of an image"
echo " -s size the size of an image"
echo " -r root the mount point for the root of an image, relative to the package-location"
echo "Example: $0 -p /tmp -a create -i vic-disk1.vmdk -s 6GiB -r mnt/root -i vic-disk2.vmdk -s 2GiB -r mnt/data"
echo "Example: $0 -p /tmp -a create -i vic-disk1.vmdk -i vic-disk2.vmdk -s 6GiB -s 2GiB -r mnt/root -r mnt/data"
exit 1
}

while getopts "p:a:" flag
while getopts "p:a:i:s:r:" flag
do
case $flag in

Expand All @@ -161,36 +168,34 @@ do
;;

a)
# Optional. Offline cache of yum packages
# Required. Action: create or export
ACTION="$OPTARG"
;;

i)
# Required, multi. Ordered list of image names
IMAGES+=("$OPTARG")
;;

s)
# Required, multi. Ordered list of image sizes
IMAGESIZES+=("$OPTARG")
;;

r)
# Required, multi. Ordered list of image roots
IMAGEROOTS+=("$OPTARG")
;;

*)
usage
;;
esac
done
shift $((OPTIND-1))
if [[ -n "$*" || -z "${PACKAGE}" || -z "${ACTION}" ]]; then
usage
fi

# These sizes are minimal for install, since partitions are resized to full disk space after firstboot.
IMAGESIZES=(
"6GiB"
"2GiB"
)
IMAGES=(
"vic-disk1"
"vic-disk2"
)
IMAGEROOTS=(
"${PACKAGE}/mnt/root"
"${PACKAGE}/mnt/data"
)

# check there were no extra args and the required ones are set
if [[ -n "$*" || -z "${PACKAGE}" || -z "${ACTION}" ]]; then
# check there were no extra args, the required ones are set, and an equal number of each disk argument were supplied
if [[ -n "$*" || -z "${PACKAGE}" || -z "${ACTION}" || ${#IMAGES[@]} -eq 0 || ${#IMAGES[@]} -ne ${#IMAGESIZES[@]} || ${#IMAGES[@]} -ne ${#IMAGEROOTS[@]} ]]; then
usage
fi

Expand All @@ -200,7 +205,7 @@ if [ "${ACTION}" == "create" ]; then
BOOT=""
[ "$i" == "0" ] && BOOT="1"
log2 "creating ${IMAGES[$i]}.img"
create_disk "${IMAGES[$i]}.img" "${IMAGESIZES[$i]}" "${IMAGEROOTS[$i]}" $BOOT
create_disk "${IMAGES[$i]}.img" "${IMAGESIZES[$i]}" "${PACKAGE}/${IMAGEROOTS[$i]}" $BOOT
done

elif [ "${ACTION}" == "export" ]; then
Expand All @@ -209,7 +214,7 @@ elif [ "${ACTION}" == "export" ]; then
log2 "exporting ${IMAGES[$i]}.img to ${IMAGES[$i]}.vmdk"
echo "export ${PACKAGE}/${IMAGES[$i]}"
DEV=$(losetup -l -O NAME,BACK-FILE -a | tail -n +2 | grep "${PACKAGE}/${IMAGES[$i]}" | awk '{print $1}')
convert "${DEV}" "${IMAGEROOTS[$i]}" "${IMAGES[$i]}.img" "${IMAGES[$i]}.vmdk"
convert "${DEV}" "${PACKAGE}/${IMAGEROOTS[$i]}" "${IMAGES[$i]}.img" "${IMAGES[$i]}.vmdk"
done

log2 "VMDK Sizes"
Expand All @@ -218,4 +223,4 @@ elif [ "${ACTION}" == "export" ]; then
else
usage

fi
fi
35 changes: 29 additions & 6 deletions installer/build/bootable/build-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ BASE=""
CACHE=""
MANIFEST=""

IMAGES=(
"vic-disk1"
"vic-disk2"
)
IMAGEFILES=("${IMAGES[@]/%/".vmdk"}")
# These sizes are minimal for install, since partitions are resized to full disk space after firstboot.
IMAGESIZES=(
"6GiB"
"2GiB"
)
IMAGEROOTS=(
"/mnt/root"
"/mnt/data"
)

function cleanup() {
log1 "--------------------------------------------------"
log1 "cleaning up..."
Expand Down Expand Up @@ -107,9 +122,11 @@ function build_app {
}

function main {
IMAGEARGS=("${IMAGES[@]/#/"-i"}" "${IMAGESIZES[@]/#/"-s"}" "${IMAGEROOTS[@]/#/"-r"}")

PACKAGE=$(mktemp -d)
# create disks
"${DIR}"/build-disks.sh -a "create" -p "${PACKAGE}"
"${DIR}"/build-disks.sh -a "create" -p "${PACKAGE}" "${IMAGEARGS[@]}"

# extract or build base install
log1 "Installing base os"
Expand All @@ -129,16 +146,22 @@ function main {
build_app "${PACKAGE}/mnt/root" "${PACKAGE}/mnt/data"

# package
"${DIR}"/build-disks.sh -a "export" -p "${PACKAGE}"
"${DIR}"/build-disks.sh -a "export" -p "${PACKAGE}" "${IMAGEARGS[@]}"

log1 "--------------------------------------------------"
log1 "packaging OVA..."
cp "${DIR}"/config/builder.ovf "${PACKAGE}/vic-${BUILD_OVA_REVISION}.ovf"
cd "${PACKAGE}"
sed -i -e s~--version--~${BUILD_OVA_REVISION}~ vic-${BUILD_OVA_REVISION}.ovf
log2 "updating version number"
sed -i -e "s|--version--|${BUILD_OVA_REVISION}|" vic-${BUILD_OVA_REVISION}.ovf
log2 "updating image sizes"
for image in "${IMAGEFILES[@]}"
do
sed -i -e "/<File.*${image}.*/ s|ovf:size=\"[^\"]*\"|ovf:size=\"$(stat --printf="%s" ${image})\"|" vic-${BUILD_OVA_REVISION}.ovf
done
log2 "rebuilding OVF manifest"
sha256sum --tag "vic-${BUILD_OVA_REVISION}.ovf" *.vmdk | sed s/SHA256\ \(/SHA256\(/ > "vic-${BUILD_OVA_REVISION}.mf"
tar -cvf "${RESOURCE}/vic-${BUILD_OVA_REVISION}.ova" "vic-${BUILD_OVA_REVISION}.ovf" "vic-${BUILD_OVA_REVISION}.mf" *.vmdk
sha256sum --tag "vic-${BUILD_OVA_REVISION}.ovf" "${IMAGEFILES[@]}" | sed s/SHA256\ \(/SHA256\(/ > "vic-${BUILD_OVA_REVISION}.mf"
tar -cvf "${RESOURCE}/vic-${BUILD_OVA_REVISION}.ova" "vic-${BUILD_OVA_REVISION}.ovf" "vic-${BUILD_OVA_REVISION}.mf" "${IMAGEFILES[@]}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be compressed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #1837 to track.


OUTFILE=${RESOURCE}/vic-${BUILD_OVA_REVISION}.ova

Expand Down Expand Up @@ -187,4 +210,4 @@ fi

exec 3>&1 1>>"${RESOURCE}/installer-build.log" 2>&1
log1 "Starting appliance build."
main 2> /dev/fd/3
main 2> /dev/fd/3