3 # Copyright (C) 2022 Wind River Systems, Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Ensure we fail the job if any steps fail.
20 #########################################################################
22 #########################################################################
24 SRC_ORAN_BRANCH="master"
25 SRC_O2_BRANCH="master"
27 SRC_ORAN_URL="https://gerrit.o-ran-sc.org/r/pti/rtp"
28 SRC_O2_URL="https://opendev.org/starlingx/app-oran-o2"
31 ORAN_REL="ORAN G-Release (${STX_VER})"
33 SCRIPTS_DIR=$(dirname $(readlink -f $0))
34 SCRIPTS_NAME=$(basename $0)
35 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
37 #########################################################################
39 #########################################################################
44 ${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-m] [-n] [-u] [-h]
46 -w WORKSPACE_DIR is the path for the project
47 -m use mirror for src and rpm pkgs
48 -n dry-run only for bitbake
57 [ -n "$1" ] && msg_step=$1
58 echo "#########################################################################################"
59 echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
60 echo "#########################################################################################"
64 [ -n "$1" ] && msg_step=$1
65 echo "#########################################################################################"
66 echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
67 echo "#########################################################################################"
82 echo "CMD: ${RUN_CMD}"
86 #########################################################################
88 #########################################################################
93 while getopts "w:mnh" OPTION; do
96 WORKSPACE=`readlink -f ${OPTARG}`
111 if [ -z ${WORKSPACE} ]; then
112 echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
113 WORKSPACE=`readlink -f workspace`
116 #########################################################################
117 # Functions for each step
118 #########################################################################
119 PRJ_NAME=prj_oran_stx_centos
121 STX_SRC_BRANCH="r/stx.${STX_VER}"
122 STX_LOCAL_DIR=${WORKSPACE}/localdisk
123 STX_LOCAL_SRC_DIR=${STX_LOCAL_DIR}/designer/${USER}/${PRJ_NAME}
124 STX_LOCAL_PRJ_DIR=${STX_LOCAL_DIR}/loadbuild/${USER}/${PRJ_NAME}
125 STX_SRC_DIR=${WORKSPACE}/src
126 STX_PRJ_DIR=${WORKSPACE}/${PRJ_NAME}
127 STX_PRJ_OUTPUT=${WORKSPACE}/prj_output
128 STX_MIRROR_DIR=${WORKSPACE}/mirror
129 STX_MANIFEST_URL="https://opendev.org/starlingx/manifest"
131 MIRROR_SRC_STX=infbuilder/inf-src-stx:${STX_VER}
132 MIRROR_CONTAINER_IMG=infbuilder/inf-centos-mirror:2022.11-stx-${STX_VER}
134 SRC_ORAN_DIR=${STX_SRC_DIR}/rtp
135 SRC_META_PATCHES=${SRC_ORAN_DIR}/scripts/build_inf_centos/meta-patches
137 ISO_INF_COS=inf-image-centos-all-x86-64.iso
139 prepare_workspace () {
140 msg_step="Create workspace for the CentOS build"
143 mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} ${STX_PRJ_OUTPUT}
144 rm -f ${STX_SRC_DIR} ${STX_PRJ_DIR}
145 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_SRC_DIR}) ${STX_SRC_DIR}
146 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_PRJ_DIR}) ${STX_PRJ_DIR}
148 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
149 echo_info "For all layers source: ${STX_SRC_DIR}"
150 echo_info "For StarlingX rpm mirror: ${STX_MIRROR_DIR}"
151 echo_info "For StarlingX build project: ${STX_PRJ_DIR}"
157 msg_step="Create env file for the CentOS build"
160 ENV_FILENAME=env.${PRJ_NAME}
162 cat <<EOF > ${WORKSPACE}/${ENV_FILENAME}
164 export STX_MIRROR_DIR=${STX_MIRROR_DIR}
166 #######################################
168 #######################################
170 export LC_ALL=en_US.UTF-8
171 export PROJECT=${PRJ_NAME}
172 export SRC_BUILD_ENVIRONMENT=tis-r6-pike
173 export MY_LOCAL_DISK=${STX_SRC_DIR}
174 export MY_REPO_ROOT_DIR=\${MY_LOCAL_DISK}
175 export MY_REPO=\${MY_REPO_ROOT_DIR}/cgcs-root
176 export CGCSDIR=\${MY_REPO}/stx
177 export MY_WORKSPACE=${WORKSPACE}/\${PROJECT}
178 export MY_BUILD_ENVIRONMENT=\${USER}-\${PROJECT}-\${SRC_BUILD_ENVIRONMENT}
179 export MY_BUILD_ENVIRONMENT_FILE=\${MY_BUILD_ENVIRONMENT}.cfg
180 export MY_BUILD_ENVIRONMENT_FILE_STD=\${MY_BUILD_ENVIRONMENT}-std.cfg
181 export MY_BUILD_ENVIRONMENT_FILE_RT=\${MY_BUILD_ENVIRONMENT}-rt.cfg
182 export MY_BUILD_ENVIRONMENT_FILE_STD_B0=\${MY_WORKSPACE}/std/configs/\${MY_BUILD_ENVIRONMENT}-std/\${MY_BUILD_ENVIRONMENT}-std.b0.cfg
183 export MY_BUILD_ENVIRONMENT_FILE_RT_B0=\${MY_WORKSPACE}/rt/configs/\${MY_BUILD_ENVIRONMENT}-rt/\${MY_BUILD_ENVIRONMENT}-rt.b0.cfg
184 export MY_BUILD_DIR=${WORKSPACE}/\${PROJECT}
185 export MY_SRC_RPM_BUILD_DIR=\${MY_BUILD_DIR}/rpmbuild
186 export MY_BUILD_CFG=\${MY_WORKSPACE}/\${MY_BUILD_ENVIRONMENT_FILE}
187 export MY_BUILD_CFG_STD=\${MY_WORKSPACE}/std/\${MY_BUILD_ENVIRONMENT_FILE_STD}
188 export MY_BUILD_CFG_RT=\${MY_WORKSPACE}/rt/\${MY_BUILD_ENVIRONMENT_FILE_RT}
189 export PATH=\${MY_REPO}/build-tools:\${MY_LOCAL_DISK}/bin:\${CGCSDIR}/stx-update/extras/scripts:\${PATH}
190 export CGCSPATCH_DIR=\${CGCSDIR}/stx-update/cgcs-patch
191 export BUILD_ISO_USE_UDEV=1
193 # WRCP/WRA/WRO do not support layered builds at this time.
196 # StarlingX since 4.0 supports layered builds (compiler, distro, flock) as an option.
197 # Note: Only flock layer builds an iso at this time.
198 # Note: You may leave LAYER="", this will build everything, also known as a 'monolithic' build.
199 # export LAYER=compiler
200 # export LAYER=distro
203 # Upstream issue seems to have been corrected
204 # export REPO_VERSION="--repo-branch=repo-1"
207 # In order to avoid running out of space in your home directory
208 export XDG_CACHE_HOME=\${MY_LOCAL_DISK}/.cache;
209 export XDG_DATA_HOME=\${MY_LOCAL_DISK}
211 #/bin/title "\${HOSTNAME} \${PROJECT}"
213 alias patch_build=\${MY_REPO}/stx/update/extras/scripts/patch_build.sh
215 alias cdrepo="cd \$MY_REPO_ROOT_DIR"
216 alias cdbuild="cd \$MY_BUILD_DIR"
218 cd \${MY_REPO_ROOT_DIR}
222 echo_info "Env file created at ${WORKSPACE}/$ENV_FILENAME"
224 source ${WORKSPACE}/${ENV_FILENAME}
230 msg_step="Init the repo and sync"
233 # Avoid the colorization prompt
234 git config --global color.ui false
236 cd ${MY_REPO_ROOT_DIR}
237 STX_MANIFEST="default.xml"
238 if [ "$LAYER" != "" ]; then
239 STX_MANIFEST=${LAYER}.xml
242 RUN_CMD="repo init ${REPO_VERSION} -u ${STX_MANIFEST_URL} -b ${STX_SRC_BRANCH} -m ${STX_MANIFEST}"
243 run_cmd "Init the repo from manifest"
245 RUN_CMD="repo sync --force-sync"
252 msg_step="Get src mirror from dockerhub image"
255 if [ -d ${MY_REPO_ROOT_DIR}/.repo ]; then
256 echo_info "The src repos already exists, skipping"
258 docker pull ${MIRROR_SRC_STX}
259 docker create -ti --name inf-src-stx ${MIRROR_SRC_STX} sh
260 docker cp inf-src-stx:/stx-${STX_VER}.tar.bz2 ${MY_REPO_ROOT_DIR}
261 docker rm inf-src-stx
263 cd ${MY_REPO_ROOT_DIR}
264 tar xf stx-${STX_VER}.tar.bz2
265 mv stx-${STX_VER}/* stx-${STX_VER}/.repo .
266 rm -rf stx-${STX_VER} stx-${STX_VER}.tar.bz2
273 msg_step="Get rpm mirror from dockerhub image"
276 docker pull ${MIRROR_CONTAINER_IMG}
277 docker create -ti --name inf-centos-mirror ${MIRROR_CONTAINER_IMG} sh
278 docker cp inf-centos-mirror:/mirror_stx-${STX_VER}/. ${STX_MIRROR_DIR}
279 docker rm inf-centos-mirror
284 clone_update_repo () {
290 if [ -d ${REPO_NAME}/.git ]; then
291 if [ "${SKIP_UPDATE}" == "Yes" ]; then
292 echo_info "The repo ${REPO_NAME} exists, skip updating for the branch ${REPO_BRANCH}"
294 echo_info "The repo ${REPO_NAME} exists, updating for the branch ${REPO_BRANCH}"
296 git checkout ${REPO_BRANCH}
301 RUN_CMD="git clone --branch ${REPO_BRANCH} ${REPO_URL} ${REPO_NAME}"
302 run_cmd "Cloning the source of repo '${REPO_NAME}':"
304 if [ -n "${REPO_COMMIT}" ]; then
306 RUN_CMD="git checkout -b ${REPO_BRANCH}-${REPO_COMMIT} ${REPO_COMMIT}"
307 run_cmd "Checkout the repo ${REPO_NAME} to specific commit: ${REPO_COMMIT}"
315 msg_step="Get the source code repos"
318 # Clone the oran inf source if it's not already cloned
319 # Check if the script is inside the repo
320 if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
321 CLONED_ORAN_REPO=`git rev-parse --show-toplevel`
322 echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}"
323 mkdir -p ${SRC_ORAN_DIR}
326 ln -sf ${CLONED_ORAN_REPO}/scripts scripts
328 echo_info "Cloning oran layer:"
330 clone_update_repo ${SRC_ORAN_BRANCH} ${SRC_ORAN_URL} rtp
333 if [ "${USE_MIRROR}" == "Yes" ]; then
342 cd ${STX_SRC_DIR}/cgcs-root/stx/
343 clone_update_repo ${SRC_O2_BRANCH} ${SRC_O2_URL} app-oran-o2
349 echo_step_start "Patching source codes for INF project"
351 STX_PXE_DATA="${MY_REPO}/stx/metal/installer/pxe-network-installer/centos/build_srpm.data"
352 echo_info "Patching for the ${STX_PXE_DATA}"
353 sed -i "s|/import/mirrors|${STX_MIRROR_DIR}|" ${STX_PXE_DATA}
355 STX_ISSUE_DIR="${MY_REPO}/stx/config-files/centos-release-config/files"
356 echo_info "Patching for the ${STX_ISSUE_DIR}"
357 grep -q "${ORAN_REL}" ${STX_ISSUE_DIR}/issue* \
358 || sed -i "s/\(@PLATFORM_RELEASE@\)/\1 - ${ORAN_REL}/" ${STX_ISSUE_DIR}/issue*
361 cd ${SRC_META_PATCHES}
362 src_dirs=$(find . -type f -printf "%h\n"|uniq)
363 for d in ${src_dirs}; do
364 cd ${MY_REPO_ROOT_DIR}/${d}
366 # backup current branch
367 local_branch=$(git rev-parse --abbrev-ref HEAD)
368 if [ "${local_branch}" = "HEAD" ]; then
369 git checkout ${STX_SRC_BRANCH}
370 local_branch=$(git rev-parse --abbrev-ref HEAD)
372 git branch -m "${local_branch}_${TIMESTAMP}"
373 git checkout ${STX_SRC_BRANCH}
375 for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do
376 echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}"
377 git am ${SRC_META_PATCHES}/${d}/${p}
385 ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/generate-centos-repo.sh ${STX_MIRROR_DIR}/stx-${STX_VER}
386 ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/populate_downloads.sh ${STX_MIRROR_DIR}/stx-${STX_VER}
390 echo_step_start "Build CentOS images"
392 mkdir -p ${STX_PRJ_OUTPUT}
394 RUN_CMD="build-pkgs --build-avoidance"
397 # The first run always fail
398 build-iso || sleep 60
401 run_cmd "Build ISO image"
403 cp -f ${MY_BUILD_DIR}/export/bootimage.iso ${STX_PRJ_OUTPUT}/${ISO_INF_COS}
407 echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_COS}"
410 #########################################################################
412 #########################################################################