diff --git a/build_image b/build_image index 09a7eedb84..c3eac64783 100755 --- a/build_image +++ b/build_image @@ -34,6 +34,9 @@ DEFINE_string usb_disk /dev/sdb4 \ DEFINE_string enable_serial "" \ "Enable serial port for printks. Example values: ttyS0" +# include upload options +. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1 + FLAGS_HELP="USAGE: build_image [flags] [list of images to build]. This script is used to build a CoreOS image. CoreOS comes in many different forms. This scripts can be used to build the following: @@ -86,6 +89,8 @@ eval set -- "${FLAGS_ARGV}" # so will die prematurely if 'switch_to_strict_mode' is specified before now. switch_to_strict_mode +check_gsutil_opts + # N.B. Ordering matters for some of the libraries below, because # some of the files contain initialization used by later files. . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 @@ -146,6 +151,7 @@ mkdir -p "${BUILD_DIR}" # Create the base image. create_base_image ${PRISTINE_IMAGE_NAME} ${FLAGS_enable_rootfs_verification} \ ${FLAGS_enable_bootcache} +upload_image "${BUILD_DIR}/${PRISTINE_IMAGE_NAME}" # Running board-specific setup if any exists. if type board_setup &>/dev/null; then @@ -157,22 +163,26 @@ if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \ ${CHROMEOS_TEST_IMAGE_NAME}; then copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${CHROMEOS_DEVELOPER_IMAGE_NAME} install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME} + upload_image "${BUILD_DIR}/${CHROMEOS_DEVELOPER_IMAGE_NAME}" fi if should_build_image ${COREOS_PRODUCTION_IMAGE_NAME}; then copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${COREOS_PRODUCTION_IMAGE_NAME} ${SCRIPTS_DIR}/bin/cros_make_image_bootable "${BUILD_DIR}" \ ${COREOS_PRODUCTION_IMAGE_NAME} + upload_image "${BUILD_DIR}/${COREOS_PRODUCTION_IMAGE_NAME}" fi # From a developer image create a test|factory_test image. if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} mod_image_for_test ${CHROMEOS_TEST_IMAGE_NAME} + upload_image "${BUILD_DIR}/${CHROMEOS_TEST_IMAGE_NAME}" fi # Generating AU generator zip file to run outside chroot generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." +upload_image "${BUILD_DIR}/au-generator.zip" # Create a named symlink. LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}" diff --git a/build_library/release_util.sh b/build_library/release_util.sh index ba669107df..c36ad0101d 100644 --- a/build_library/release_util.sh +++ b/build_library/release_util.sh @@ -9,6 +9,9 @@ if [[ ${COREOS_OFFICIAL:-0} -eq 1 ]]; then UPLOAD_DEFAULT=${FLAGS_TRUE} fi +IMAGE_ZIPPER="lbzip2 --compress --keep" +IMAGE_ZIPEXT=".bz2" + DEFINE_boolean parallel ${FLAGS_TRUE} \ "Enable parallelism in gsutil." DEFINE_boolean upload ${UPLOAD_DEFAULT} \ @@ -35,3 +38,43 @@ upload_packages() { info "Uploading packages" gsutil ${GSUTIL_OPTS} cp -R "${BOARD_PACKAGES}"/* "${UPLOAD_PATH}" } + +make_digests() { + local dirname=$(dirname "$1") + local filename=$(basename "$1") + cd "${dirname}" + 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" + done + cd - +} + +upload_image() { + [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]] || return 0 + [[ -n "${BOARD}" ]] || die "board_options.sh must be sourced first" + + local BUILT_IMAGE="$1" + local UPLOAD_PATH="${UPLOAD_ROOT}/${BOARD}/${COREOS_VERSION_STRING}/" + + if [[ ! -f "${BUILT_IMAGE}" ]]; then + die "Image '${BUILT_IMAGE}' 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}" + fi + + # 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}" + + info "Uploading ${BUILT_IMAGE##*/}" + gsutil ${GSUTIL_OPTS} cp "${BUILT_IMAGE}" \ + "${BUILT_IMAGE}.DIGESTS" "${UPLOAD_PATH}" +}