build_inf_centos.sh: update the branch for g-release
[pti/rtp.git] / scripts / build_inf_centos / build_inf_centos.sh
index 6c373b0..19997ad 100755 (executable)
@@ -21,10 +21,13 @@ set -e -o pipefail
 # Variables
 #########################################################################
 
-SRC_ORAN_BRANCH="master"
+SRC_ORAN_BRANCH="g-release"
 
 SRC_ORAN_URL="https://gerrit.o-ran-sc.org/r/pti/rtp"
 
+STX_VER="7.0"
+ORAN_REL="ORAN G-Release (${STX_VER})"
+
 SCRIPTS_DIR=$(dirname $(readlink -f $0))
 SCRIPTS_NAME=$(basename $0)
 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
@@ -36,11 +39,11 @@ TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
 help_info () {
 cat << ENDHELP
 Usage:
-${SCRIPTS_NAME} [-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
@@ -83,8 +86,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}`
@@ -92,8 +96,8 @@ while getopts "w:b:e:r:unh" OPTION; do
         n)
             DRYRUN="-n"
             ;;
-        u)
-            SKIP_UPDATE="No"
+        m)
+            USE_MIRROR="Yes"
             ;;
         h)
             help_info
@@ -112,7 +116,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}
@@ -122,8 +126,13 @@ 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_META_PATCHES=${SCRIPTS_DIR}/meta-patches
 
+ISO_INF_COS=inf-image-centos-all-x86-64.iso
+
 prepare_workspace () {
     msg_step="Create workspace for the CentOS build"
     echo_step_start
@@ -218,6 +227,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
@@ -233,11 +245,49 @@ repo_init_sync () {
     echo_step_end
 }
 
+get_mirror_src () {
+    msg_step="Get src mirror from dockerhub image"
+    echo_step_start
+
+    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
+
+    echo_step_end
+}
+
+get_mirror_pkg () {
+    msg_step="Get rpm mirror from dockerhub image"
+    echo_step_start
+
+    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
+}
+
 patch_src () {
     echo_step_start "Some source codes need to be patched for INF project"
 
     sed -i "s|/import/mirrors|${STX_MIRROR_DIR}|" \
-        $MY_REPO/stx/metal/installer/pxe-network-installer/centos/build_srpm.data
+        ${MY_REPO}/stx/metal/installer/pxe-network-installer/centos/build_srpm.data
+
+    grep -q "${ORAN_REL}" \
+        ${MY_REPO}/stx/config-files/centos-release-config/files/issue* \
+        || sed -i "s/\(@PLATFORM_RELEASE@\)/\1 - ${ORAN_REL}/" \
+        ${MY_REPO}/stx/config-files/centos-release-config/files/issue*
 
     # Apply meta patches
     cd ${SRC_META_PATCHES}
@@ -264,30 +314,8 @@ patch_src () {
 }
 
 populate_dl () {
-    ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/generate-centos-repo.sh ${STX_MIRROR_DIR}/stx-6.0
-    ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/populate_downloads.sh ${STX_MIRROR_DIR}/stx-6.0
-}
-
-# 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
-
-build_image_rm () {
-    echo_step_start "Build CentOS images: To be removed"
-
-    mkdir -p ${STX_PRJ_OUTPUT}
-    cd ${STX_PRJ_OUTPUT}
-    wget -q ${ISO_UP} -O ${ISO_INF_COS}
-    ls -lh ${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}"
+    ${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 () {
@@ -298,6 +326,9 @@ build_image () {
     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"
 
@@ -314,8 +345,13 @@ build_image () {
 
 prepare_workspace
 create_env
-repo_init_sync
+if [ "${USE_MIRROR}" == "Yes" ]; then
+    get_mirror_src
+    get_mirror_pkg
+else
+    repo_init_sync
+    get_mirror_pkg
+fi
 patch_src
 populate_dl
-#build_image_rm
 build_image