mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-07 21:16:57 +02:00
feat(image_to_vm): Add support for uploading vm images
After this I can make production AMI images available for download! :-D
This commit is contained in:
parent
ca0b25028e
commit
c5cd245603
@ -85,40 +85,50 @@ upload_packages() {
|
||||
|
||||
make_digests() {
|
||||
local dirname=$(dirname "$1")
|
||||
local filename=$(basename "$1")
|
||||
local basename=$(basename "$1")
|
||||
|
||||
cd "${dirname}"
|
||||
echo -n > "${basename}.DIGESTS"
|
||||
for filename in "$@"; do
|
||||
filename=$(basename "$filename")
|
||||
info "Computing DIGESTS for ${filename}"
|
||||
echo -n > "${filename}.DIGESTS"
|
||||
for hash in md5 sha1 sha512; do
|
||||
echo "# $hash HASH" | tr "a-z" "A-Z" >> "${filename}.DIGESTS"
|
||||
${hash}sum "${filename}" >> "${filename}.DIGESTS"
|
||||
echo "# $hash HASH" | tr "a-z" "A-Z" >> "${basename}.DIGESTS"
|
||||
${hash}sum "${filename}" >> "${basename}.DIGESTS"
|
||||
done
|
||||
done
|
||||
cd -
|
||||
}
|
||||
|
||||
# Upload a image along with optional supporting files
|
||||
# The image file must be the first argument
|
||||
upload_image() {
|
||||
[[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]] || return 0
|
||||
[[ -n "${BOARD}" ]] || die "board_options.sh must be sourced first"
|
||||
|
||||
local BUILT_IMAGE="$1"
|
||||
|
||||
if [[ ! -f "${BUILT_IMAGE}" ]]; then
|
||||
die "Image '${BUILT_IMAGE}' does not exist!"
|
||||
local uploads=()
|
||||
local filename
|
||||
for filename in "$@"; do
|
||||
if [[ ! -f "${filename}" ]]; then
|
||||
die "File '${filename}' does not exist!"
|
||||
fi
|
||||
|
||||
# Compress raw images
|
||||
if [[ "${BUILT_IMAGE}" =~ \.(img|bin)$ ]]; then
|
||||
info "Compressing ${BUILT_IMAGE##*/}"
|
||||
$IMAGE_ZIPPER "${BUILT_IMAGE}"
|
||||
BUILT_IMAGE="${BUILT_IMAGE}${IMAGE_ZIPEXT}"
|
||||
# Compress disk images
|
||||
if [[ "${filename}" =~ \.(img|bin|vdi|vmdk)$ ]]; then
|
||||
info "Compressing ${filename##*/}"
|
||||
$IMAGE_ZIPPER -f "${filename}"
|
||||
uploads+=( "${filename}${IMAGE_ZIPEXT}" )
|
||||
else
|
||||
uploads+=( "${filename}" )
|
||||
fi
|
||||
done
|
||||
|
||||
# For consistency generate a .DIGESTS file similar to the one catalyst
|
||||
# produces for the SDK tarballs and up upload it too.
|
||||
make_digests "${BUILT_IMAGE}"
|
||||
make_digests "${uploads[@]}"
|
||||
uploads+=( "${uploads[0]}.DIGESTS" )
|
||||
|
||||
local log_msg="${BUILT_IMAGE##*/}"
|
||||
local log_msg="${1##*/}"
|
||||
local def_upload_path="${UPLOAD_ROOT}/${BOARD}/${COREOS_VERSION_STRING}"
|
||||
upload_files "${log_msg}" "${def_upload_path}" "" \
|
||||
"${BUILT_IMAGE}" "${BUILT_IMAGE}.DIGESTS"
|
||||
upload_files "${log_msg}" "${def_upload_path}" "" "${uploads[@]}"
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ VM_README=
|
||||
VM_NAME=
|
||||
VM_UUID=
|
||||
|
||||
# Contains a list of all generated files
|
||||
VM_GENERATED_FILES=()
|
||||
|
||||
## DEFAULT
|
||||
# If set to 1 use a hybrid GPT/MBR format instead of plain GPT
|
||||
IMG_DEFAULT_HYBRID_MBR=0
|
||||
@ -228,8 +231,9 @@ write_vm_disk() {
|
||||
fi
|
||||
|
||||
local disk_format=$(_get_vm_opt DISK_FORMAT)
|
||||
info "Writing $disk_format image to $(relpath "${VM_DST_IMG}")"
|
||||
info "Writing $disk_format image $(basename "${VM_DST_IMG}")"
|
||||
_write_${disk_format}_disk "${VM_TMP_IMG}" "${VM_DST_IMG}"
|
||||
VM_GENERATED_FILES+=( "${VM_DST_IMG}" )
|
||||
}
|
||||
|
||||
_write_hybrid_mbr() {
|
||||
@ -319,6 +323,8 @@ qemu-system-x86_64 -curses -m ${vm_mem} -readconfig "${conf_path##*/}"
|
||||
SSH into that host with:
|
||||
ssh 127.0.0.1 -p 2222
|
||||
EOF
|
||||
|
||||
VM_GENERATED_FILES+=( "${conf_path}" "${VM_README}" )
|
||||
}
|
||||
|
||||
# Generate the vmware config file
|
||||
@ -346,6 +352,7 @@ guestOS = "otherlinux"
|
||||
ethernet0.addressType = "generated"
|
||||
floppy0.present = "FALSE""
|
||||
EOF
|
||||
VM_GENERATED_FILES+=( "${vmx_path}" )
|
||||
}
|
||||
|
||||
# Generate a new-style (xl) Xen config file for both pvgrub and pygrub
|
||||
@ -393,6 +400,7 @@ xl console ${VM_NAME}
|
||||
Kill the vm with:
|
||||
xl destroy ${VM_NAME}
|
||||
EOF
|
||||
VM_GENERATED_FILES+=( "${pygrub}" "${pvgrub}" "${VM_README}" )
|
||||
}
|
||||
|
||||
vm_cleanup() {
|
||||
@ -401,6 +409,12 @@ vm_cleanup() {
|
||||
}
|
||||
|
||||
print_readme() {
|
||||
local filename
|
||||
info "Files written to $(relpath "$(dirname "${VM_DST_IMG}")")"
|
||||
for filename in "${VM_GENERATED_FILES[@]}"; do
|
||||
info " - $(basename "${filename}")"
|
||||
done
|
||||
|
||||
if [[ -f "${VM_README}" ]]; then
|
||||
cat "${VM_README}"
|
||||
fi
|
||||
|
@ -52,6 +52,9 @@ DEFINE_boolean prod_image "${FLAGS_FALSE}" \
|
||||
DEFINE_string to "" \
|
||||
"Destination folder for VM output file(s)"
|
||||
|
||||
# include upload options
|
||||
. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1
|
||||
|
||||
# Parse command line
|
||||
FLAGS "$@" || exit 1
|
||||
eval set -- "${FLAGS_ARGV}"
|
||||
@ -116,6 +119,9 @@ write_vm_conf "${FLAGS_mem}"
|
||||
vm_cleanup
|
||||
trap - EXIT
|
||||
|
||||
# Optionally upload all of our hard work
|
||||
upload_image "${VM_GENERATED_FILES[@]}"
|
||||
|
||||
# Ready to set sail!
|
||||
okboat
|
||||
command_completed
|
||||
|
Loading…
Reference in New Issue
Block a user