d51f8050cd
Script changes to download content by layer. Valid options are 'all', 'compiler', 'distro', 'flock'. Current .lst and yum files under directory centos-mirror-tools are relocated. Generic package dependencies are relocated to centos-mirror-tools/config/<os>/<layer>/ . Lst entries for compilable content have been relocated to other git repos by prior updates. i.e. those that list tarballs or srpms to be compiled within that repo. The original .lst files are deleted to make it easier to identify new content during development. Layer 'all' builds all layers in a single workspace. The lst files are identical to current content, minus the src.rpm and tarball entries. Other layers get only a subset of packages download. The minimum required to build the layer. The 'flock' layer will have additional content to satisfy the run time requirements as well as the build time requirements. An upper layer does not need to list rpms known to be provided by a lower layer. Instead the config file 'required_layer_pkgs.cfg' lists urls for lst files for lower layer build outputs. These build outputs are generated and published by cengn for each layer. A second layer config file, 'required_layer_iso_inc.cfg' lists image.inc files for lower layer builds. These build outputs are generated and published by cengn for each layer, summarizing the image.inc files found in individual git repos. Image.inc files inform the build-iso process, listing rpms that that provide services and commands that need to be included in the iso. The transitive list of required rpms need not be listed. Finally the layer config should include a yum.repos.d directory in which supplementary yum repos are defined to pick up cengn built content from lower layers. To allow a designer to do cross-layer building using local sources rather than those provided by CENGN, there are several options. The designer can modify the urls for lower layer build outputs, as found in the .cfg and .repo files within the config directory 'stx-tools/centos-mirror-tools/config/<distro>/<layer-to-build>' directly within the git. Substitute urls can use the file:/// syntax. Just be sure to remove these changes before submitting. Alternatively new args have been added to download_mirror.sh, generate-cgcs-centos-repo.sh and commands that override the normal config. The easiest to use is a command argurement that substitutes a new config directory, replacing stx-tools/centos-mirror-tools/config. The intent is for the designer to do a recursive copy of that directory into a side location. make his changes there, outside of git, and provide the path to that directory as an extra arguement to download_mirror.sh and generate-cgcs-centos-repo.sh. e.g. For simplicity I'll only list the 'extra' arguements download_mirror.sh -C <my-config-dir> \ -l <layer> \ ... generate-cgcs-centos-repo.sh --config-dir=<my-config-dir> \ --layer=<layer> \ ... populate_downloads.sh --config-dir=<my-config-dir> \ --layer=<layer> \ ... These arguements can also be suplied via the environment. For the purpose of containerized builds, these arguements should be defined in your localrc. e.g. export STX_CONFIG_DIR=<my-config-dir> export LAYER=<layer> The final alternative is to override things at a more granular level, replacing a single lst file of image.inc file. Here you can replace a single line found in a required_layer_pkgs.cfg or required_layer_iso_inc.cfg file. e.g. We are doing a flock build and want to modify the content picked up from the distro layer's rt build, and that content delivers a service we want in the iso. For simplicity I'll only list the 'extra' arguments ./download_mirror.sh -l flock \ -L distro,rt,file:///<my-distro-workspace>/rt/rpmbuild/RPMS/rpm.lst \ -I distro,std,file:///<my-distro-workspace>/rt/image.inc \ ... generate-cgcs-centos-repo.sh --layer=flock \ --layer-pkg-url=distro,rt,file:///<my-distro-workspace>/rt/rpmbuild/RPMS/rpm.lst \ --layer-inc-url=distro,std,file:////<my-distro-workspace>/rt/image.inc \ ... NOTE: The triplet syntax for a package list url is <lower-layer>,<build-type>,<url-to-rpm.lst> lower-layer: 'compiler', 'distro' build-type: 'std', 'rt', 'installer' Also if 'file:///' syntax is used, a matching change is made to the yum *.repo file. This assumes that the rpm.lst is co-resident with repodata directory, as is the norm for our build outputs. NOTE: The triplet syntax for a image inc url is <lower-layer>,<include-type>,<url-to-image.inc> lower-layer: 'compiler', 'distro' build-type: 'std', 'dev' A typical user is likely only working in the flock layer on the master branch. He should be content to use the compiler and distro layer outputs from cengn. His workflow looks like ... 1, sync code for flock layer $ repo init -u https://opendev.org/starlingx/manifest.git -b master -m flock.xml $ repo sync 2, download rpms for flock layer, and populate a local mirror $ LOCAL_MIRROR=/import/mirrors/starlingx $ cd stx-tools/centos-mirror-tools $ ./download_mirror.sh -n -g -c yum.conf.sample -S -l flock $ cp -r output/stx-r1/CentOS/pike/* $LOCAL_MIRROR/ 3, Prepare a virtual repo and downloads directory for building $ cd ../toCOPY $ ./generate-cgcs-centos-repo.sh --layer=flock $LOCAL_MIRROR $ ./populate_downloads.sh --layer=flock $LOCAL_MIRROR 4, rpm package and iso building $ build-pkgs && build-iso && build-helm-charts.sh Building all layers in a single workspace is still supported, and looks identical to the previous workflow. 1, sync code $ repo init -u https://opendev.org/starlingx/manifest.git -b master $ repo sync 2, download rpms for flock layer, and populate a local mirror $ LOCAL_MIRROR=/import/mirrors/starlingx $ cd stx-tools/centos-mirror-tools $ ./download_mirror.sh -n -g -c yum.conf.sample -S $ cp -r output/stx-r1/CentOS/pike/* $LOCAL_MIRROR/ 3, create repo named "StxCentos7Distro" for building $ cd ../toCOPY $ generate-cgcs-centos-repo.sh $LOCAL_MIRROR $ populate_downloads.sh $LOCAL_MIRROR 4, rpm package and iso building $ build-pkgs && build-iso && build-helm-charts.sh Only a cross-layer developer should setup two or three copies of the building environment, one per layer. We suggest you use seperate shells for each layer, as the various paths (MY_REPO, MY_WORKSPACE ...) need to be unique, Shell 1, compiler layer $ LOCAL_MIRROR=/import/mirrors/starlingx $ LOCAL_CONFIG=<some-dir>/config $ MY_REPO_ROOT_DIR=<some-dir>/layer-compiler $ MY_REPO=$MY_REPO_ROOT_DIR/cgcs-root $ MY_WORKSPACE=$MY_REPO_ROOT_DIR/workspace ... $ mkdir -p $MY_REPO_ROOT_DIR $ cd $MY_REPO_ROOT_DIR $ repo init -u https://opendev.org/starlingx/manifest.git -b master -m compiler.xml $ cd stx-tools/centos-mirror-tools $ cp -r config/* $LOCAL_CONFIG ... edit urls in *.cfg and *.repo files under $LOCAL_CONFIG ... $ ./download_mirror.sh -n -g -c yum.conf.sample -S -C $LOCAL_CONFIG -l compiler $ cp -r output/stx-r1/CentOS/pike/* $LOCAL_MIRROR/ $ cd ../toCOPY $ ./generate-cgcs-centos-repo.sh --config-dir=$LOCAL_CONFIG --layer=compiler $LOCAL_MIRROR $ ./populate_downloads.sh --config-dir=$LOCAL_CONFIG --layer=flock $LOCAL_MIRROR $ build-pkgs Shell 2, distro layer $ LOCAL_MIRROR=/import/mirrors/starlingx $ LOCAL_CONFIG=<some-dir>/config $ MY_REPO_ROOT_DIR=<some-dir>/layer-distro $ MY_REPO=$MY_REPO_ROOT_DIR/cgcs-root $ MY_WORKSPACE=$MY_REPO_ROOT_DIR/workspace ... $ mkdir -p $MY_REPO_ROOT_DIR $ cd $MY_REPO_ROOT_DIR $ repo init -u https://opendev.org/starlingx/manifest.git -b master -m distro.xml $ repo sync $ cd stx-tools/centos-mirror-tools $ ./download_mirror.sh -n -g -c yum.conf.sample -S -C $LOCAL_CONFIG -l distro $ cp -r output/stx-r1/CentOS/pike/* $LOCAL_MIRROR/ $ cd ../toCOPY $ ./generate-cgcs-centos-repo.sh --config-dir=$LOCAL_CONFIG --layer=distro $LOCAL_MIRROR $ ./populate_downloads.sh --config-dir=$LOCAL_CONFIG --layer=flock $LOCAL_MIRROR $ build-pkgs Shell 3, flock layer $ LOCAL_MIRROR=/import/mirrors/starlingx $ LOCAL_CONFIG=<some-dir>/config $ MY_REPO_ROOT_DIR=<some-dir>/layer-flock $ MY_REPO=$MY_REPO_ROOT_DIR/cgcs-root $ MY_WORKSPACE=$MY_REPO_ROOT_DIR/workspace ... $ mkdir -p $MY_REPO_ROOT_DIR $ cd $MY_REPO_ROOT_DIR $ repo init -u https://opendev.org/starlingx/manifest.git -b master -m flock.xml $ repo sync $ cd stx-tools/centos-mirror-tools $ ./download_mirror.sh -n -g -c yum.conf.sample -S -C $LOCAL_CONFIG -l flock $ cp -r output/stx-r1/CentOS/pike/* $LOCAL_MIRROR/ $ cd ../toCOPY $ ./generate-cgcs-centos-repo.sh --config-dir=$LOCAL_CONFIG --layer=flock $LOCAL_MIRROR $ ./populate_downloads.sh --config-dir=$LOCAL_CONFIG --layer=flock $LOCAL_MIRROR $ build-pkgs && build-iso && build-helm-charts.sh Story: 2006166 Task: 37103 Depends-On: https://review.opendev.org/698756 Depends-On: https://review.opendev.org/700819 Depends-On: https://review.opendev.org/700821 Change-Id: I088020b81f08656e50aa29b5584bbc1dd1378f12 Signed-off-by: Scott Little <scott.little@windriver.com>
287 lines
7.7 KiB
Bash
Executable File
287 lines
7.7 KiB
Bash
Executable File
#!/bin/bash -e
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# download RPMs/SRPMs from different sources.
|
|
# this script was originated by Brian Avery, and later updated by Yong Hu
|
|
|
|
set -o errexit
|
|
set -o nounset
|
|
|
|
# By default, we use "sudo" and we don't use a local yum.conf. These can
|
|
# be overridden via flags.
|
|
|
|
SUDOCMD="sudo -E"
|
|
RELEASEVER="--releasever=7"
|
|
YUMCONFOPT=""
|
|
|
|
DL_RPMS_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
|
|
|
|
source $DL_RPMS_DIR/utils.sh
|
|
|
|
usage() {
|
|
echo "$0 [-n] [-c <yum.conf>] <rpms_list> <match_level> "
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -n: Do not use sudo when performing operations"
|
|
echo " -c: Use an alternate yum.conf rather than the system file"
|
|
echo " -x: Clean log files only, do not run."
|
|
echo " rpm_list: a list of RPM files to be downloaded."
|
|
echo " match_level: value could be L1, L2 or L3:"
|
|
echo " L1: use name, major version and minor version:"
|
|
echo " vim-7.4.160-2.el7 to search vim-7.4.160-2.el7.src.rpm"
|
|
echo " L2: use name and major version:"
|
|
echo " using vim-7.4.160 to search vim-7.4.160-2.el7.src.rpm"
|
|
echo " L3: use name:"
|
|
echo " using vim to search vim-7.4.160-2.el7.src.rpm"
|
|
echo " K1: Use Koji rather than yum repos as a source."
|
|
echo " Koji has a longer retention period than epel mirrors."
|
|
echo ""
|
|
echo "Returns: 0 = All files downloaded successfully"
|
|
echo " 1 = Some files could not be downloaded"
|
|
echo " 2 = Bad arguements or other error"
|
|
echo ""
|
|
}
|
|
|
|
|
|
CLEAN_LOGS_ONLY=0
|
|
dl_rc=0
|
|
|
|
# Permitted values of dl_source
|
|
dl_from_stx_mirror="stx_mirror"
|
|
dl_from_upstream="upstream"
|
|
dl_from_stx_then_upstream="$dl_from_stx_mirror $dl_from_upstream"
|
|
dl_from_upstream_then_stx="$dl_from_upstream $dl_from_stx_mirror"
|
|
|
|
# Download from what source?
|
|
# dl_from_stx_mirror = StarlingX mirror only
|
|
# dl_from_upstream = Original upstream source only
|
|
# dl_from_stx_then_upstream = Either source, STX prefered (default)"
|
|
# dl_from_upstream_then_stx = Either source, UPSTREAM prefered"
|
|
dl_source="$dl_from_stx_then_upstream"
|
|
dl_flag=""
|
|
|
|
distro="centos"
|
|
|
|
MULTIPLE_DL_FLAG_ERROR_MSG="Error: Please use only one of: -s,-S,-u,-U"
|
|
|
|
multiple_dl_flag_check () {
|
|
if [ "$dl_flag" != "" ]; then
|
|
echo "$MULTIPLE_DL_FLAG_ERROR_MSG"
|
|
usage
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Parse option flags
|
|
while getopts "c:nxD:sSuUh" o; do
|
|
case "${o}" in
|
|
n)
|
|
# No-sudo
|
|
SUDOCMD=""
|
|
;;
|
|
x)
|
|
# Clean only
|
|
CLEAN_LOGS_ONLY=1
|
|
;;
|
|
c)
|
|
# Use an alternate yum.conf
|
|
YUMCONFOPT="-c $OPTARG"
|
|
grep -q "releasever=" $OPTARG && RELEASEVER="--$(grep releasever= ${OPTARG})"
|
|
;;
|
|
D)
|
|
distro="${OPTARG}"
|
|
;;
|
|
|
|
s)
|
|
# Download from StarlingX mirror only. Do not use upstream sources.
|
|
multiple_dl_flag_check
|
|
dl_source="$dl_from_stx_mirror"
|
|
dl_flag="-s"
|
|
;;
|
|
S)
|
|
# Download from StarlingX mirror only. Do not use upstream sources.
|
|
multiple_dl_flag_check
|
|
dl_source="$dl_from_stx_then_upstream"
|
|
dl_flag="-S"
|
|
;;
|
|
u)
|
|
# Download from upstream only. Do not use StarlingX mirror.
|
|
multiple_dl_flag_check
|
|
dl_source="$dl_from_upstream"
|
|
dl_flag="-u"
|
|
;;
|
|
U)
|
|
# Download from upstream only. Do not use StarlingX mirror.
|
|
multiple_dl_flag_check
|
|
dl_source="$dl_from_upstream_then_stx"
|
|
dl_flag="-U"
|
|
;;
|
|
|
|
h)
|
|
# Help
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
usage
|
|
exit 2
|
|
;;
|
|
esac
|
|
done
|
|
shift $((OPTIND-1))
|
|
|
|
if [ $# -lt 2 ]; then
|
|
usage
|
|
exit 2
|
|
fi
|
|
|
|
if [ "$1" == "" ]; then
|
|
echo "Need to supply the rpm file list"
|
|
exit 2;
|
|
else
|
|
rpms_list=$1
|
|
echo "using $rpms_list as the download name lists"
|
|
fi
|
|
|
|
match_level="L1"
|
|
|
|
if [ ! -z "$2" -a "$2" != " " ];then
|
|
match_level=$2
|
|
fi
|
|
|
|
timestamp=$(date +%F_%H%M)
|
|
echo $timestamp
|
|
|
|
export DL_MIRROR_LOG_DIR="${DL_MIRROR_LOG_DIR:-./logs}"
|
|
export DL_MIRROR_OUTPUT_DIR="${DL_MIRROR_OUTPUT_DIR:-./output/stx-r1/CentOS/pike}"
|
|
|
|
MDIR_SRC="${DL_MIRROR_OUTPUT_DIR}/Source"
|
|
mkdir -p "$MDIR_SRC"
|
|
MDIR_BIN="${DL_MIRROR_OUTPUT_DIR}/Binary"
|
|
mkdir -p "$MDIR_BIN"
|
|
|
|
LOGSDIR="${DL_MIRROR_LOG_DIR}"
|
|
from=$(get_from $rpms_list)
|
|
LOG="$LOGSDIR/${match_level}_failmoved_url_${from}.log"
|
|
MISSING_SRPMS="$LOGSDIR/${match_level}_srpms_missing_${from}.log"
|
|
MISSING_RPMS="$LOGSDIR/${match_level}_rpms_missing_${from}.log"
|
|
FOUND_SRPMS="$LOGSDIR/${match_level}_srpms_found_${from}.log"
|
|
FOUND_RPMS="$LOGSDIR/${match_level}_rpms_found_${from}.log"
|
|
cat /dev/null > $LOG
|
|
cat /dev/null > $MISSING_SRPMS
|
|
cat /dev/null > $MISSING_RPMS
|
|
cat /dev/null > $FOUND_SRPMS
|
|
cat /dev/null > $FOUND_RPMS
|
|
|
|
|
|
if [ $CLEAN_LOGS_ONLY -eq 1 ];then
|
|
exit 0
|
|
fi
|
|
|
|
# Function to download different types of RPMs in different ways
|
|
download () {
|
|
local _file=$1
|
|
local _level=$2
|
|
local _list=""
|
|
local _from=""
|
|
|
|
local _arch=""
|
|
|
|
local rc=0
|
|
local download_cmd=""
|
|
local download_url=""
|
|
local rpm_name=""
|
|
local SFILE=""
|
|
local lvl
|
|
local dl_result
|
|
|
|
_list=$(cat $_file)
|
|
_from=$(get_from $_file)
|
|
|
|
echo "now the rpm will come from: $_from"
|
|
for ff in $_list; do
|
|
_arch=$(get_arch_from_rpm $ff)
|
|
rpm_name="$(get_rpm_name $ff)"
|
|
dest_dir="$(get_dest_directory $_arch)"
|
|
|
|
if [ ! -e $dest_dir/$rpm_name ]; then
|
|
dl_result=1
|
|
for dl_src in $dl_source; do
|
|
case $dl_src in
|
|
$dl_from_stx_mirror)
|
|
lvl=$dl_from_stx_mirror
|
|
;;
|
|
$dl_from_upstream)
|
|
lvl=$_level
|
|
;;
|
|
*)
|
|
echo "Error: Unknown dl_source '$dl_src'"
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
download_cmd="$(get_download_cmd $ff $lvl)"
|
|
|
|
echo "Looking for $rpm_name"
|
|
echo "--> run: $download_cmd"
|
|
if $download_cmd ; then
|
|
download_url="$(get_url $ff $lvl)"
|
|
SFILE="$(get_rpm_level_name $rpm_name $lvl)"
|
|
process_result "$_arch" "$dest_dir" "$download_url" "$SFILE"
|
|
dl_result=0
|
|
break
|
|
else
|
|
echo "Warning: $rpm_name not found"
|
|
fi
|
|
done
|
|
|
|
if [ $dl_result -eq 1 ]; then
|
|
echo "Error: $rpm_name not found"
|
|
echo "missing_srpm:$rpm_name" >> $LOG
|
|
echo $rpm_name >> $MISSING_SRPMS
|
|
rc=1
|
|
fi
|
|
else
|
|
echo "Already have $dest_dir/$rpm_name"
|
|
fi
|
|
echo
|
|
done
|
|
|
|
return $rc
|
|
}
|
|
|
|
|
|
# Prime the cache
|
|
loop_count=0
|
|
max_loop_count=5
|
|
echo "${SUDOCMD} yum ${YUMCONFOPT} ${RELEASEVER} makecache"
|
|
while ! ${SUDOCMD} yum ${YUMCONFOPT} ${RELEASEVER} makecache ; do
|
|
# To protect against intermittent 404 errors, we'll retry
|
|
# a few times. The suspected issue is pulling repodata
|
|
# from multiple source that are temporarily inconsistent.
|
|
loop_count=$((loop_count + 1))
|
|
if [ $loop_count -gt $max_loop_count ]; then
|
|
break
|
|
fi
|
|
echo "makecache retry: $loop_count"
|
|
|
|
# Wipe the inconsistent data from the last try
|
|
echo "yum ${YUMCONFOPT} ${RELEASEVER} clean all"
|
|
yum ${YUMCONFOPT} ${RELEASEVER} clean all
|
|
done
|
|
|
|
|
|
# Download files
|
|
if [ -s "$rpms_list" ];then
|
|
echo "--> start searching $rpms_list"
|
|
download $rpms_list $match_level
|
|
if [ $? -ne 0 ]; then
|
|
dl_rc=1
|
|
fi
|
|
fi
|
|
|
|
echo "Done!"
|
|
|
|
exit $dl_rc
|