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 deb 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 #########################################################################
118 # "_" can't be used in project name
119 PRJ_NAME=prj-oran-stx-deb
121 # stx 8.0 is not released yet
122 #STX_SRC_BRANCH="r/stx.${STX_VER}"
124 # Temporary for master
125 STX_TAG="master-1ba0db8"
126 STX_SRC_BRANCH="master"
128 STX_LOCAL_DIR=${WORKSPACE}/localdisk
129 STX_LOCAL_SRC_DIR=${STX_LOCAL_DIR}/designer/${USER}/${PRJ_NAME}
130 STX_LOCAL_PRJ_DIR=${STX_LOCAL_DIR}/loadbuild/${USER}/${PRJ_NAME}
131 STX_SRC_DIR=${WORKSPACE}/src
132 STX_PRJ_DIR=${WORKSPACE}/${PRJ_NAME}
133 STX_PRJ_OUTPUT=${WORKSPACE}/prj_output
134 STX_MIRROR_DIR=${WORKSPACE}/mirrors
135 STX_APTLY_DIR=${WORKSPACE}/aptly
136 STX_MINIKUBE_HOME=${WORKSPACE}/minikube_home
137 STX_MANIFEST_URL="https://opendev.org/starlingx/manifest"
139 #MIRROR_SRC_STX=infbuilder/inf-src-stx:${STX_VER}
140 MIRROR_SRC_STX=infbuilder/inf-src-stx:${STX_TAG}
141 MIRROR_CONTAINER_IMG=infbuilder/inf-debian-mirror:2022.11-stx-${STX_VER}
142 MIRROR_APTLY_IMG=infbuilder/inf-debian-aptly:2022.11-stx-${STX_VER}
144 STX_SHARED_REPO=http://mirror.starlingx.cengn.ca/mirror/starlingx/master/debian/monolithic/20221123T070000Z/outputs/aptly/deb-local-build/
145 STX_SHARED_SOURCE=http://mirror.starlingx.cengn.ca/mirror/starlingx/master/debian/monolithic/20221123T070000Z/outputs/aptly/deb-local-source/
148 SRC_META_PATCHES=${SCRIPTS_DIR}/meta-patches
150 ISO_INF_DEB=inf-image-debian-all-x86-64.iso
152 prepare_workspace () {
153 msg_step="Create workspace for the Debian build"
156 mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} \
157 ${STX_APTLY_DIR} ${STX_PRJ_OUTPUT} ${STX_MINIKUBE_HOME}
158 rm -f ${STX_SRC_DIR} ${STX_PRJ_DIR}
159 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_SRC_DIR}) ${STX_SRC_DIR}
160 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_PRJ_DIR}) ${STX_PRJ_DIR}
162 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
163 echo_info "For all source repos: ${STX_SRC_DIR}"
164 echo_info "For StarlingX deb pkgs mirror: ${STX_MIRROR_DIR}"
165 echo_info "For StarlingX build project: ${STX_PRJ_DIR}"
171 msg_step="Create env file for the Debian build"
174 ENV_FILENAME=env.${PRJ_NAME}
176 cat <<EOF > ${WORKSPACE}/${ENV_FILENAME}
178 export STX_BUILD_HOME=${WORKSPACE}
179 export PROJECT=${PRJ_NAME}
180 export STX_MIRROR_DIR=${STX_MIRROR_DIR}
181 export STX_REPO_ROOT=${STX_SRC_DIR}
182 #export STX_REPO_ROOT_SUBDIR="localdisk/designer/${USER}/${PRJ_NAME}"
184 export USER_NAME=${USER}
185 export USER_EMAIL=${USER}@windriver.com
188 export STX_PLATFORM="minikube"
189 export STX_MINIKUBENAME="minikube-${USER}"
190 export MINIKUBE_HOME=${STX_MINIKUBE_HOME}
192 # Manifest/Repo Options:
193 export STX_MANIFEST_URL="${STX_MANIFEST_URL}"
194 export STX_MANIFEST_BRANCH="master"
195 export STX_MANIFEST="default.xml"
199 echo_info "Env file created at ${WORKSPACE}/$ENV_FILENAME"
200 cat ${WORKSPACE}/$ENV_FILENAME
202 source ${WORKSPACE}/${ENV_FILENAME}
204 git config --global user.email "${USER_EMAIL}"
205 git config --global user.name "${USER_NAME}"
206 git config --global color.ui false
212 msg_step="Init the repo and sync"
215 # Avoid the colorization prompt
216 git config --global color.ui false
218 if [ -d ${STX_REPO_ROOT}/.repo ]; then
219 echo_info "the src repos already exists, skipping"
223 RUN_CMD="repo init -u ${STX_MANIFEST_URL} -b ${STX_SRC_BRANCH} -m ${STX_MANIFEST}"
224 run_cmd "Init the repo from manifest"
226 RUN_CMD="repo sync --force-sync"
229 touch .repo-init-done
236 msg_step="Get src mirror from dockerhub image"
239 if [ -d ${STX_REPO_ROOT}/.repo ]; then
240 echo_info "the src repos already exists, skipping"
242 docker pull ${MIRROR_SRC_STX}
243 docker create -ti --name inf-src-stx ${MIRROR_SRC_STX} sh
244 #docker cp inf-src-stx:/stx-${STX_VER}.tar.bz2 ${STX_REPO_ROOT}
245 docker cp inf-src-stx:/stx-${STX_TAG}.tar.bz2 ${STX_REPO_ROOT}
246 docker rm inf-src-stx
249 #tar xf stx-${STX_VER}.tar.bz2
250 #mv stx-${STX_VER}/* stx-${STX_VER}/.repo .
251 #rm -rf stx-${STX_VER} stx-${STX_VER}.tar.bz2
252 tar xf stx-${STX_TAG}.tar.bz2
253 mv stx-${STX_SRC_BRANCH}/* stx-${STX_SRC_BRANCH}/.repo .
254 rm -rf stx-${STX_SRC_BRANCH} stx-${STX_TAG}.tar.bz2
255 touch .repo-init-done
263 msg_step="Get deb mirror from dockerhub image"
266 if [ -d ${STX_MIRROR_DIR}/starlingx ]; then
267 echo_info "The deb mirror already exists, skipping"
269 docker pull ${MIRROR_CONTAINER_IMG}
270 docker create -ti --name inf-debian-mirror ${MIRROR_CONTAINER_IMG} sh
271 docker cp inf-debian-mirror:/mirror-stx-${STX_VER}/. ${STX_MIRROR_DIR}
272 docker rm inf-debian-mirror
278 get_mirror_aptly () {
279 msg_step="Get deb mirror aptly from dockerhub image"
282 if [ -f ${STX_APTLY_DIR}/aptly.conf ]; then
283 echo_info "The deb aptly already exists, skipping"
285 docker pull ${MIRROR_APTLY_IMG}
286 docker create -ti --name inf-debian-aptly ${MIRROR_APTLY_IMG} sh
287 docker cp inf-debian-aptly:/aptly-stx-${STX_VER}/. ${STX_APTLY_DIR}
288 docker rm inf-debian-aptly
295 echo_step_start "Some source codes need to be patched for INF project"
297 STX_ISSUE_DIR="${STX_REPO_ROOT}/cgcs-root/stx/config-files/debian-release-config/files"
298 grep -q "${ORAN_REL}" ${STX_ISSUE_DIR}/issue* \
299 || sed -i "s/\(@PLATFORM_RELEASE@\)/\1 - ${ORAN_REL}/" ${STX_ISSUE_DIR}/issue*
301 grep -q "\-\-parallel" ${STX_REPO_ROOT}/stx-tools/stx/lib/stx/stx_build.py \
302 || sed -i 's/\(build-pkgs -a \)/\1 --parallel 2 --reuse /' \
303 ${STX_REPO_ROOT}/stx-tools/stx/lib/stx/stx_build.py
305 STX_LOCALRC="${STX_REPO_ROOT}/stx-tools/stx/stx-build-tools-chart/stx-builder/configmap/localrc.sample"
306 echo "export STX_SHARED_REPO=${STX_SHARED_REPO}" >> ${STX_LOCALRC}
307 echo "export STX_SHARED_SOURCE=${STX_SHARED_SOURCE}" >> ${STX_LOCALRC}
311 if [ -d ${SRC_META_PATCHES} ]; then
312 cd ${SRC_META_PATCHES}
313 src_dirs=$(find . -type f -printf "%h\n"|uniq)
314 for d in ${src_dirs}; do
315 cd ${STX_REPO_ROOT}/${d}
317 # backup current branch
318 local_branch=$(git rev-parse --abbrev-ref HEAD)
319 if [ "${local_branch}" = "HEAD" ]; then
320 git checkout ${STX_SRC_BRANCH}
321 local_branch=$(git rev-parse --abbrev-ref HEAD)
323 git branch -m "${local_branch}_${TIMESTAMP}"
324 git checkout ${STX_SRC_BRANCH}
326 for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do
327 echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}"
328 git am ${SRC_META_PATCHES}/${d}/${p}
337 echo_step_start "Init stx tool"
341 cp stx.conf.sample stx.conf
345 # Align the builder container to use your user/UID
346 stx config --add builder.myuname $(id -un)
347 stx config --add builder.uid $(id -u)
349 # Embedded in ~/localrc of the build container
350 stx config --add project.gituser ${USER_NAME}
351 stx config --add project.gitemail ${USER_EMAIL}
353 # This will be included in the name of your build container and the basename for $STX_REPO_ROOT
354 stx config --add project.name ${PRJ_NAME}
356 #stx config --add project.proxy true
357 #stx config --add project.proxyserver 147.11.252.42
358 #stx config --add project.proxyport 9090
366 echo_step_start "Build Debian images"
368 cd ${STX_REPO_ROOT}/stx-tools
369 RUN_CMD="./stx-init-env"
370 run_cmd "Run stx-init-env script"
374 # wait for all the pods running
378 RUN_CMD="stx build prepare"
379 run_cmd "Build prepare"
381 RUN_CMD="stx build download"
382 run_cmd "Download packges"
384 RUN_CMD="stx repomgr list"
385 run_cmd "repomgr list"
387 #RUN_CMD="stx shell -c 'build-pkgs -a --parallel 10'"
388 RUN_CMD="stx build world"
391 #RUN_CMD="stx shell -c 'build-image'"
392 RUN_CMD="stx build image"
393 run_cmd "Build ISO image"
395 cp -f ${STX_LOCAL_DIR}/deploy/starlingx-intel-x86-64-cd.iso ${STX_PRJ_OUTPUT}/${ISO_INF_DEB}
399 echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_INF_DEB}"
402 #########################################################################
404 #########################################################################
408 if [ "${USE_MIRROR}" == "Yes" ]; then