build package
[stor4nfv.git] / ci / build.sh
1 #!/bin/bash
2 #
3 # Common parameter parsing for kvmfornfv scripts
4 #
5
6 function usage() {
7     echo ""
8     echo "Usage --> $0 [-p package_type] [-o output_dir] [-h]"
9     echo "  package_type : centos/ubuntu/both ;  default is ubuntu"
10     echo "  output_dir : stores rpm and debian packages"
11     echo "  -h : Help section"
12     echo ""
13 }
14
15 output_dir=""
16 type=""
17
18 function run() {
19    case $1 in
20       centos)
21          cd $WORKSPACE/ci/build_rpm
22          sudo docker build -t stor_rpm .
23          sudo docker run --privileged=true -v $WORKSPACE:/opt/stor4nfv -t  stor_rpm \
24                       /opt/stor4nfv/ci/build_interface.sh $1
25       ;;
26       ubuntu)
27          cd $WORKSPACE/ci/build_deb
28          sudo docker build -t stor_deb .
29          sudo docker run -v $WORKSPACE:/opt/stor4nfv -t  stor_deb \
30                      /opt/stor4nfv/ci/build_interface.sh $1
31       ;;
32       *) echo "Not supported system"; exit 1;;
33    esac
34 }
35
36 function build_package() {
37     choice=$1
38     case "$choice" in
39         "centos"|"ubuntu")
40             echo "Build $choice Rpms/Debians"
41             run $choice
42         ;;
43         "both")
44             echo "Build $choice Debians and Rpms"
45             run "centos"
46             run "ubuntu"
47         ;;
48         *)
49             echo "Invalid package option"
50             usage
51             exit 1
52         ;;
53     esac
54 }
55
56 ##  --- Parse command line arguments / parameters ---
57 while getopts ":o:p:h" option; do
58     case $option in
59         p) # package
60           type=$OPTARG
61           ;;
62         o) # output_dir
63           output_dir=$OPTARG
64           ;;
65         :)
66           echo "Option -$OPTARG requires an argument."
67           usage
68           exit 1
69           ;;
70         h)
71           usage
72           exit 0
73           ;;
74         *)
75           echo "Unknown option: $OPTARG."
76           usage
77           exit 1
78           ;;
79         ?)
80           echo "[WARNING] Unknown parameters!!!"
81           echo "Using default values for package generation & output"
82     esac
83 done
84
85 if [[ -z "$type" ]]
86 then
87     type='ubuntu'
88 fi
89
90 if [[ -z "$output_dir" ]]
91 then
92     output_dir=$WORKSPACE/build_output
93 fi
94
95 job_type=`echo $JOB_NAME | cut -d '-' -f 2`
96
97 echo ""
98 echo "Building for $type package in $output_dir"
99 echo ""
100
101 mkdir -p $output_dir
102 build_package $type
103
104 if [ $job_type == "verify" ]; then
105    if [ $type == "centos" ]; then
106       #echo "Removing kernel-debuginfo rpm from output_dir"
107       #rm -f ${output_dir}/kernel-debug*
108       echo "Checking packages in output_dir"
109       ls -lrth ${output_dir}
110    else
111      echo "Removing debug debian from output_dir"
112      rm -f ${output_dir}/*dbg*
113      echo "Checking packages in output_dir"
114      ls -lrth ${output_dir}
115    fi
116 fi