3 # Copyright (C) 2023 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_SCRIPTS_BRANCH="master"
26 SRC_SCRIPTS_URL="https://github.com/jackiehjm/stx-builds.git"
28 SCRIPTS_DIR=$(dirname $(readlink -f $0))
29 SCRIPTS_NAME=$(basename $0)
30 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
34 STX_SRC_BRANCH_SUPPORTED="\
39 WRCP_22.12_PRESTAGING \
41 STX_SRC_BRANCH="master"
42 STX_MANIFEST_URL="https://opendev.org/starlingx/manifest"
43 STX_MANIFEST_URL_WRCP="ssh://git@vxgit.wrs.com:7999/cgcs/github.com.stx-staging.stx-manifest.git"
51 # Source code fixes for ARM64
52 SRC_FIX_URL="https://github.com/jackiehjm"
53 SRC_FIX_BRANCH="arm64/20230515-stx80-native"
64 stx/ansible-playbooks \
69 SDK_URL="http://ala-lpggp5:5088/3_open_source/stx/images-arm64/lat-sdk/lat-sdk-build_20230525/AppSDK.sh"
71 #########################################################################
73 #########################################################################
78 ${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-p PARALLEL_BUILD] [-a arch] [-b STX_SRC_BRANCH] [-h]
80 -w WORKSPACE_DIR is the path for the project
81 -p PARALLEL_BUILD is the num of paralle build, default is 2
82 -a STX_ARCH is the build arch, default is x86-64, only supports: 'x86-64' and 'arm64'
83 -b STX_SRC_BRANCH is the branch for stx repos, default is master
92 [ -n "$1" ] && msg_step=$1
93 echo "#########################################################################################"
94 echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
95 echo "#########################################################################################"
99 [ -n "$1" ] && msg_step=$1
100 echo "#########################################################################################"
101 echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
102 echo "#########################################################################################"
117 echo "CMD: ${RUN_CMD}"
121 check_valid_branch () {
123 for b in ${STX_SRC_BRANCH_SUPPORTED}; do
124 if [ "${branch}" == "${b}" ]; then
125 BRANCH_VALID="${branch}"
129 if [ -z "${BRANCH_VALID}" ]; then
130 echo_error "${branch} is not a supported BRANCH, the supported BRANCHs are: ${STX_SRC_BRANCH_SUPPORTED}"
133 STX_SRC_BRANCH=${BRANCH_VALID}
137 check_valid_arch () {
139 for a in ${STX_ARCH_SUPPORTED}; do
140 if [ "${arch}" == "${a}" ]; then
145 if [ -z "${ARCH_VALID}" ]; then
146 echo_error "${arch} is not a supported ARCH, the supported ARCHs are: ${STX_ARCH_SUPPORTED}"
149 STX_ARCH=${ARCH_VALID}
154 #########################################################################
156 #########################################################################
159 while getopts "w:p:a:b:h" OPTION; do
162 WORKSPACE=`readlink -f ${OPTARG}`
165 STX_PARALLEL="${OPTARG}"
168 check_valid_arch ${OPTARG}
171 check_valid_branch ${OPTARG}
180 if [ -z ${WORKSPACE} ]; then
181 echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
182 WORKSPACE=`readlink -f workspace`
185 if [[ ${STX_SRC_BRANCH} =~ "WRCP" ]]; then
186 STX_MANIFEST_URL=${STX_MANIFEST_URL_WRCP}
189 #########################################################################
190 # Functions for each step
191 #########################################################################
193 # "_" can't be used in project name
196 STX_LOCAL_DIR=${WORKSPACE}/localdisk
197 STX_LOCAL_SRC_DIR=${STX_LOCAL_DIR}/designer/${USER}/${PRJ_NAME}
198 STX_LOCAL_PRJ_DIR=${STX_LOCAL_DIR}/loadbuild/${USER}/${PRJ_NAME}
199 STX_SRC_DIR=${WORKSPACE}/src
200 STX_PRJ_DIR=${WORKSPACE}/${PRJ_NAME}
201 STX_PRJ_OUTPUT=${WORKSPACE}/prj_output
202 STX_MIRROR_DIR=${WORKSPACE}/mirrors
203 STX_APTLY_DIR=${WORKSPACE}/aptly
204 STX_MINIKUBE_HOME=${WORKSPACE}/minikube_home
206 SRC_SCRIPTS_DIR=${STX_SRC_DIR}/stx-builds
207 SRC_META_PATCHES=${SRC_SCRIPTS_DIR}/build_stx_debian/meta-patches
209 ISO_STX_DEB_X86_DEPLOY=starlingx-intel-x86-64-cd.iso
210 ISO_STX_DEB_X86_OUTPUT=stx-image-debian-all-x86-64.iso
211 ISO_STX_DEB_ARM_DEPLOY=starlingx-qemuarm64-cd.iso
212 ISO_STX_DEB_ARM_OUTPUT=stx-image-debian-all-arm64.iso
214 prepare_workspace () {
215 msg_step="Create workspace for the Debian build"
218 mkdir -p ${STX_LOCAL_SRC_DIR} ${STX_LOCAL_PRJ_DIR} ${STX_MIRROR_DIR} \
219 ${STX_APTLY_DIR} ${STX_PRJ_OUTPUT} ${STX_MINIKUBE_HOME}
220 rm -f ${STX_SRC_DIR} ${STX_PRJ_DIR}
221 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_SRC_DIR}) ${STX_SRC_DIR}
222 ln -sf $(realpath --relative-to=${WORKSPACE} ${STX_LOCAL_PRJ_DIR}) ${STX_PRJ_DIR}
224 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
225 echo_info "For all source repos: ${STX_SRC_DIR}"
226 echo_info "For StarlingX deb pkgs mirror: ${STX_MIRROR_DIR}"
227 echo_info "For StarlingX build project: ${STX_PRJ_DIR}"
233 msg_step="Create env file for the Debian build"
236 GIT_USER=`git config user.name`
237 GIT_EMAIL=`git config user.email`
239 if [ -z "${GIT_USER}" ]; then
241 git config --global user.name "${GIT_USER}"
243 if [ -z "${GIT_EMAIL}" ]; then
244 GIT_EMAIL=${USER}@windriver.com
245 git config --global user.email "${GIT_EMAIL}"
248 ENV_FILENAME=env.${PRJ_NAME}
250 cat <<EOF > ${WORKSPACE}/${ENV_FILENAME}
252 export STX_BUILD_HOME=${WORKSPACE}
253 export PROJECT=${PRJ_NAME}
254 export STX_MIRROR_DIR=${STX_MIRROR_DIR}
255 export STX_REPO_ROOT=${STX_SRC_DIR}
256 #export STX_REPO_ROOT_SUBDIR="localdisk/designer/${USER}/${PRJ_NAME}"
258 export USER_NAME="${USER}"
259 export USER_EMAIL="${GIT_EMAIL}"
262 export STX_PLATFORM="minikube"
263 export STX_MINIKUBENAME="minikube-${USER}"
264 export MINIKUBE_HOME=${STX_MINIKUBE_HOME}
266 # Manifest/Repo Options:
267 export STX_MANIFEST_URL="${STX_MANIFEST_URL}"
268 export STX_MANIFEST_BRANCH="${STX_SRC_BRANCH}"
269 export STX_MANIFEST="default.xml"
273 echo_info "Env file created at ${WORKSPACE}/$ENV_FILENAME"
274 cat ${WORKSPACE}/$ENV_FILENAME
276 source ${WORKSPACE}/${ENV_FILENAME}
278 git config --global color.ui false
284 msg_step="Init the repo and sync"
287 # Avoid the colorization prompt
288 git config --global color.ui false
290 if [ -d ${STX_REPO_ROOT}/.repo ]; then
291 echo_info "the src repos already exists, skipping"
295 RUN_CMD="repo init -u ${STX_MANIFEST_URL} -b ${STX_SRC_BRANCH} -m ${STX_MANIFEST}"
296 run_cmd "Init the repo from manifest"
298 RUN_CMD="repo sync --force-sync"
301 touch .repo-init-done
307 clone_update_repo () {
313 if [ -d ${REPO_NAME}/.git ]; then
314 if [ "${SKIP_UPDATE}" == "Yes" ]; then
315 echo_info "The repo ${REPO_NAME} exists, skip updating for the branch ${REPO_BRANCH}"
317 echo_info "The repo ${REPO_NAME} exists, updating for the branch ${REPO_BRANCH}"
319 git checkout ${REPO_BRANCH}
324 RUN_CMD="git clone --branch ${REPO_BRANCH} ${REPO_URL} ${REPO_NAME}"
325 run_cmd "Cloning the source of repo '${REPO_NAME}':"
327 if [ -n "${REPO_COMMIT}" ]; then
329 RUN_CMD="git checkout -b ${REPO_BRANCH}-${REPO_COMMIT} ${REPO_COMMIT}"
330 run_cmd "Checkout the repo ${REPO_NAME} to specific commit: ${REPO_COMMIT}"
338 msg_step="Get the source code repos"
341 # Clone the stx-builds repo if it's not already cloned
342 # Check if the script is inside the repo
343 if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
344 CLONED_SCRIPTS_REPO=`git rev-parse --show-toplevel`
345 echo_info "Use the cloned stx-builds repo: ${CLONED_SCRIPTS_REPO}"
347 ln -sf ${CLONED_SCRIPTS_REPO}
349 echo_info "Cloning stx-builds repo:"
351 clone_update_repo ${SRC_SCRIPTS_BRANCH} ${SRC_SCRIPTS_URL}
361 for repo in ${SRC_FIX_REPOS}; do
362 if [ $repo = "cgcs-root" ]; then
363 fix_repo="stx-cgcs-root"
365 fix_repo="${repo/\//-}"
367 if [ -d ${STX_REPO_ROOT}/${repo} ]; then
368 echo_info "Patching for the ${repo}"
369 cd ${STX_REPO_ROOT}/${repo}
370 elif [ -d ${STX_REPO_ROOT}/cgcs-root/${repo} ]; then
371 echo_info "Patching for the cgcs-root/${repo}"
372 cd ${STX_REPO_ROOT}/cgcs-root/${repo}
374 echo_error "The repo ${repo} is not found!!"
377 git remote add hjm-github ${SRC_FIX_URL}/${fix_repo}
379 git checkout -b ${SRC_FIX_BRANCH} hjm-github/${SRC_FIX_BRANCH}
384 echo_step_start "Patching source codes for stx project"
386 if [ ${STX_ARCH} = "arm64" ]; then
390 STX_BUILDER="${STX_REPO_ROOT}/stx-tools/stx/lib/stx/stx_build.py"
391 echo_info "Patching for the ${STX_BUILDER}"
392 grep -q "\-\-parallel" ${STX_BUILDER} \
393 || sed -i "s/\(build-pkgs -a \)/\1 --parallel ${STX_PARALLEL} /" \
397 if [ -d ${SRC_META_PATCHES} ]; then
398 cd ${SRC_META_PATCHES}
399 src_dirs=$(find . -type f -printf "%h\n"|uniq)
400 for d in ${src_dirs}; do
401 cd ${STX_REPO_ROOT}/${d}
403 # backup current branch
404 local_branch=$(git rev-parse --abbrev-ref HEAD)
405 if [ "${local_branch}" = "HEAD" ]; then
406 git checkout ${STX_SRC_BRANCH}
407 local_branch=$(git rev-parse --abbrev-ref HEAD)
409 git branch -m "${local_branch}_${TIMESTAMP}"
410 git checkout ${STX_SRC_BRANCH}
412 for p in $(ls -1 ${SRC_META_PATCHES}/${d}); do
413 echo_info "Apllying patch: ${SRC_META_PATCHES}/${d}/${p}"
414 git am ${SRC_META_PATCHES}/${d}/${p}
423 # This is only needed for ARM64
424 echo_step_start "Prepare LAT-SDK"
426 SDK_DIR=${STX_REPO_ROOT}/stx-tools/stx/toCOPY/lat-sdk/
429 RUN_CMD="wget ${SDK_URL} -O ${SDK_DIR}/AppSDK.sh"
430 run_cmd "Download the ${SDK_URL} to ${SDK_DIR}"
436 echo_step_start "Init stx tool"
440 cp stx.conf.sample stx.conf
444 # Align the builder container to use your user/UID
445 stx config --add builder.myuname $(id -un)
446 stx config --add builder.uid $(id -u)
448 # Embedded in ~/localrc of the build container
449 stx config --add project.gituser ${USER_NAME}
450 stx config --add project.gitemail ${USER_EMAIL}
452 # This will be included in the name of your build container and the basename for $STX_REPO_ROOT
453 stx config --add project.name ${PRJ_NAME}
455 #stx config --add project.proxy true
456 #stx config --add project.proxyserver 147.11.252.42
457 #stx config --add project.proxyport 9090
465 echo_step_start "Build Debian images"
467 cd ${STX_REPO_ROOT}/stx-tools
468 if [ ${STX_ARCH} = "arm64" ]; then
469 RUN_CMD="./stx-init-env --rebuild"
471 RUN_CMD="./stx-init-env"
473 run_cmd "Run stx-init-env script"
477 # wait for all the pods running
481 RUN_CMD="stx build prepare"
482 run_cmd "Build prepare"
484 RUN_CMD="stx build download"
485 run_cmd "Download packges"
487 RUN_CMD="stx repomgr list"
488 run_cmd "repomgr list"
490 RUN_CMD="stx build world"
493 RUN_CMD="stx build image"
494 run_cmd "Build ISO image"
496 if [ ${STX_ARCH} = "arm64" ]; then
497 cp -f ${STX_LOCAL_DIR}/deploy/${ISO_STX_DEB_ARM_DEPLOY} ${STX_PRJ_OUTPUT}/${ISO_STX_DEB_ARM_OUTPUT}
499 cp -f ${STX_LOCAL_DIR}/deploy/${ISO_STX_DEB_X86_DEPLOY} ${STX_PRJ_OUTPUT}/${ISO_STX_DEB_X86_OUTPUT}
504 echo_info "Build succeeded, you can get the image in ${STX_PRJ_OUTPUT}/${ISO_STX_DEB}"
507 #########################################################################
509 #########################################################################
515 if [ ${STX_ARCH} = "arm64" ]; then