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