From 5600c9f0d98f620c5ac57f24cd3c8fffee9d0a47 Mon Sep 17 00:00:00 2001 From: Scott Wittenburg Date: Mon, 17 Dec 2018 17:40:16 -0700 Subject: release workflow: Add build scripts for jobs and means to upload pkgs --- bin/rebuild-index.sh | 13 ++ bin/rebuild-package.sh | 316 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 329 insertions(+) create mode 100755 bin/rebuild-index.sh create mode 100755 bin/rebuild-package.sh (limited to 'bin') diff --git a/bin/rebuild-index.sh b/bin/rebuild-index.sh new file mode 100755 index 0000000000..09e14a9cee --- /dev/null +++ b/bin/rebuild-index.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +set -x + +SPACK_BIN_DIR="${CI_PROJECT_DIR}/bin" +export PATH="${SPACK_BIN_DIR}:${PATH}" + +spack upload-s3 index diff --git a/bin/rebuild-package.sh b/bin/rebuild-package.sh new file mode 100755 index 0000000000..459303e95e --- /dev/null +++ b/bin/rebuild-package.sh @@ -0,0 +1,316 @@ +#!/bin/bash + +# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +### +### This script represents a gitlab-ci job, corresponding to a single release +### spec. As such this script must first decide whether or not the spec it +### has been assigned is up to date on the remote binary mirror. If it is +### not (i.e. the source code has changed in a way that caused a change in the +### full_hash of the spec), this script will build the package, create a +### binary cache for it, and then push all related files to the remote binary +### mirror. This script also communicates with a remote CDash instance to +### share status on the package build process. +### +### The following environment variables are expected to be set in order for +### the various elements in this script to function properly. Listed first +### are two defaults we rely on from gitlab, then three we set up in the +### variables section of gitlab ourselves, and finally four variables +### written into the .gitlab-ci.yml file. +### +### CI_PROJECT_DIR +### CI_JOB_NAME +### +### AWS_ACCESS_KEY_ID +### AWS_SECRET_ACCESS_KEY +### SPACK_SIGNING_KEY +### +### CDASH_BASE_URL +### ROOT_SPEC +### DEPENDENCIES +### MIRROR_URL +### + +shopt -s expand_aliases + +export FORCE_UNSAFE_CONFIGURE=1 + +TEMP_DIR="${CI_PROJECT_DIR}/jobs_scratch_dir" + +JOB_LOG_DIR="${TEMP_DIR}/logs" +SPEC_DIR="${TEMP_DIR}/specs" +LOCAL_MIRROR="${CI_PROJECT_DIR}/local_mirror" +BUILD_CACHE_DIR="${LOCAL_MIRROR}/build_cache" +SPACK_BIN_DIR="${CI_PROJECT_DIR}/bin" +CDASH_UPLOAD_URL="${CDASH_BASE_URL}/submit.php?project=Spack" +DEP_JOB_RELATEBUILDS_URL="${CDASH_BASE_URL}/api/v1/relateBuilds.php" +declare -a JOB_DEPS_PKG_NAMES + +export SPACK_ROOT=${CI_PROJECT_DIR} +export PATH="${SPACK_BIN_DIR}:${PATH}" +export GNUPGHOME="${CI_PROJECT_DIR}/opt/spack/gpg" + +mkdir -p ${JOB_LOG_DIR} +mkdir -p ${SPEC_DIR} + +cleanup() { + set +x + + if [ -z "$exit_code" ] ; then + + exit_code=$1 + if [ -z "$exit_code" ] ; then + exit_code=0 + fi + + restore_io + + if [ "$( type -t finalize )" '=' 'function' ] ; then + finalize "$JOB_LOG_DIR/cdash_log.txt" + fi + + # We can clean these out later on, once we have a good sense for + # how the logging infrastructure is working + # rm -rf "$JOB_LOG_DIR" + fi + + \exit $exit_code +} + +alias exit='cleanup' + +begin_logging() { + trap "cleanup 1; \\exit \$exit_code" INT TERM QUIT + trap "cleanup 0; \\exit \$exit_code" EXIT + + rm -rf "$JOB_LOG_DIR/cdash_log.txt" + + # NOTE: Here, some redirects are set up + exec 3>&1 # fd 3 is now a dup of stdout + exec 4>&2 # fd 4 is now a dup of stderr + + # stdout and stderr are joined and redirected to the log + exec &> "$JOB_LOG_DIR/cdash_log.txt" + + set -x +} + +restore_io() { + exec >&- + exec 2>&- + + exec >&3 + exec 2>&4 + + exec 3>&- + exec 4>&- +} + +finalize() { + # If you define a finalize function: + # - it will always be called at the very end of the script + # - the log file will be passed in as the first argument, and + # - the code in this function will not be logged. + echo "The full log file is located at $1" + # TODO: send this log data to cdash! +} + +check_error() +{ + local last_exit_code=$1 + local last_cmd=$2 + if [[ ${last_exit_code} -ne 0 ]]; then + echo "${last_cmd} exited with code ${last_exit_code}" + echo "TERMINATING JOB" + exit 1 + else + echo "${last_cmd} completed successfully" + fi +} + +extract_build_id() +{ + LINES_TO_SEARCH=$1 + regex="buildSummary\.php\?buildid=([[:digit:]]+)" + SINGLE_LINE_OUTPUT=$(echo ${LINES_TO_SEARCH} | tr -d '\n') + + if [[ ${SINGLE_LINE_OUTPUT} =~ ${regex} ]]; then + echo "${BASH_REMATCH[1]}" + else + echo "NONE" + fi +} + +get_relate_builds_post_data() +{ + cat <> ${JOB_CDASH_ID_FILE} + + # TODO: The upload-s3 command should eventually be replaced with something + # like: "spack buildcache put ", when that subcommand is + # properly implemented. + spack -d upload-s3 spec --base-dir "${LOCAL_MIRROR}" --spec-yaml "${SPEC_YAML_PATH}" + check_error $? "spack upload-s3 spec" +else + echo "spec ${JOB_SPEC_NAME} is already up to date on remote mirror, downloading it" + + # Configure remote mirror so we can download buildcache entry + spack mirror add remote_binary_mirror ${MIRROR_URL} + + # Now download it + spack -d buildcache download --spec-yaml "${SPEC_YAML_PATH}" --path "${BUILD_CACHE_DIR}/" --require-cdashid + check_error $? "spack buildcache download" +fi + +# The next step is to relate this job to the jobs it depends on +if [ -f "${JOB_CDASH_ID_FILE}" ]; then + JOB_CDASH_BUILD_ID=$(<${JOB_CDASH_ID_FILE}) + + if [ "${JOB_CDASH_BUILD_ID}" == "NONE" ]; then + echo "ERROR: unable to read this jobs id from ${JOB_CDASH_ID_FILE}" + exit 1 + fi + + # Now get CDash ids for dependencies and "relate" each dependency build + # with this jobs build + for DEP_PKG_NAME in "${JOB_DEPS_PKG_NAMES[@]}"; do + echo "Getting cdash id for dependency --> ${DEP_PKG_NAME} <--" + DEP_SPEC_YAML_PATH="${SPEC_DIR}/${DEP_PKG_NAME}.yaml" + DEP_JOB_BUILDCACHE_NAME=`spack -d buildcache get-buildcache-name --spec-yaml "${DEP_SPEC_YAML_PATH}"` + + if [[ $? -eq 0 ]]; then + DEP_JOB_ID_FILE="${BUILD_CACHE_DIR}/${DEP_JOB_BUILDCACHE_NAME}.cdashid" + echo "DEP_JOB_ID_FILE path = ${DEP_JOB_ID_FILE}" + + if [ -f "${DEP_JOB_ID_FILE}" ]; then + DEP_JOB_CDASH_BUILD_ID=$(<${DEP_JOB_ID_FILE}) + echo "File ${DEP_JOB_ID_FILE} contained value ${DEP_JOB_CDASH_BUILD_ID}" + echo "Relating builds -> ${JOB_SPEC_NAME} (buildid=${JOB_CDASH_BUILD_ID}) depends on ${DEP_PKG_NAME} (buildid=${DEP_JOB_CDASH_BUILD_ID})" + relateBuildsPostBody="$(get_relate_builds_post_data "Spack" ${JOB_CDASH_BUILD_ID} ${DEP_JOB_CDASH_BUILD_ID})" + relateBuildsResult=`curl "${DEP_JOB_RELATEBUILDS_URL}" -H "Content-Type: application/json" -H "Accept: application/json" -d "${relateBuildsPostBody}"` + echo "Result of curl request: ${relateBuildsResult}" + else + echo "ERROR: Did not find expected .cdashid file for dependency: ${DEP_JOB_ID_FILE}" + exit 1 + fi + else + echo "ERROR: Unable to get buildcache entry name for ${DEP_SPEC_NAME}" + exit 1 + fi + done +else + echo "ERROR: Did not find expected .cdashid file ${JOB_CDASH_ID_FILE}" + exit 1 +fi + +# Show the size of the buildcache and a list of what's in it, directly +# in the gitlab log output +( + restore_io + du -sh ${BUILD_CACHE_DIR} + find ${BUILD_CACHE_DIR} -maxdepth 3 -type d -ls +) + +echo "End of rebuild package script" -- cgit v1.2.3-60-g2f50