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 J-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] [-p PARALLEL_BUILD] [-m] [-n] [-u] [-h]
44 -w WORKSPACE_DIR is the path for the project
45 -p PARALLEL_BUILD is the num of paralle build, default is 2
46 -m use mirror for src and deb pkgs
47 -n dry-run only for bitbake
56 [ -n "$1" ] && msg_step=$1
57 echo "#########################################################################################"
58 echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
59 echo "#########################################################################################"
63 [ -n "$1" ] && msg_step=$1
64 echo "#########################################################################################"
65 echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
66 echo "#########################################################################################"
81 echo "CMD: ${RUN_CMD}"
85 #########################################################################
87 #########################################################################
94 while getopts "w:p:mnh" OPTION; do
97 WORKSPACE=`readlink -f ${OPTARG}`
100 STX_PARALLEL="${OPTARG}"
107 REUSE_APTLY="--reuse"
116 if [ -z ${WORKSPACE} ]; then
117 echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
118 WORKSPACE=`readlink -f workspace`
121 #########################################################################
122 # Functions for each step
123 #########################################################################
125 # "_" can't be used in project name
126 PRJ_NAME=prj-oran-stx-deb
128 STX_SRC_BRANCH="r/stx.${STX_VER}"
130 # Temporary for master
131 #STX_TAG="master-1ba0db8"
132 #STX_SRC_BRANCH="master"
134 STX_LOCAL_DIR=${WORKSPACE}/localdisk
135 STX_LOCAL_SRC_DIR=${STX_LOCAL_DIR}/designer/${USER}/${PRJ_NAME}
136 STX_LOCAL_PRJ_DIR=${STX_LOCAL_DIR}/loadbuild/${USER}/${PRJ_NAME}
137 STX_SRC_DIR=${WORKSPACE}/src
138 STX_PRJ_DIR=${WORKSPACE}/${PRJ_NAME}
139 STX_PRJ_OUTPUT=${WORKSPACE}/prj_output
140 STX_MIRROR_DIR=${WORKSPACE}/mirrors
141 STX_APTLY_DIR=${WORKSPACE}/aptly
142 STX_MINIKUBE_HOME=${WORKSPACE}/minikube_home
143 STX_MANIFEST_URL="https://opendev.org/starlingx/manifest"
145 MIRROR_SRC_STX=infbuilder/inf-src-stx:${STX_VER}
146 #MIRROR_SRC_STX=infbuilder/inf-src-stx:${STX_TAG}
147 MIRROR_CONTAINER_IMG=infbuilder/inf-debian-mirror:2022.11-stx-${STX_VER}
148 MIRROR_APTLY_IMG=infbuilder/inf-debian-aptly:2022.11-stx-${STX_VER}
150 STX_SHARED_REPO=http://mirror.starlingx.cengn.ca/mirror/starlingx/master/debian/monolithic/20221123T070000Z/outputs/aptly/deb-local-build/
151 STX_SHARED_SOURCE=http://mirror.starlingx.cengn.ca/mirror/starlingx/master/debian/monolithic/20221123T070000Z/outputs/aptly/deb-local-source/
153 SRC_ORAN_DIR=${STX_SRC_DIR}/rtp
154 SRC_META_PATCHES=${SRC_ORAN_DIR}/scripts/build_inf_debian/meta-patches
156 ISO_INF_DEB=inf-image-debian-all-x86-64.iso
158 prepare_workspace () {
159 msg_step="Create workspace for the Debian build"
162 mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} \
163 ${STX_APTLY_DIR} ${STX_PRJ_OUTPUT} ${STX_MINIKUBE_HOME}
164 rm -f ${STX_SRC_DIR} ${STX_PRJ_DIR}
165 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_SRC_DIR}) ${STX_SRC_DIR}
166 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_PRJ_DIR}) ${STX_PRJ_DIR}
168 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
169 echo_info "For all source repos: ${STX_SRC_DIR}"
170 echo_info "For StarlingX deb pkgs mirror: ${STX_MIRROR_DIR}"
171 echo_info "For StarlingX build project: ${STX_PRJ_DIR}"
177 msg_step="Create env file for the Debian build"
180 ENV_FILENAME=env.${PRJ_NAME}
182 cat <<EOF > ${WORKSPACE}/${ENV_FILENAME}
184 export STX_BUILD_HOME=${WORKSPACE}
185 export PROJECT=${PRJ_NAME}
186 export STX_MIRROR_DIR=${STX_MIRROR_DIR}
187 export STX_REPO_ROOT=${STX_SRC_DIR}
188 #export STX_REPO_ROOT_SUBDIR="localdisk/designer/${USER}/${PRJ_NAME}"
190 export USER_NAME=${USER}
191 export USER_EMAIL=${USER}@windriver.com
194 export STX_PLATFORM="minikube"
195 export STX_MINIKUBENAME="minikube-${USER}"
196 export MINIKUBE_HOME=${STX_MINIKUBE_HOME}
198 # Manifest/Repo Options:
199 export STX_MANIFEST_URL="${STX_MANIFEST_URL}"
200 export STX_MANIFEST_BRANCH="master"
201 export STX_MANIFEST="default.xml"
205 echo_info "Env file created at ${WORKSPACE}/$ENV_FILENAME"
206 cat ${WORKSPACE}/$ENV_FILENAME
208 source ${WORKSPACE}/${ENV_FILENAME}
210 git config --global user.email "${USER_EMAIL}"
211 git config --global user.name "${USER_NAME}"
212 git config --global color.ui false
218 msg_step="Init the repo and sync"
221 # Avoid the colorization prompt
222 git config --global color.ui false
224 if [ -d ${STX_REPO_ROOT}/.repo ]; then
225 echo_info "the src repos already exists, skipping"
229 RUN_CMD="repo init -u ${STX_MANIFEST_URL} -b ${STX_SRC_BRANCH} -m ${STX_MANIFEST}"
230 run_cmd "Init the repo from manifest"
232 RUN_CMD="repo sync --force-sync"
235 touch .repo-init-done
242 msg_step="Get src mirror from dockerhub image"
245 if [ -d ${STX_REPO_ROOT}/.repo ]; then
246 echo_info "the src repos already exists, skipping"
248 docker pull ${MIRROR_SRC_STX}
249 docker create -ti --name inf-src-stx ${MIRROR_SRC_STX} sh
250 #docker cp inf-src-stx:/stx-${STX_VER}.tar.bz2 ${STX_REPO_ROOT}
251 docker cp inf-src-stx:/stx-${STX_TAG}.tar.bz2 ${STX_REPO_ROOT}
252 docker rm inf-src-stx
255 #tar xf stx-${STX_VER}.tar.bz2
256 #mv stx-${STX_VER}/* stx-${STX_VER}/.repo .
257 #rm -rf stx-${STX_VER} stx-${STX_VER}.tar.bz2
258 tar xf stx-${STX_TAG}.tar.bz2
259 mv stx-${STX_SRC_BRANCH}/* stx-${STX_SRC_BRANCH}/.repo .
260 rm -rf stx-${STX_SRC_BRANCH} stx-${STX_TAG}.tar.bz2
261 touch .repo-init-done
269 msg_step="Get deb mirror from dockerhub image"
272 if [ -d ${STX_MIRROR_DIR}/starlingx ]; then
273 echo_info "The deb mirror already exists, skipping"
275 docker pull ${MIRROR_CONTAINER_IMG}
276 docker create -ti --name inf-debian-mirror ${MIRROR_CONTAINER_IMG} sh
277 docker cp inf-debian-mirror:/mirror-stx-${STX_VER}/. ${STX_MIRROR_DIR}
278 docker rm inf-debian-mirror
284 get_mirror_aptly () {
285 msg_step="Get deb mirror aptly from dockerhub image"
288 if [ -f ${STX_APTLY_DIR}/aptly.conf ]; then
289 echo_info "The deb aptly already exists, skipping"
291 docker pull ${MIRROR_APTLY_IMG}
292 docker create -ti --name inf-debian-aptly ${MIRROR_APTLY_IMG} sh
293 docker cp inf-debian-aptly:/aptly-stx-${STX_VER}/. ${STX_APTLY_DIR}
294 docker rm inf-debian-aptly
300 clone_update_repo () {
306 if [ -d ${REPO_NAME}/.git ]; then
307 if [ "${SKIP_UPDATE}" == "Yes" ]; then
308 echo_info "The repo ${REPO_NAME} exists, skip updating for the branch ${REPO_BRANCH}"
310 echo_info "The repo ${REPO_NAME} exists, updating for the branch ${REPO_BRANCH}"
312 git checkout ${REPO_BRANCH}
317 RUN_CMD="git clone --branch ${REPO_BRANCH} ${REPO_URL} ${REPO_NAME}"
318 run_cmd "Cloning the source of repo '${REPO_NAME}':"
320 if [ -n "${REPO_COMMIT}" ]; then
322 RUN_CMD="git checkout -b ${REPO_BRANCH}-${REPO_COMMIT} ${REPO_COMMIT}"
323 run_cmd "Checkout the repo ${REPO_NAME} to specific commit: ${REPO_COMMIT}"
331 msg_step="Get the source code repos"
334 # Clone the oran inf source if it's not already cloned
335 # Check if the script is inside the repo
336 if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
337 CLONED_ORAN_REPO=`git rev-parse --show-toplevel`
338 echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}"
339 mkdir -p ${SRC_ORAN_DIR}
342 ln -sf ${CLONED_ORAN_REPO}/scripts scripts
344 echo_info "Cloning oran layer:"
346 clone_update_repo ${SRC_ORAN_BRANCH} ${SRC_ORAN_URL} rtp
349 if [ "${USE_MIRROR}" == "Yes" ]; then
363 echo_step_start "Patching source codes for INF project"
365 STX_ISSUE_DIR="${STX_REPO_ROOT}/cgcs-root/stx/config-files/debian-release-config/files"
366 echo_info "Patching for the ${STX_ISSUE_DIR}"
367 grep -q "${ORAN_REL}" ${STX_ISSUE_DIR}/issue* \
368 || sed -i "s/\(@PLATFORM_RELEASE@\)/\1 - ${ORAN_REL}/" ${STX_ISSUE_DIR}/issue*
370 STX_BUILDER="${STX_REPO_ROOT}/stx-tools/stx/lib/stx/stx_build.py"
371 echo_info "Patching for the ${STX_BUILDER}"
372 grep -q "\-\-parallel" ${STX_BUILDER} \
373 || sed -i "s/\(build-pkgs -a \)/\1 --parallel ${STX_PARALLEL} ${REUSE_APTLY}/" \
376 STX_LOCALRC="${STX_REPO_ROOT}/stx-tools/stx/stx-build-tools-chart/stx-builder/configmap/localrc.sample"
377 echo_info "Patching for the localrc file"
378 echo "export STX_SHARED_REPO=${STX_SHARED_REPO}" >> ${STX_LOCALRC}
379 echo "export STX_SHARED_SOURCE=${STX_SHARED_SOURCE}" >> ${STX_LOCALRC}
382 if [ -d ${SRC_META_PATCHES} ]; then
383 cd ${SRC_META_PATCHES}
384 src_dirs=$(find . -type f -printf "%h\n"|uniq)
385 for d in ${src_dirs}; do
386 cd ${STX_REPO_ROOT}/${d}
388 # backup current branch
389 local_branch=$(git rev-parse --abbrev-ref HEAD)
390 if [ "${local_branch}" = "HEAD" ]; then
391 git checkout ${STX_SRC_BRANCH}
392 local_branch=$(git rev-parse --abbrev-ref HEAD)
394 git branch -m "${local_branch}_${TIMESTAMP}"
395 git checkout ${STX_SRC_BRANCH}
397 for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do
398 echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}"
399 git am ${SRC_META_PATCHES}/${d}/${p}
408 echo_step_start "Init stx tool"
412 cp stx.conf.sample stx.conf
416 # Align the builder container to use your user/UID
417 stx config --add builder.myuname $(id -un)
418 stx config --add builder.uid $(id -u)
420 # Embedded in ~/localrc of the build container
421 stx config --add project.gituser ${USER_NAME}
422 stx config --add project.gitemail ${USER_EMAIL}
424 # This will be included in the name of your build container and the basename for $STX_REPO_ROOT
425 stx config --add project.name ${PRJ_NAME}
427 #stx config --add project.proxy true
428 #stx config --add project.proxyserver 147.11.252.42
429 #stx config --add project.proxyport 9090
437 echo_step_start "Build Debian images"
439 cd ${STX_REPO_ROOT}/stx-tools
440 RUN_CMD="./stx-init-env"
441 run_cmd "Run stx-init-env script"
445 # wait for all the pods running
449 RUN_CMD="stx build prepare"
450 run_cmd "Build prepare"
452 RUN_CMD="stx build download"
453 run_cmd "Download packges"
455 RUN_CMD="stx repomgr list"
456 run_cmd "repomgr list"
458 RUN_CMD="stx build world"
461 RUN_CMD="stx build image"
462 run_cmd "Build ISO image"
464 cp -f ${STX_LOCAL_DIR}/deploy/starlingx-intel-x86-64-cd.iso ${STX_PRJ_OUTPUT}/${ISO_INF_DEB}
468 echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_DEB}"
471 #########################################################################
473 #########################################################################