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"
26 SRC_ORAN_URL="https://gerrit.o-ran-sc.org/r/pti/rtp"
29 ORAN_REL="ORAN G-Release (${STX_VER})"
31 SCRIPTS_DIR=$(dirname $(readlink -f $0))
32 SCRIPTS_NAME=$(basename $0)
33 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
35 #########################################################################
37 #########################################################################
42 ${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-m] [-n] [-u] [-h]
44 -w WORKSPACE_DIR is the path for the project
45 -m use mirror for src and rpm pkgs
46 -n dry-run only for bitbake
55 [ -n "$1" ] && msg_step=$1
56 echo "#########################################################################################"
57 echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
58 echo "#########################################################################################"
62 [ -n "$1" ] && msg_step=$1
63 echo "#########################################################################################"
64 echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
65 echo "#########################################################################################"
80 echo "CMD: ${RUN_CMD}"
84 #########################################################################
86 #########################################################################
91 while getopts "w:mnh" OPTION; do
94 WORKSPACE=`readlink -f ${OPTARG}`
109 if [ -z ${WORKSPACE} ]; then
110 echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
111 WORKSPACE=`readlink -f workspace`
114 #########################################################################
115 # Functions for each step
116 #########################################################################
117 PRJ_NAME=prj_oran_stx_centos
119 STX_SRC_BRANCH="r/stx.${STX_VER}"
120 STX_LOCAL_DIR=${WORKSPACE}/localdisk
121 STX_LOCAL_SRC_DIR=${STX_LOCAL_DIR}/designer/${USER}/${PRJ_NAME}
122 STX_LOCAL_PRJ_DIR=${STX_LOCAL_DIR}/loadbuild/${USER}/${PRJ_NAME}
123 STX_SRC_DIR=${WORKSPACE}/src
124 STX_PRJ_DIR=${WORKSPACE}/${PRJ_NAME}
125 STX_PRJ_OUTPUT=${WORKSPACE}/prj_output
126 STX_MIRROR_DIR=${WORKSPACE}/mirror
127 STX_MANIFEST_URL="https://opendev.org/starlingx/manifest"
129 MIRROR_SRC_STX=infbuilder/inf-src-stx:${STX_VER}
130 MIRROR_CONTAINER_IMG=infbuilder/inf-centos-mirror:2022.11-stx-${STX_VER}
132 SRC_META_PATCHES=${SCRIPTS_DIR}/meta-patches
134 ISO_INF_COS=inf-image-centos-all-x86-64.iso
136 prepare_workspace () {
137 msg_step="Create workspace for the CentOS build"
140 mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} ${STX_PRJ_OUTPUT}
141 rm -f ${STX_SRC_DIR} ${STX_PRJ_DIR}
142 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_SRC_DIR}) ${STX_SRC_DIR}
143 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_PRJ_DIR}) ${STX_PRJ_DIR}
145 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
146 echo_info "For all layers source: ${STX_SRC_DIR}"
147 echo_info "For StarlingX rpm mirror: ${STX_MIRROR_DIR}"
148 echo_info "For StarlingX build project: ${STX_PRJ_DIR}"
154 msg_step="Create env file for the CentOS build"
157 ENV_FILENAME=env.${PRJ_NAME}
159 cat <<EOF > ${WORKSPACE}/${ENV_FILENAME}
161 export STX_MIRROR_DIR=${STX_MIRROR_DIR}
163 #######################################
165 #######################################
167 export LC_ALL=en_US.UTF-8
168 export PROJECT=${PRJ_NAME}
169 export SRC_BUILD_ENVIRONMENT=tis-r6-pike
170 export MY_LOCAL_DISK=${STX_SRC_DIR}
171 export MY_REPO_ROOT_DIR=\${MY_LOCAL_DISK}
172 export MY_REPO=\${MY_REPO_ROOT_DIR}/cgcs-root
173 export CGCSDIR=\${MY_REPO}/stx
174 export MY_WORKSPACE=${WORKSPACE}/\${PROJECT}
175 export MY_BUILD_ENVIRONMENT=\${USER}-\${PROJECT}-\${SRC_BUILD_ENVIRONMENT}
176 export MY_BUILD_ENVIRONMENT_FILE=\${MY_BUILD_ENVIRONMENT}.cfg
177 export MY_BUILD_ENVIRONMENT_FILE_STD=\${MY_BUILD_ENVIRONMENT}-std.cfg
178 export MY_BUILD_ENVIRONMENT_FILE_RT=\${MY_BUILD_ENVIRONMENT}-rt.cfg
179 export MY_BUILD_ENVIRONMENT_FILE_STD_B0=\${MY_WORKSPACE}/std/configs/\${MY_BUILD_ENVIRONMENT}-std/\${MY_BUILD_ENVIRONMENT}-std.b0.cfg
180 export MY_BUILD_ENVIRONMENT_FILE_RT_B0=\${MY_WORKSPACE}/rt/configs/\${MY_BUILD_ENVIRONMENT}-rt/\${MY_BUILD_ENVIRONMENT}-rt.b0.cfg
181 export MY_BUILD_DIR=${WORKSPACE}/\${PROJECT}
182 export MY_SRC_RPM_BUILD_DIR=\${MY_BUILD_DIR}/rpmbuild
183 export MY_BUILD_CFG=\${MY_WORKSPACE}/\${MY_BUILD_ENVIRONMENT_FILE}
184 export MY_BUILD_CFG_STD=\${MY_WORKSPACE}/std/\${MY_BUILD_ENVIRONMENT_FILE_STD}
185 export MY_BUILD_CFG_RT=\${MY_WORKSPACE}/rt/\${MY_BUILD_ENVIRONMENT_FILE_RT}
186 export PATH=\${MY_REPO}/build-tools:\${MY_LOCAL_DISK}/bin:\${CGCSDIR}/stx-update/extras/scripts:\${PATH}
187 export CGCSPATCH_DIR=\${CGCSDIR}/stx-update/cgcs-patch
188 export BUILD_ISO_USE_UDEV=1
190 # WRCP/WRA/WRO do not support layered builds at this time.
193 # StarlingX since 4.0 supports layered builds (compiler, distro, flock) as an option.
194 # Note: Only flock layer builds an iso at this time.
195 # Note: You may leave LAYER="", this will build everything, also known as a 'monolithic' build.
196 # export LAYER=compiler
197 # export LAYER=distro
200 # Upstream issue seems to have been corrected
201 # export REPO_VERSION="--repo-branch=repo-1"
204 # In order to avoid running out of space in your home directory
205 export XDG_CACHE_HOME=\${MY_LOCAL_DISK}/.cache;
206 export XDG_DATA_HOME=\${MY_LOCAL_DISK}
208 #/bin/title "\${HOSTNAME} \${PROJECT}"
210 alias patch_build=\${MY_REPO}/stx/update/extras/scripts/patch_build.sh
212 alias cdrepo="cd \$MY_REPO_ROOT_DIR"
213 alias cdbuild="cd \$MY_BUILD_DIR"
215 cd \${MY_REPO_ROOT_DIR}
219 echo_info "Env file created at ${WORKSPACE}/$ENV_FILENAME"
221 source ${WORKSPACE}/${ENV_FILENAME}
227 msg_step="Init the repo and sync"
230 # Avoid the colorization prompt
231 git config --global color.ui false
233 cd ${MY_REPO_ROOT_DIR}
234 STX_MANIFEST="default.xml"
235 if [ "$LAYER" != "" ]; then
236 STX_MANIFEST=${LAYER}.xml
239 RUN_CMD="repo init ${REPO_VERSION} -u ${STX_MANIFEST_URL} -b ${STX_SRC_BRANCH} -m ${STX_MANIFEST}"
240 run_cmd "Init the repo from manifest"
242 RUN_CMD="repo sync --force-sync"
249 msg_step="Get src mirror from dockerhub image"
252 if [ -d ${MY_REPO_ROOT_DIR}/.repo ]; then
253 echo_info "The src repos already exists, skipping"
255 docker pull ${MIRROR_SRC_STX}
256 docker create -ti --name inf-src-stx ${MIRROR_SRC_STX} sh
257 docker cp inf-src-stx:/stx-${STX_VER}.tar.bz2 ${MY_REPO_ROOT_DIR}
258 docker rm inf-src-stx
260 cd ${MY_REPO_ROOT_DIR}
261 tar xf stx-${STX_VER}.tar.bz2
262 mv stx-${STX_VER}/* stx-${STX_VER}/.repo .
263 rm -rf stx-${STX_VER} stx-${STX_VER}.tar.bz2
270 msg_step="Get rpm mirror from dockerhub image"
273 docker pull ${MIRROR_CONTAINER_IMG}
274 docker create -ti --name inf-centos-mirror ${MIRROR_CONTAINER_IMG} sh
275 docker cp inf-centos-mirror:/mirror_stx-${STX_VER}/. ${STX_MIRROR_DIR}
276 docker rm inf-centos-mirror
282 echo_step_start "Some source codes need to be patched for INF project"
284 sed -i "s|/import/mirrors|${STX_MIRROR_DIR}|" \
285 ${MY_REPO}/stx/metal/installer/pxe-network-installer/centos/build_srpm.data
287 grep -q "${ORAN_REL}" \
288 ${MY_REPO}/stx/config-files/centos-release-config/files/issue* \
289 || sed -i "s/\(@PLATFORM_RELEASE@\)/\1 - ${ORAN_REL}/" \
290 ${MY_REPO}/stx/config-files/centos-release-config/files/issue*
293 cd ${SRC_META_PATCHES}
294 src_dirs=$(find . -type f -printf "%h\n"|uniq)
295 for d in ${src_dirs}; do
296 cd ${MY_REPO_ROOT_DIR}/${d}
298 # backup current branch
299 local_branch=$(git rev-parse --abbrev-ref HEAD)
300 if [ "${local_branch}" = "HEAD" ]; then
301 git checkout ${STX_SRC_BRANCH}
302 local_branch=$(git rev-parse --abbrev-ref HEAD)
304 git branch -m "${local_branch}_${TIMESTAMP}"
305 git checkout ${STX_SRC_BRANCH}
307 for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do
308 echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}"
309 git am ${SRC_META_PATCHES}/${d}/${p}
317 ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/generate-centos-repo.sh ${STX_MIRROR_DIR}/stx-${STX_VER}
318 ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/populate_downloads.sh ${STX_MIRROR_DIR}/stx-${STX_VER}
322 echo_step_start "Build CentOS images"
324 mkdir -p ${STX_PRJ_OUTPUT}
326 RUN_CMD="build-pkgs --build-avoidance"
329 # The first run always fail
330 build-iso || sleep 60
333 run_cmd "Build ISO image"
335 cp -f ${MY_BUILD_DIR}/export/bootimage.iso ${STX_PRJ_OUTPUT}/${ISO_INF_COS}
339 echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_COS}"
342 #########################################################################
344 #########################################################################
348 if [ "${USE_MIRROR}" == "Yes" ]; then