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"
28 SCRIPTS_DIR=$(dirname $(readlink -f $0))
29 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
31 #########################################################################
33 #########################################################################
38 $(basename $0) [-w WORKSPACE_DIR] [-n] [-u] [-h]
40 -w WORKSPACE_DIR is the path for the project
41 -n dry-run only for bitbake
42 -u update the repo if it exists
51 [ -n "$1" ] && msg_step=$1
52 echo "#########################################################################################"
53 echo "## STEP START: ${msg_step}"
54 echo "#########################################################################################"
58 [ -n "$1" ] && msg_step=$1
59 echo "#########################################################################################"
60 echo "## STEP END: ${msg_step}"
61 echo "#########################################################################################"
76 echo "CMD: ${RUN_CMD}"
80 #########################################################################
82 #########################################################################
86 while getopts "w:b:e:r:unh" OPTION; do
89 WORKSPACE=`readlink -f ${OPTARG}`
104 if [ -z ${WORKSPACE} ]; then
105 echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
106 WORKSPACE=`readlink -f workspace`
109 #########################################################################
110 # Functions for each step
111 #########################################################################
112 PRJ_NAME=prj_oran_stx_centos
114 STX_SRC_BRANCH="r/stx.6.0"
115 STX_LOCAL_DIR=${WORKSPACE}/localdisk
116 STX_LOCAL_SRC_DIR=${STX_LOCAL_DIR}/designer/${USER}/${PRJ_NAME}
117 STX_LOCAL_PRJ_DIR=${STX_LOCAL_DIR}/loadbuild/${USER}/${PRJ_NAME}
118 STX_SRC_DIR=${WORKSPACE}/src
119 STX_PRJ_DIR=${WORKSPACE}/${PRJ_NAME}
120 STX_PRJ_OUTPUT=${WORKSPACE}/prj_output
121 STX_MIRROR_DIR=${WORKSPACE}/mirror
122 STX_MANIFEST_URL="https://opendev.org/starlingx/manifest"
124 SRC_META_PATCHES=${SCRIPTS_DIR}/meta-patches
126 prepare_workspace () {
127 msg_step="Create workspace for the CentOS build"
130 mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} ${STX_PRJ_OUTPUT}
131 rm -f ${STX_SRC_DIR} ${STX_PRJ_DIR}
132 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_SRC_DIR}) ${STX_SRC_DIR}
133 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_PRJ_DIR}) ${STX_PRJ_DIR}
135 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
136 echo_info "For all layers source: ${STX_SRC_DIR}"
137 echo_info "For StarlingX rpm mirror: ${STX_MIRROR_DIR}"
138 echo_info "For StarlingX build project: ${STX_PRJ_DIR}"
144 msg_step="Create env file for the CentOS build"
147 ENV_FILENAME=env.${PRJ_NAME}
149 cat <<EOF > ${WORKSPACE}/${ENV_FILENAME}
151 export STX_MIRROR_DIR=${STX_MIRROR_DIR}
153 #######################################
155 #######################################
157 export LC_ALL=en_US.UTF-8
158 export PROJECT=${PRJ_NAME}
159 export SRC_BUILD_ENVIRONMENT=tis-r6-pike
160 export MY_LOCAL_DISK=${STX_SRC_DIR}
161 export MY_REPO_ROOT_DIR=\${MY_LOCAL_DISK}
162 export MY_REPO=\${MY_REPO_ROOT_DIR}/cgcs-root
163 export CGCSDIR=\${MY_REPO}/stx
164 export MY_WORKSPACE=${WORKSPACE}/\${PROJECT}
165 export MY_BUILD_ENVIRONMENT=\${USER}-\${PROJECT}-\${SRC_BUILD_ENVIRONMENT}
166 export MY_BUILD_ENVIRONMENT_FILE=\${MY_BUILD_ENVIRONMENT}.cfg
167 export MY_BUILD_ENVIRONMENT_FILE_STD=\${MY_BUILD_ENVIRONMENT}-std.cfg
168 export MY_BUILD_ENVIRONMENT_FILE_RT=\${MY_BUILD_ENVIRONMENT}-rt.cfg
169 export MY_BUILD_ENVIRONMENT_FILE_STD_B0=\${MY_WORKSPACE}/std/configs/\${MY_BUILD_ENVIRONMENT}-std/\${MY_BUILD_ENVIRONMENT}-std.b0.cfg
170 export MY_BUILD_ENVIRONMENT_FILE_RT_B0=\${MY_WORKSPACE}/rt/configs/\${MY_BUILD_ENVIRONMENT}-rt/\${MY_BUILD_ENVIRONMENT}-rt.b0.cfg
171 export MY_BUILD_DIR=${WORKSPACE}/\${PROJECT}
172 export MY_SRC_RPM_BUILD_DIR=\${MY_BUILD_DIR}/rpmbuild
173 export MY_BUILD_CFG=\${MY_WORKSPACE}/\${MY_BUILD_ENVIRONMENT_FILE}
174 export MY_BUILD_CFG_STD=\${MY_WORKSPACE}/std/\${MY_BUILD_ENVIRONMENT_FILE_STD}
175 export MY_BUILD_CFG_RT=\${MY_WORKSPACE}/rt/\${MY_BUILD_ENVIRONMENT_FILE_RT}
176 export PATH=\${MY_REPO}/build-tools:\${MY_LOCAL_DISK}/bin:\${CGCSDIR}/stx-update/extras/scripts:\${PATH}
177 export CGCSPATCH_DIR=\${CGCSDIR}/stx-update/cgcs-patch
178 export BUILD_ISO_USE_UDEV=1
180 # WRCP/WRA/WRO do not support layered builds at this time.
183 # StarlingX since 4.0 supports layered builds (compiler, distro, flock) as an option.
184 # Note: Only flock layer builds an iso at this time.
185 # Note: You may leave LAYER="", this will build everything, also known as a 'monolithic' build.
186 # export LAYER=compiler
187 # export LAYER=distro
190 # Upstream issue seems to have been corrected
191 # export REPO_VERSION="--repo-branch=repo-1"
194 # In order to avoid running out of space in your home directory
195 export XDG_CACHE_HOME=\${MY_LOCAL_DISK}/.cache;
196 export XDG_DATA_HOME=\${MY_LOCAL_DISK}
198 #/bin/title "\${HOSTNAME} \${PROJECT}"
200 alias patch_build=\${MY_REPO}/stx/update/extras/scripts/patch_build.sh
202 alias cdrepo="cd \$MY_REPO_ROOT_DIR"
203 alias cdbuild="cd \$MY_BUILD_DIR"
205 cd \${MY_REPO_ROOT_DIR}
209 echo_info "Env file created at ${WORKSPACE}/$ENV_FILENAME"
211 source ${WORKSPACE}/${ENV_FILENAME}
217 msg_step="Init the repo and sync"
220 cd ${MY_REPO_ROOT_DIR}
221 STX_MANIFEST="default.xml"
222 if [ "$LAYER" != "" ]; then
223 STX_MANIFEST=${LAYER}.xml
226 RUN_CMD="repo init ${REPO_VERSION} -u ${STX_MANIFEST_URL} -b ${STX_SRC_BRANCH} -m ${STX_MANIFEST}"
227 run_cmd "Init the repo from manifest"
229 RUN_CMD="repo sync --force-sync"
236 echo_step_start "Some source codes need to be patched for INF project"
238 sed -i "s|/import/mirrors|${STX_MIRROR_DIR}|" \
239 $MY_REPO/stx/metal/installer/pxe-network-installer/centos/build_srpm.data
242 cd ${SRC_META_PATCHES}
243 src_dirs=$(find . -type f -printf "%h\n"|uniq)
244 for d in ${src_dirs}; do
245 cd ${MY_REPO_ROOT_DIR}/${d}
247 # backup current branch
248 local_branch=$(git rev-parse --abbrev-ref HEAD)
249 if [ "${local_branch}" = "HEAD" ]; then
250 git checkout ${STX_SRC_BRANCH}
251 local_branch=$(git rev-parse --abbrev-ref HEAD)
253 git branch -m "${local_branch}_${TIMESTAMP}"
254 git checkout ${STX_SRC_BRANCH}
256 for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do
257 echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}"
258 git am ${SRC_META_PATCHES}/${d}/${p}
266 ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/generate-centos-repo.sh ${STX_MIRROR_DIR}/stx-6.0
267 ${MY_REPO_ROOT_DIR}/stx-tools/toCOPY/populate_downloads.sh ${STX_MIRROR_DIR}/stx-6.0
271 # This build script can not successfully build out the image yet,
272 # get the upstream image temporary so we can still test the CI job to
273 # upload the image to nexus
274 ISO_STX_COS=bootimage.iso
276 ISO_UP=http://mirror.starlingx.cengn.ca/mirror/starlingx/release/${ISO_UP_VER}/centos/flock/outputs/iso/${ISO_STX_COS}
277 ISO_INF_COS=inf-image-centos-all-x86-64.iso
280 echo_step_start "Build CentOS images: To be removed"
282 mkdir -p ${STX_PRJ_OUTPUT}
284 wget -q ${ISO_UP} -O ${ISO_INF_COS}
285 ls -lh ${STX_PRJ_OUTPUT}/${ISO_INF_COS}
289 echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_COS}"
293 echo_step_start "Build CentOS images"
295 mkdir -p ${STX_PRJ_OUTPUT}
297 RUN_CMD="build-pkgs --build-avoidance"
301 run_cmd "Build ISO image"
303 cp ${MY_BUILD_DIR}/export/bootimage.iso ${STX_PRJ_OUTPUT}/${ISO_INF_COS}
307 echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_COS}"
311 #########################################################################
313 #########################################################################