build_inf.sh: add debug info for CI jenkins build
[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 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
26
27 #########################################################################
28 # Common Functions
29 #########################################################################
30
31 help_info () {
32 cat << ENDHELP
33 Note:
34 This is a wrapper script to build both Yocto based and CentOS based images
35 with default options, and tend to be used by ORAN CI build only.
36 Usage:
37 $(basename $0) [-w WORKSPACE_DIR] [-n] [-h]
38 where:
39     -w WORKSPACE_DIR is the path for the project
40     -n dry-run only for bitbake
41     -h this help info
42 examples:
43 $0
44 $0 -w workspace
45 ENDHELP
46 }
47
48 echo_step_start() {
49     [ -n "$1" ] && msg_step=$1
50     echo "#########################################################################################"
51     echo "## STEP START: ${msg_step}"
52     echo "#########################################################################################"
53 }
54
55 echo_step_end() {
56     [ -n "$1" ] && msg_step=$1
57     echo "#########################################################################################"
58     echo "## STEP END: ${msg_step}"
59     echo "#########################################################################################"
60     echo
61 }
62
63 echo_info () {
64     echo "INFO: $1"
65 }
66
67 echo_error () {
68     echo "ERROR: $1"
69 }
70
71 echo_cmd () {
72     echo
73     echo_info "$1"
74     echo "CMD: ${RUN_CMD}"
75 }
76
77
78 #########################################################################
79 # Parse cmd options
80 #########################################################################
81
82 DRYRUN=""
83
84 while getopts "w:b:e:r:unh" OPTION; do
85     case ${OPTION} in
86         w)
87             WORKSPACE=`readlink -f ${OPTARG}`
88             ;;
89         n)
90             DRYRUN="-n"
91             ;;
92         h)
93             help_info
94             exit
95             ;;
96     esac
97 done
98
99 if [ -z ${WORKSPACE} ]; then
100     echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
101     WORKSPACE=`readlink -f workspace`
102 fi
103
104 #########################################################################
105 # Functions for each step
106 #########################################################################
107 WORKSPACE_YP=${WORKSPACE}/workspace_yocto
108 WORKSPACE_CENTOS=${WORKSPACE}/workspace_centos
109 SCRIPT_YP=${SCRIPTS_DIR}/build_inf_yocto/build_inf_yocto.sh
110 SCRIPT_CENTOS=${SCRIPTS_DIR}/build_inf_centos/build_inf_centos.sh
111
112 prepare_workspace () {
113     msg_step="Create workspace for the multi-os builds"
114     echo_step_start
115
116     mkdir -p ${WORKSPACE_YP} ${WORKSPACE_CENTOS}
117
118     echo_info "The following directories are created in your workspace(${WORKSPACE}):"
119     echo_info "For Yocto buid: ${WORKSPACE_YP}"
120     echo_info "For CentOS buid: ${WORKSPACE_CENTOS}"
121
122     echo_step_end
123 }
124
125 # debug for CI Jenkins build
126 get_debug_info () {
127     msg_step="Get debug info for CI Jenkins build"
128     echo_step_start
129
130     echo_info "=== Get env ==="
131     env
132     echo_info "==============="
133
134     set -x
135     df -h
136     groups
137     uname -a
138     cat /etc/*release
139     lscpu
140     free -h
141     rpm -qa|grep mock
142     mock --debug-config
143     docker version
144     set +x
145
146     echo_step_end
147 }
148
149
150 #########################################################################
151 # Main process
152 #########################################################################
153
154 prepare_workspace
155 if [ "$CI" = "true" ]; then
156     get_debug_info
157 fi
158
159 # dry-run is not supported yet for CentOS build
160 if [ -z "${DRYRUN}" ]; then
161     ${SCRIPT_CENTOS} -w ${WORKSPACE_CENTOS} ${DRYRUN}
162 fi
163
164 ${SCRIPT_YP} -w ${WORKSPACE_YP} ${DRYRUN}