build_inf.sh: temp step for CI test
[pti/rtp.git] / scripts / build_inf.sh
1 #!/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.
18 set -e -o pipefail
19
20 #########################################################################
21 # Variables
22 #########################################################################
23
24 SCRIPTS_DIR=$(dirname $(readlink -f $0))
25 SCRIPTS_NAME=$(basename $0)
26 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
27
28 #########################################################################
29 # Common Functions
30 #########################################################################
31
32 help_info () {
33 cat << ENDHELP
34 Note:
35 This is a wrapper script to build both Yocto based and CentOS based images
36 with default options, and tend to be used by ORAN CI build only.
37 Usage:
38 ${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-n] [-h]
39 where:
40     -w WORKSPACE_DIR is the path for the project
41     -n dry-run only for bitbake
42     -h this help info
43 examples:
44 $0
45 $0 -w workspace
46 ENDHELP
47 }
48
49 echo_step_start() {
50     [ -n "$1" ] && msg_step=$1
51     echo "#########################################################################################"
52     echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
53     echo "#########################################################################################"
54 }
55
56 echo_step_end() {
57     [ -n "$1" ] && msg_step=$1
58     echo "#########################################################################################"
59     echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
60     echo "#########################################################################################"
61     echo
62 }
63
64 echo_info () {
65     echo "INFO: $1"
66 }
67
68 echo_error () {
69     echo "ERROR: $1"
70 }
71
72 run_cmd () {
73     echo
74     echo_info "$1"
75     echo "CMD: ${RUN_CMD}"
76     ${RUN_CMD}
77 }
78
79 #########################################################################
80 # Parse cmd options
81 #########################################################################
82
83 DRYRUN="-n"
84 YP_ARGS="-s"
85
86 while getopts "w:b:e:r:unh" OPTION; do
87     case ${OPTION} in
88         w)
89             WORKSPACE=`readlink -f ${OPTARG}`
90             ;;
91         n)
92             DRYRUN="-n"
93             YP_ARGS=""
94             ;;
95         h)
96             help_info
97             exit
98             ;;
99     esac
100 done
101
102 if [ -z ${WORKSPACE} ]; then
103     echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
104     WORKSPACE=`readlink -f workspace`
105 fi
106
107 #########################################################################
108 # Functions for each step
109 #########################################################################
110 WORKSPACE_YP=${WORKSPACE}/workspace_yocto
111 WORKSPACE_CENTOS=${WORKSPACE}/workspace_centos
112 WORKSPACE_DEB=${WORKSPACE}/workspace_debian
113 SCRIPT_YP=${SCRIPTS_DIR}/build_inf_yocto/build_inf_yocto.sh
114 SCRIPT_CENTOS=${SCRIPTS_DIR}/build_inf_centos/build_inf_centos.sh
115 SCRIPT_CENTOS_PRE=${SCRIPTS_DIR}/build_inf_centos/build_inf_prepare_jenkins.sh
116 SCRIPT_DEB=${SCRIPTS_DIR}/build_inf_debian/build_inf_debian.sh
117 SCRIPT_DEB_PRE=${SCRIPTS_DIR}/build_inf_debian/build_inf_prepare_jenkins.sh
118
119 prepare_workspace () {
120     msg_step="Create workspace for the multi-os builds"
121     echo_step_start
122
123     mkdir -p ${WORKSPACE_YP} ${WORKSPACE_CENTOS}
124
125     echo_info "The following directories are created in your workspace(${WORKSPACE}):"
126     echo_info "For Yocto buid: ${WORKSPACE_YP}"
127     echo_info "For CentOS buid: ${WORKSPACE_CENTOS}"
128
129     echo_step_end
130 }
131
132 # debug for CI Jenkins build
133 get_debug_info () {
134     msg_step="Get debug info for CI Jenkins build"
135     echo_step_start
136
137     echo_info "=== Get env ==="
138     env
139     echo_info "==============="
140
141     set -x
142     df -h
143     groups
144     uname -a
145     cat /etc/*release
146     lscpu
147     free -h
148     rpm -qa|grep mock
149     mock --debug-config
150     docker version
151     set +x
152
153     echo_step_end
154 }
155
156 build_yocto () {
157     msg_step="Yocto builds"
158     echo_step_start
159
160     RUN_CMD="${SCRIPT_YP} -w ${WORKSPACE_YP} ${DRYRUN} ${YP_ARGS}"
161     run_cmd "Start Yocto builds"
162
163     echo_step_end
164 }
165
166 build_centos () {
167     # dry-run is not supported yet for CentOS build
168     if [ -z "${DRYRUN}" ]; then
169         msg_step="CentOS builds"
170         echo_step_start
171
172         if [ "$CI" = "true" ]; then
173             RUN_CMD="${SCRIPT_CENTOS_PRE} -w ${WORKSPACE_CENTOS}"
174             run_cmd "Prepare for CentOS builds"
175         fi
176         RUN_CMD="${SCRIPT_CENTOS} -w ${WORKSPACE_CENTOS} ${DRYRUN}"
177         run_cmd "Start CentOS builds"
178
179         echo_step_end
180     fi
181 }
182
183 build_centos_dl () {
184     # Temp for testing the lftools deploy
185     mkdir -p ${WORKSPACE_DEB}/prj_output/
186     wget http://mirror.starlingx.cengn.ca/mirror/starlingx/master/debian/monolithic/latest_build/outputs/iso/starlingx-intel-x86-64-cd.iso -O ${WORKSPACE_DEB}/prj_output/inf-image-debian-all-x86-64.iso
187 }
188
189 build_debian () {
190     if [ -z "${DRYRUN}" ]; then
191         msg_step="Debian builds"
192         echo_step_start
193
194         if [ "$CI" = "true" ]; then
195             RUN_CMD="${SCRIPT_DEB_PRE} -w ${WORKSPACE_DEB}"
196             run_cmd "Prepare for Debian builds"
197         fi
198
199         RUN_CMD="${SCRIPT_DEB} -w ${WORKSPACE_DEB} ${DRYRUN}"
200         run_cmd "Start Yocto builds"
201
202         echo_step_end
203     fi
204 }
205
206
207 #########################################################################
208 # Main process
209 #########################################################################
210
211 prepare_workspace
212 if [ "$CI" = "true" ]; then
213     get_debug_info
214 fi
215
216 build_yocto
217 #build_centos
218 build_centos_dl
219 #build_debian
220