4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 LIBDIR="$(dirname $(readlink -f ${BASH_SOURCE[0]}))"
21 PUBLISH_RESULTS="${PUBLISH_RESULTS:-false}"
22 VIRT_CUSTOMIZE_MEM="${VIRT_CUSTOMIZE_MEM:-}"
23 VIRT_CUSTOMIZE_SMP="${VIRT_CUSTOMIZE_SMP:-}"
24 PARALLEL_BUILD_TIMEOUT="${PARALLEL_BUILD_TIMEOUT:-0}"
25 ENABLE_GOLDEN_IMAGE_ROOT_PASSWORD="${ENABLE_GOLDEN_IMAGE_ROOT_PASSWORD:-true}"
26 GOLDEN_BASE_IMAGE_TAR_URL=${GOLDEN_BASE_IMAGE_TAR_URL:-}
27 GOLDEN_BASE_IMAGE_FETCH_USER=${GOLDEN_BASE_IMAGE_FETCH_USER:-}
28 GOLDEN_BASE_IMAGE_FETCH_PASSWORD=${GOLDEN_BASE_IMAGE_FETCH_PASSWORD:-}
30 WORK=$(dirname $(dirname $LIBDIR))
31 RPM_BUILDER=$(find $WORK -maxdepth 2 -type d -name rpmbuilder)
34 WORKLOGS=$WORKTMP/logs
35 DURATION_LOG=$WORKLOGS/durations.log
36 MANIFEST_PATH=$WORK/.repo/manifests
37 BUILD_CONFIG_INI=$WORK/.repo/manifests/build_config.ini
38 GOLDEN_IMAGE_NAME=guest-image.img
39 TMP_GOLDEN_IMAGE=$WORKTMP/$GOLDEN_IMAGE_NAME
41 WORKRESULTS=$WORK/results
42 REPO_FILES=$WORKRESULTS/repo_files
43 REPO_DIR=$WORKRESULTS/repo
44 SRC_REPO_DIR=$WORKRESULTS/src_repo
45 RPMLISTS=$WORKRESULTS/rpmlists
46 CHECKSUM_DIR=$WORKRESULTS/bin_checksum
47 RESULT_IMAGES_DIR=$WORKRESULTS/images
48 RPM_BUILDER_SETTINGS=$WORKTMP/mocksettings/mock.cfg
50 function _read_build_config()
52 local config_ini=$BUILD_CONFIG_INI
53 if [[ -f "$1" ]] && [[ $1 == *.ini ]]; then
57 PYTHONPATH=$LIBDIR $LIBDIR/tools/script/read_build_config.py $config_ini $@
60 function _read_manifest_vars()
62 PRODUCT_RELEASE_BUILD_ID="${BUILD_NUMBER:?0}"
63 PRODUCT_RELEASE_LABEL="$(_read_build_config DEFAULT product_release_label)"
66 function _initialize_work_dirs()
69 mkdir -p $WORKRESULTS $REPO_FILES $REPO_DIR $RPMLISTS $CHECKSUM_DIR
70 # dont clear tmp, can be used for caching
88 _info "##################################################################"
90 _info "##################################################################"
96 _info "------------------------------------------------------------------"
102 _header "STEP START: $@"
115 _header "STEP OK: $@"
121 _info "[cmd-start]: $@"
122 stamp_start=$(date +%s)
123 time $@ 2>&1 || _abort "Command failed: $@"
124 stamp_end=$(date +%s)
125 echo "$((stamp_end - stamp_start)) $@" >> $DURATION_LOG.unsorted
126 sort -nr $DURATION_LOG.unsorted > $DURATION_LOG
131 function _run_cmd_as_step()
133 if [ $# -eq 1 -a -f $1 ]; then
134 step="$(basename $1)"
144 function _add_rpms_to_repo()
149 cp -f $(repomanage --keep=1 --new $rpm_dir) $repo_dir/
152 function _create_localrepo()
155 _run_cmd createrepo --workers=8 --update .
158 _run_cmd createrepo --workers=8 --update .
162 function _add_rpms_to_repos_from_workdir()
164 _add_rpms_to_repo $REPO_DIR $1/buildrepository/mock/rpm
165 _add_rpms_to_repo $SRC_REPO_DIR $1/buildrepository/mock/srpm
166 #find $1/ -name '*.tar.gz' | xargs rm -f
170 function _publish_results()
174 mkdir -p $(dirname $to)
178 function _publish_image()
180 _publish_results $1 $2
184 function _create_checksum()
186 _create_md5_checksum $1
187 _create_sha256_checksum $1
190 function _create_sha256_checksum()
193 time sha256sum $(basename $1) > $(basename $1).sha256
197 function _create_md5_checksum()
200 time md5sum $(basename $1) > $(basename $1).md5
206 # e.g. for Jenkins boolean parameters
210 function _join_array()
217 function _get_package_list()
219 PYTHONPATH=$LIBDIR $LIBDIR/tools/script/read_package_config.py $@
222 function _load_docker_image()
224 local docker_image=$1
225 local docker_image_url="$(_read_build_config DEFAULT docker_images)/${docker_image}.tar"
226 if docker inspect ${docker_image} &> /dev/null; then
227 echo "Using already built ${docker_image} image"
229 echo "Loading ${docker_image} image"
230 curl -L $docker_image_url | docker load