blob: 81be9d53fd247dfd552b7eee9871b76b7246f46e [file] [log] [blame]
Jackie Huangcb89a812022-05-17 14:42:39 +08001#!/bin/bash
2#
3# Copyright (C) 2022 Wind River Systems, Inc.
4#
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
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17# Ensure we fail the job if any steps fail.
18set -e -o pipefail
19
20#########################################################################
21# Variables
22#########################################################################
23
24SCRIPTS_DIR=$(dirname $(readlink -f $0))
25TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
26
27#########################################################################
28# Common Functions
29#########################################################################
30
31help_info () {
32cat << ENDHELP
33Note:
34This is a wrapper script to build both Yocto based and CentOS based images
35with default options, and tend to be used by ORAN CI build only.
36Usage:
37$(basename $0) [-w WORKSPACE_DIR] [-n] [-h]
38where:
39 -w WORKSPACE_DIR is the path for the project
40 -n dry-run only for bitbake
41 -h this help info
42examples:
43$0
44$0 -w workspace
45ENDHELP
46}
47
48echo_step_start() {
49 [ -n "$1" ] && msg_step=$1
50 echo "#########################################################################################"
51 echo "## STEP START: ${msg_step}"
52 echo "#########################################################################################"
53}
54
55echo_step_end() {
56 [ -n "$1" ] && msg_step=$1
57 echo "#########################################################################################"
58 echo "## STEP END: ${msg_step}"
59 echo "#########################################################################################"
60 echo
61}
62
63echo_info () {
64 echo "INFO: $1"
65}
66
67echo_error () {
68 echo "ERROR: $1"
69}
70
71echo_cmd () {
72 echo
73 echo_info "$1"
74 echo "CMD: ${RUN_CMD}"
75}
76
77
78#########################################################################
79# Parse cmd options
80#########################################################################
81
82DRYRUN=""
Jackie Huang80492bc2022-05-18 17:02:38 +080083YP_ARGS="-s"
Jackie Huangcb89a812022-05-17 14:42:39 +080084
85while getopts "w:b:e:r:unh" OPTION; do
86 case ${OPTION} in
87 w)
88 WORKSPACE=`readlink -f ${OPTARG}`
89 ;;
90 n)
91 DRYRUN="-n"
Jackie Huang80492bc2022-05-18 17:02:38 +080092 YP_ARGS=""
Jackie Huangcb89a812022-05-17 14:42:39 +080093 ;;
94 h)
95 help_info
96 exit
97 ;;
98 esac
99done
100
101if [ -z ${WORKSPACE} ]; then
102 echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
103 WORKSPACE=`readlink -f workspace`
104fi
105
106#########################################################################
107# Functions for each step
108#########################################################################
109WORKSPACE_YP=${WORKSPACE}/workspace_yocto
110WORKSPACE_CENTOS=${WORKSPACE}/workspace_centos
111SCRIPT_YP=${SCRIPTS_DIR}/build_inf_yocto/build_inf_yocto.sh
112SCRIPT_CENTOS=${SCRIPTS_DIR}/build_inf_centos/build_inf_centos.sh
113
114prepare_workspace () {
115 msg_step="Create workspace for the multi-os builds"
116 echo_step_start
117
118 mkdir -p ${WORKSPACE_YP} ${WORKSPACE_CENTOS}
119
120 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
121 echo_info "For Yocto buid: ${WORKSPACE_YP}"
122 echo_info "For CentOS buid: ${WORKSPACE_CENTOS}"
123
124 echo_step_end
125}
126
Jackie Huangecb441b2022-05-18 09:41:42 +0800127# debug for CI Jenkins build
128get_debug_info () {
129 msg_step="Get debug info for CI Jenkins build"
130 echo_step_start
131
132 echo_info "=== Get env ==="
133 env
134 echo_info "==============="
135
136 set -x
137 df -h
138 groups
139 uname -a
140 cat /etc/*release
141 lscpu
142 free -h
143 rpm -qa|grep mock
144 mock --debug-config
145 docker version
146 set +x
147
148 echo_step_end
149}
150
Jackie Huangcb89a812022-05-17 14:42:39 +0800151
152#########################################################################
153# Main process
154#########################################################################
155
156prepare_workspace
Jackie Huangecb441b2022-05-18 09:41:42 +0800157if [ "$CI" = "true" ]; then
158 get_debug_info
159fi
Jackie Huangcb89a812022-05-17 14:42:39 +0800160
161# dry-run is not supported yet for CentOS build
162if [ -z "${DRYRUN}" ]; then
Jackie Huangecb441b2022-05-18 09:41:42 +0800163 ${SCRIPT_CENTOS} -w ${WORKSPACE_CENTOS} ${DRYRUN}
Jackie Huangcb89a812022-05-17 14:42:39 +0800164fi
Jackie Huangecb441b2022-05-18 09:41:42 +0800165
Jackie Huang80492bc2022-05-18 17:02:38 +0800166${SCRIPT_YP} -w ${WORKSPACE_YP} ${DRYRUN} ${YP_ARGS}