X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=scripts%2Fbuild_inf_centos%2Fbuild_inf_centos.sh;h=a7664b286b6d0b8e342bfc614a5f24953ddbc397;hb=37efbaa4fd4bc6016ab52a0efd8138794725105c;hp=ddb29f398a7747825d7873f6b333715bc79971f3;hpb=84ec2b862e9c8ae827c1eb841733cb479d021e73;p=pti%2Frtp.git diff --git a/scripts/build_inf_centos/build_inf_centos.sh b/scripts/build_inf_centos/build_inf_centos.sh index ddb29f3..a7664b2 100755 --- a/scripts/build_inf_centos/build_inf_centos.sh +++ b/scripts/build_inf_centos/build_inf_centos.sh @@ -22,10 +22,16 @@ set -e -o pipefail ######################################################################### SRC_ORAN_BRANCH="master" +SRC_O2_BRANCH="master" SRC_ORAN_URL="https://gerrit.o-ran-sc.org/r/pti/rtp" +SRC_O2_URL="https://opendev.org/starlingx/app-oran-o2" + +STX_VER="7.0" +ORAN_REL="ORAN H-Release (${STX_VER})" SCRIPTS_DIR=$(dirname $(readlink -f $0)) +SCRIPTS_NAME=$(basename $0) TIMESTAMP=`date +"%Y%m%d_%H%M%S"` ######################################################################### @@ -35,11 +41,11 @@ TIMESTAMP=`date +"%Y%m%d_%H%M%S"` help_info () { cat << ENDHELP Usage: -$(basename $0) [-w WORKSPACE_DIR] [-n] [-u] [-h] +${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-m] [-n] [-u] [-h] where: -w WORKSPACE_DIR is the path for the project + -m use mirror for src and rpm pkgs -n dry-run only for bitbake - -u update the repo if it exists -h this help info examples: $0 @@ -50,14 +56,14 @@ ENDHELP echo_step_start() { [ -n "$1" ] && msg_step=$1 echo "#########################################################################################" - echo "## STEP START: ${msg_step}" + echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}" echo "#########################################################################################" } echo_step_end() { [ -n "$1" ] && msg_step=$1 echo "#########################################################################################" - echo "## STEP END: ${msg_step}" + echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}" echo "#########################################################################################" echo } @@ -82,8 +88,9 @@ run_cmd () { ######################################################################### DRYRUN="" +USE_MIRROR="No" -while getopts "w:b:e:r:unh" OPTION; do +while getopts "w:mnh" OPTION; do case ${OPTION} in w) WORKSPACE=`readlink -f ${OPTARG}` @@ -91,9 +98,9 @@ while getopts "w:b:e:r:unh" OPTION; do n) DRYRUN="-n" ;; - u) - SKIP_UPDATE="No" - ;; + m) + USE_MIRROR="Yes" + ;; h) help_info exit @@ -111,7 +118,7 @@ fi ######################################################################### PRJ_NAME=prj_oran_stx_centos -STX_SRC_BRANCH="r/stx.6.0" +STX_SRC_BRANCH="r/stx.${STX_VER}" STX_LOCAL_DIR=${WORKSPACE}/localdisk STX_LOCAL_SRC_DIR=${STX_LOCAL_DIR}/designer/${USER}/${PRJ_NAME} STX_LOCAL_PRJ_DIR=${STX_LOCAL_DIR}/loadbuild/${USER}/${PRJ_NAME} @@ -121,8 +128,16 @@ STX_PRJ_OUTPUT=${WORKSPACE}/prj_output STX_MIRROR_DIR=${WORKSPACE}/mirror STX_MANIFEST_URL="https://opendev.org/starlingx/manifest" +MIRROR_SRC_STX=infbuilder/inf-src-stx:${STX_VER} +MIRROR_CONTAINER_IMG=infbuilder/inf-centos-mirror:2022.11-stx-${STX_VER} + +SRC_ORAN_DIR=${STX_SRC_DIR}/rtp +SRC_META_PATCHES=${SRC_ORAN_DIR}/scripts/build_inf_centos/meta-patches + +ISO_INF_COS=inf-image-centos-all-x86-64.iso + prepare_workspace () { - msg_step="Create workspace for the build" + msg_step="Create workspace for the CentOS build" echo_step_start mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} ${STX_PRJ_OUTPUT} @@ -139,7 +154,7 @@ prepare_workspace () { } create_env () { - msg_step="Create env file for the build" + msg_step="Create env file for the CentOS build" echo_step_start ENV_FILENAME=env.${PRJ_NAME} @@ -215,6 +230,9 @@ repo_init_sync () { msg_step="Init the repo and sync" echo_step_start + # Avoid the colorization prompt + git config --global color.ui false + cd ${MY_REPO_ROOT_DIR} STX_MANIFEST="default.xml" if [ "$LAYER" != "" ]; then @@ -230,80 +248,171 @@ repo_init_sync () { echo_step_end } -create_build_docker () { - msg_step="Create build environment docker container" +get_mirror_src () { + msg_step="Get src mirror from dockerhub image" echo_step_start - cd ${MY_REPO_ROOT_DIR}/stx-tools/ - export PATH=$PATH:$PWD - - echo "MYUNAME=${USER}" > localrc - echo "PROJECT=${PRJ_NAME}" >> localrc - echo "HOST_PREFIX=${WORKSPACE}" >> localrc - echo "HOST_MIRROR_DIR=${WORKSPACE}/mirror" >> localrc - echo "LAYER=${LAYER}" >> localrc - echo "MY_EMAIL=jackie.huang@windriver.com" >> localrc + if [ -d ${MY_REPO_ROOT_DIR}/.repo ]; then + echo_info "The src repos already exists, skipping" + else + docker pull ${MIRROR_SRC_STX} + docker create -ti --name inf-src-stx ${MIRROR_SRC_STX} sh + docker cp inf-src-stx:/stx-${STX_VER}.tar.bz2 ${MY_REPO_ROOT_DIR} + docker rm inf-src-stx + + cd ${MY_REPO_ROOT_DIR} + tar xf stx-${STX_VER}.tar.bz2 + mv stx-${STX_VER}/* stx-${STX_VER}/.repo . + rm -rf stx-${STX_VER} stx-${STX_VER}.tar.bz2 + fi - # workarounds - #git checkout master - #sed -i 's/docker /sudo docker /' tb.sh + echo_step_end +} - #RUN_CMD="tb.sh create" - #run_cmd "Create build environment docker image" +get_mirror_pkg () { + msg_step="Get rpm mirror from dockerhub image" + echo_step_start - RUN_CMD="tb.sh run" - run_cmd "Create build environment docker container" + docker pull ${MIRROR_CONTAINER_IMG} + docker create -ti --name inf-centos-mirror ${MIRROR_CONTAINER_IMG} sh + docker cp inf-centos-mirror:/mirror_stx-${STX_VER}/. ${STX_MIRROR_DIR} + docker rm inf-centos-mirror echo_step_end } -exec_build_docker () { - msg_step="Enter a bash shell within the build environment container" +clone_update_repo () { + REPO_BRANCH=$1 + REPO_URL=$2 + REPO_NAME=$3 + REPO_COMMIT=$4 + + if [ -d ${REPO_NAME}/.git ]; then + if [ "${SKIP_UPDATE}" == "Yes" ]; then + echo_info "The repo ${REPO_NAME} exists, skip updating for the branch ${REPO_BRANCH}" + else + echo_info "The repo ${REPO_NAME} exists, updating for the branch ${REPO_BRANCH}" + cd ${REPO_NAME} + git checkout ${REPO_BRANCH} + git pull + cd - + fi + else + RUN_CMD="git clone --branch ${REPO_BRANCH} ${REPO_URL} ${REPO_NAME}" + run_cmd "Cloning the source of repo '${REPO_NAME}':" + + if [ -n "${REPO_COMMIT}" ]; then + cd ${REPO_NAME} + RUN_CMD="git checkout -b ${REPO_BRANCH}-${REPO_COMMIT} ${REPO_COMMIT}" + run_cmd "Checkout the repo ${REPO_NAME} to specific commit: ${REPO_COMMIT}" + cd - + fi + fi +} + + +prepare_src () { + msg_step="Get the source code repos" echo_step_start - cd ${MY_REPO_ROOT_DIR}/stx-tools/ - export PATH=$PATH:$PWD + # Clone the oran inf source if it's not already cloned + # Check if the script is inside the repo + if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then + CLONED_ORAN_REPO=`git rev-parse --show-toplevel` + echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}" + mkdir -p ${SRC_ORAN_DIR} + cd ${SRC_ORAN_DIR} + rm -rf scripts + ln -sf ${CLONED_ORAN_REPO}/scripts scripts + else + echo_info "Cloning oran layer:" + cd ${STX_SRC_DIR} + clone_update_repo ${SRC_ORAN_BRANCH} ${SRC_ORAN_URL} rtp + fi - RUN_CMD="tb.sh exec" - run_cmd "Enter a bash shell within the build environment container" + if [ "${USE_MIRROR}" == "Yes" ]; then + get_mirror_src + get_mirror_pkg + else + repo_init_sync + get_mirror_pkg + fi + patch_src - #cd $MY_REPO_ROOT_DIR/stx-tools/centos-mirror-tools/ - #RUN_CMD="sudo -E ./download_mirror.sh" - #run_cmd "Download rpms" + cd ${STX_SRC_DIR}/cgcs-root/stx/ + clone_update_repo ${SRC_O2_BRANCH} ${SRC_O2_URL} app-oran-o2 echo_step_end } -# To be removed: -# This build script can not successfully build out the image yet, -# get the upstream image temporary so we can still test the CI job to -# upload the image to nexus -ISO_STX_COS=bootimage.iso -ISO_UP_VER=6.0.0 -ISO_UP=http://mirror.starlingx.cengn.ca/mirror/starlingx/release/${ISO_UP_VER}/centos/flock/outputs/iso/${ISO_STX_COS} -ISO_INF_COS=inf-image-centos-all-x86-64.iso +patch_src () { + echo_step_start "Patching source codes for INF project" + + STX_PXE_DATA="${MY_REPO}/stx/metal/installer/pxe-network-installer/centos/build_srpm.data" + echo_info "Patching for the ${STX_PXE_DATA}" + sed -i "s|/import/mirrors|${STX_MIRROR_DIR}|" ${STX_PXE_DATA} + + STX_ISSUE_DIR="${MY_REPO}/stx/config-files/centos-release-config/files" + echo_info "Patching for the ${STX_ISSUE_DIR}" + grep -q "${ORAN_REL}" ${STX_ISSUE_DIR}/issue* \ + || sed -i "s/\(@PLATFORM_RELEASE@\)/\1 - ${ORAN_REL}/" ${STX_ISSUE_DIR}/issue* + + # Apply meta patches + cd ${SRC_META_PATCHES} + src_dirs=$(find . -type f -printf "%h\n"|uniq) + for d in ${src_dirs}; do + cd ${MY_REPO_ROOT_DIR}/${d} + + # backup current branch + local_branch=$(git rev-parse --abbrev-ref HEAD) + if [ "${local_branch}" = "HEAD" ]; then + git checkout ${STX_SRC_BRANCH} + local_branch=$(git rev-parse --abbrev-ref HEAD) + fi + git branch -m "${local_branch}_${TIMESTAMP}" + git checkout ${STX_SRC_BRANCH} + + for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do + echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}" + git am ${SRC_META_PATCHES}/${d}/${p} + done + done + echo_step_end +} + +populate_dl () { + ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/generate-centos-repo.sh ${STX_MIRROR_DIR}/stx-${STX_VER} + ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/populate_downloads.sh ${STX_MIRROR_DIR}/stx-${STX_VER} +} build_image () { echo_step_start "Build CentOS images" mkdir -p ${STX_PRJ_OUTPUT} - cd ${STX_PRJ_OUTPUT} - wget ${ISO_UP} -O ${ISO_INF_COS} + cd ${MY_BUILD_DIR} + RUN_CMD="build-pkgs --build-avoidance" + run_cmd "Build pkgs" + + # The first run always fail + build-iso || sleep 60 + + RUN_CMD="build-iso" + run_cmd "Build ISO image" + + cp -f ${MY_BUILD_DIR}/export/bootimage.iso ${STX_PRJ_OUTPUT}/${ISO_INF_COS} echo_step_end echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_COS}" } - ######################################################################### # Main process ######################################################################### prepare_workspace create_env -#repo_init_sync -#create_build_docker -#exec_build_docker +prepare_src +populate_dl build_image