build_inf.sh: build debian image only
[pti/rtp.git] / scripts / build_inf.sh
index e8bd658..82926aa 100755 (executable)
@@ -22,6 +22,7 @@ set -e -o pipefail
 #########################################################################
 
 SCRIPTS_DIR=$(dirname $(readlink -f $0))
+SCRIPTS_NAME=$(basename $0)
 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
 
 #########################################################################
@@ -34,7 +35,7 @@ Note:
 This is a wrapper script to build both Yocto based and CentOS based images
 with default options, and tend to be used by ORAN CI build only.
 Usage:
-$(basename $0) [-w WORKSPACE_DIR] [-n] [-h]
+${SCRIPTS_NAME} [-w WORKSPACE_DIR] [-n] [-h]
 where:
     -w WORKSPACE_DIR is the path for the project
     -n dry-run only for bitbake
@@ -48,14 +49,14 @@ ENDHELP
 echo_step_start() {
     [ -n "$1" ] && msg_step=$1
     echo "#########################################################################################"
-    echo "## STEP START: ${msg_step}"
+    echo "## ${SCRIPTS_NAME} - STEP START: ${msg_step}"
     echo "#########################################################################################"
 }
 
 echo_step_end() {
     [ -n "$1" ] && msg_step=$1
     echo "#########################################################################################"
-    echo "## STEP END: ${msg_step}"
+    echo "## ${SCRIPTS_NAME} - STEP END: ${msg_step}"
     echo "#########################################################################################"
     echo
 }
@@ -68,26 +69,40 @@ echo_error () {
     echo "ERROR: $1"
 }
 
-echo_cmd () {
+run_cmd () {
     echo
     echo_info "$1"
     echo "CMD: ${RUN_CMD}"
+    ${RUN_CMD}
 }
 
-
 #########################################################################
 # Parse cmd options
 #########################################################################
 
 DRYRUN=""
+YP_ARGS="-s"
+YOCTO_ONLY="No"
+CENTOS_ONLY="No"
+DEBIAN_ONLY="Yes"
 
-while getopts "w:b:e:r:unh" OPTION; do
+while getopts "w:ycdnh" OPTION; do
     case ${OPTION} in
         w)
             WORKSPACE=`readlink -f ${OPTARG}`
             ;;
         n)
             DRYRUN="-n"
+            YP_ARGS=""
+            ;;
+        y)
+            YOCTO_ONLY="Yes"
+            ;;
+        c)
+            CENTOS_ONLY="Yes"
+            ;;
+        d)
+            DEBIAN_ONLY="Yes"
             ;;
         h)
             help_info
@@ -106,32 +121,113 @@ fi
 #########################################################################
 WORKSPACE_YP=${WORKSPACE}/workspace_yocto
 WORKSPACE_CENTOS=${WORKSPACE}/workspace_centos
+WORKSPACE_DEB=${WORKSPACE}/workspace_debian
 SCRIPT_YP=${SCRIPTS_DIR}/build_inf_yocto/build_inf_yocto.sh
 SCRIPT_CENTOS=${SCRIPTS_DIR}/build_inf_centos/build_inf_centos.sh
+SCRIPT_CENTOS_PRE=${SCRIPTS_DIR}/build_inf_centos/build_inf_prepare_jenkins.sh
+SCRIPT_DEB=${SCRIPTS_DIR}/build_inf_debian/build_inf_debian.sh
+SCRIPT_DEB_PRE=${SCRIPTS_DIR}/build_inf_debian/build_inf_prepare_jenkins.sh
 
 prepare_workspace () {
     msg_step="Create workspace for the multi-os builds"
     echo_step_start
 
-    mkdir -p ${WORKSPACE_YP} ${WORKSPACE_CENTOS}
+    mkdir -p ${WORKSPACE_YP} ${WORKSPACE_CENTOS} ${WORKSPACE_DEB}
 
     echo_info "The following directories are created in your workspace(${WORKSPACE}):"
     echo_info "For Yocto buid: ${WORKSPACE_YP}"
     echo_info "For CentOS buid: ${WORKSPACE_CENTOS}"
+    echo_info "For Debian buid: ${WORKSPACE_DEB}"
 
     echo_step_end
 }
 
+# debug for CI Jenkins build
+get_debug_info () {
+    msg_step="Get debug info for CI Jenkins build"
+    echo_step_start
+
+    echo_info "=== Get env ==="
+    env
+    echo_info "==============="
+
+    set -x
+    df -h
+    groups
+    uname -a
+    cat /etc/*release
+    lscpu
+    free -h
+    rpm -qa|grep mock
+    mock --debug-config
+    docker version
+    set +x
+
+    echo_step_end
+}
+
+build_yocto () {
+    msg_step="Yocto builds"
+    echo_step_start
+
+    RUN_CMD="${SCRIPT_YP} -w ${WORKSPACE_YP} ${DRYRUN} ${YP_ARGS}"
+    run_cmd "Start Yocto builds"
+
+    echo_step_end
+}
+
+build_centos () {
+    # dry-run is not supported yet for CentOS build
+    if [ -z "${DRYRUN}" ]; then
+        msg_step="CentOS builds"
+        echo_step_start
+
+        if [ "$CI" = "true" ]; then
+            RUN_CMD="${SCRIPT_CENTOS_PRE} -w ${WORKSPACE_CENTOS}"
+            run_cmd "Prepare for CentOS builds"
+        fi
+        RUN_CMD="${SCRIPT_CENTOS} -w ${WORKSPACE_CENTOS} -m ${DRYRUN}"
+        run_cmd "Start CentOS builds"
+
+        echo_step_end
+    fi
+}
+
+build_debian () {
+    if [ -z "${DRYRUN}" ]; then
+        msg_step="Debian builds"
+        echo_step_start
+
+        if [ "$CI" = "true" ]; then
+            RUN_CMD="${SCRIPT_DEB_PRE} -w ${WORKSPACE_DEB}"
+            run_cmd "Prepare for Debian builds"
+        fi
+
+        RUN_CMD="${SCRIPT_DEB} -w ${WORKSPACE_DEB} -m ${DRYRUN}"
+        run_cmd "Start Debian builds"
+
+        echo_step_end
+    fi
+}
+
 
 #########################################################################
 # Main process
 #########################################################################
 
 prepare_workspace
+if [ "$CI" = "true" ]; then
+    get_debug_info
+fi
 
-${SCRIPT_CENTOS} -w ${WORKSPACE_CENTOS} ${DRYRUN}
-
-# dry-run is not supported yet for CentOS build
-if [ -z "${DRYRUN}" ]; then
-    ${SCRIPT_YP} -w ${WORKSPACE_YP} ${DRYRUN}
+if [ "${YOCTO_ONLY}" == "Yes" ]; then
+    build_yocto
+elif [ "${CENTOS_ONLY}" == "Yes" ]; then
+    build_centos
+elif [ "${DEBIAN_ONLY}" == "Yes" ]; then
+    build_debian
+else
+    build_centos
+    build_yocto
+    build_debian
 fi