fix(build_packages): Move gsutil code from build_packages to a library.

To avoid making the same gsutil changes in more scripts move the code to
a library file where some of the basic parts can be shared.
This commit is contained in:
Michael Marineau 2013-07-05 21:45:05 -04:00
parent 8af55de72c
commit 34bbdc1996
2 changed files with 43 additions and 24 deletions

View File

@ -0,0 +1,37 @@
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
GSUTIL_OPTS=
UPLOAD_ROOT="gs://storage.core-os.net/coreos"
UPLOAD_DEFAULT=${FLAGS_FALSE}
if [[ ${COREOS_OFFICIAL:-0} -eq 1 ]]; then
UPLOAD_DEFAULT=${FLAGS_TRUE}
fi
DEFINE_boolean parallel ${FLAGS_TRUE} \
"Enable parallelism in gsutil."
DEFINE_boolean upload ${UPLOAD_DEFAULT} \
"Upload all packages/images via gsutil."
check_gsutil_opts() {
[[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]] || return 0
if [[ ${FLAGS_parallel} -eq ${FLAGS_TRUE} ]]; then
GSUTIL_OPTS="-m"
fi
if [[ ! -f "$HOME/.boto" ]]; then
die_notrace "Please run gsutil config to create ~/.boto"
fi
}
upload_packages() {
[[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]] || return 0
[[ -n "${BOARD}" ]] || die "board_options.sh must be sourced first"
local BOARD_PACKAGES="${1:-"${BOARD_ROOT}/packages"}"
local UPLOAD_PATH="${UPLOAD_ROOT}/${BOARD}/${COREOS_VERSION_STRING}/pkgs/"
info "Uploading packages"
gsutil ${GSUTIL_OPTS} cp -R "${BOARD_PACKAGES}"/* "${UPLOAD_PATH}"
}

View File

@ -11,12 +11,6 @@ restart_in_chroot_if_needed "$@"
assert_not_root_user
UPLOAD_ROOT="gs://storage.core-os.net/coreos"
UPLOAD_DEFAULT=${FLAGS_FALSE}
if [[ ${COREOS_OFFICIAL:-0} -eq 1 ]]; then
UPLOAD_DEFAULT=${FLAGS_TRUE}
fi
# Developer-visible flags.
DEFINE_string board "${DEFAULT_BOARD}" \
"The board to build packages for."
@ -32,10 +26,9 @@ DEFINE_boolean withautotest "${FLAGS_TRUE}" \
"Build autotest client code."
DEFINE_boolean fetchonly "${FLAGS_FALSE}" \
"Don't build anything, instead only fetch what is needed."
DEFINE_boolean parallel ${FLAGS_TRUE} \
"Enable parallelism in gsutil."
DEFINE_boolean upload ${UPLOAD_DEFAULT} \
"Upload all packages via gsutil."
# include upload options
. "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1
FLAGS_HELP="usage: $(basename $0) [flags] [packages]
@ -95,9 +88,7 @@ if [[ -z "${FLAGS_board}" ]]; then
exit 1
fi
if [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} && ! -f "$HOME/.boto" ]]; then
die_notrace "Please run gsutil config to create ~/.boto"
fi
check_gsutil_opts
CHROMITE_BIN="${GCLIENT_ROOT}/chromite/bin"
@ -246,17 +237,8 @@ info "Merging board packages now"
tee "${tmpfile}"
)
if [[ ${FLAGS_upload} -eq ${FLAGS_TRUE} ]]; then
GSUTIL_OPTS=
if [[ ${FLAGS_parallel} -eq ${FLAGS_TRUE} ]]; then
GSUTIL_OPTS="-m"
fi
BOARD_PACKAGES="${BOARD_ROOT}/packages"
UPLOAD_PATH="${UPLOAD_ROOT}/${BOARD}/${COREOS_VERSION_STRING}/pkgs/"
info "Uploading packages"
gsutil ${GSUTIL_OPTS} cp -R "${BOARD_PACKAGES}"/* "${UPLOAD_PATH}"
fi
# upload packages if enabled
upload_packages
# Extract total package count from emerge output.
package_count=$(awk '$0 ~ /^Total: [0-9]+ packages/ { print $2 }' "${tmpfile}")