build package 51/50751/2
authorQiaowei Ren <qiaowei.ren@intel.com>
Thu, 18 Jan 2018 04:39:37 +0000 (12:39 +0800)
committerQiaowei Ren <qiaowei.ren@intel.com>
Fri, 19 Jan 2018 01:52:21 +0000 (09:52 +0800)
This patch is to build debian/centos package. Currently it only
can build ceph package and only support debian package building
from ceph official repo.

Change-Id: I702a1d28dd0101156bc3267d93510133db122613
Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
ci/build.sh [new file with mode: 0755]
ci/build_deb/Dockerfile [new file with mode: 0644]
ci/build_interface.sh [new file with mode: 0755]
ci/build_rpm/Dockerfile [new file with mode: 0644]
ci/ceph_build.sh [new file with mode: 0755]

diff --git a/ci/build.sh b/ci/build.sh
new file mode 100755 (executable)
index 0000000..61a5cc6
--- /dev/null
@@ -0,0 +1,116 @@
+#!/bin/bash
+#
+# Common parameter parsing for kvmfornfv scripts
+#
+
+function usage() {
+    echo ""
+    echo "Usage --> $0 [-p package_type] [-o output_dir] [-h]"
+    echo "  package_type : centos/ubuntu/both ;  default is ubuntu"
+    echo "  output_dir : stores rpm and debian packages"
+    echo "  -h : Help section"
+    echo ""
+}
+
+output_dir=""
+type=""
+
+function run() {
+   case $1 in
+      centos)
+         cd $WORKSPACE/ci/build_rpm
+         sudo docker build -t stor_rpm .
+         sudo docker run --privileged=true -v $WORKSPACE:/opt/stor4nfv -t  stor_rpm \
+                      /opt/stor4nfv/ci/build_interface.sh $1
+      ;;
+      ubuntu)
+         cd $WORKSPACE/ci/build_deb
+         sudo docker build -t stor_deb .
+         sudo docker run -v $WORKSPACE:/opt/stor4nfv -t  stor_deb \
+                     /opt/stor4nfv/ci/build_interface.sh $1
+      ;;
+      *) echo "Not supported system"; exit 1;;
+   esac
+}
+
+function build_package() {
+    choice=$1
+    case "$choice" in
+        "centos"|"ubuntu")
+            echo "Build $choice Rpms/Debians"
+            run $choice
+        ;;
+        "both")
+            echo "Build $choice Debians and Rpms"
+            run "centos"
+            run "ubuntu"
+        ;;
+        *)
+            echo "Invalid package option"
+            usage
+            exit 1
+        ;;
+    esac
+}
+
+##  --- Parse command line arguments / parameters ---
+while getopts ":o:p:h" option; do
+    case $option in
+        p) # package
+          type=$OPTARG
+          ;;
+        o) # output_dir
+          output_dir=$OPTARG
+          ;;
+        :)
+          echo "Option -$OPTARG requires an argument."
+          usage
+          exit 1
+          ;;
+        h)
+          usage
+          exit 0
+          ;;
+        *)
+          echo "Unknown option: $OPTARG."
+          usage
+          exit 1
+          ;;
+        ?)
+          echo "[WARNING] Unknown parameters!!!"
+          echo "Using default values for package generation & output"
+    esac
+done
+
+if [[ -z "$type" ]]
+then
+    type='ubuntu'
+fi
+
+if [[ -z "$output_dir" ]]
+then
+    output_dir=$WORKSPACE/build_output
+fi
+
+job_type=`echo $JOB_NAME | cut -d '-' -f 2`
+
+echo ""
+echo "Building for $type package in $output_dir"
+echo ""
+
+mkdir -p $output_dir
+build_package $type
+
+if [ $job_type == "verify" ]; then
+   if [ $type == "centos" ]; then
+      #echo "Removing kernel-debuginfo rpm from output_dir"
+      #rm -f ${output_dir}/kernel-debug*
+      echo "Checking packages in output_dir"
+      ls -lrth ${output_dir}
+   else
+     echo "Removing debug debian from output_dir"
+     rm -f ${output_dir}/*dbg*
+     echo "Checking packages in output_dir"
+     ls -lrth ${output_dir}
+   fi
+fi
diff --git a/ci/build_deb/Dockerfile b/ci/build_deb/Dockerfile
new file mode 100644 (file)
index 0000000..bcaeba3
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+FROM ubuntu:16.04
+RUN apt-get update && apt-get install -y \
+  sudo \
+  git \
+  cmake \
+  debhelper \
+  python-pip
+RUN echo "ALL ALL=NOPASSWD: ALL" > /etc/sudoers.d/open-sudo
+RUN chmod 0440 /etc/sudoers.d/open-sudo
diff --git a/ci/build_interface.sh b/ci/build_interface.sh
new file mode 100755 (executable)
index 0000000..343b84d
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+type=$1
+
+tmp_build_dir=/root/stor4nfv
+build_dir=/opt/stor4nfv
+tmp_output_dir=$tmp_build_dir/build_output
+output_dir=$build_dir/build_output
+cp -r $build_dir $tmp_build_dir
+
+cd $tmp_build_dir
+# Build ceph packages
+./ci/ceph_build.sh build_output $type
+
+if [ $type == "centos" ];then
+   # Move Ceph Rpm builds from tmp_output_dir to output_dir
+   mv $tmp_output_dir/*.rpm $output_dir
+elif [ $type == "ubuntu" ];then
+   # Move Ceph Debian builds from tmp_output_dir to output_dir
+   mv $tmp_output_dir/*.deb $output_dir
+fi
diff --git a/ci/build_rpm/Dockerfile b/ci/build_rpm/Dockerfile
new file mode 100644 (file)
index 0000000..b341fcc
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+FROM centos
+RUN yum -y update && yum -y install \
+  git \
+  cmake \
+  python-pip \
+  rpm \
+  rpm-build
diff --git a/ci/ceph_build.sh b/ci/ceph_build.sh
new file mode 100755 (executable)
index 0000000..1e16b2c
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+workspace=/root
+build_dir=$workspace/stor4nfv
+ceph_src_dir=$build_dir/src/ceph
+
+function show_stage {
+    echo
+    echo $1
+    echo
+}
+
+function ceph_build_validate {
+    show_stage "validate"
+    if [[ -z "$@" ]]; then
+        echo "usage: ${0} output_dir pkgtype"
+       exit 1
+    fi
+    output_dir="$1"
+    pkgtype="$2"
+    if [ ! -d ${output_dir} -o ! -w ${output_dir} ] ; then
+        echo "${0}: Output directory '${output_dir}' does not exist or cannot be written"
+        exit 1
+    fi
+    if [ ! -d ${ceph_src_dir} ] ; then
+        echo "${0}: Directory '${ceph_src_dir}' does not exist, run this script from the root of stor4nfv source tree"
+        exit 1
+    fi
+    echo
+    echo "Build"
+    echo
+}
+
+# Build ceph
+show_stage "compile"
+# TODO: use code inside stor4nfv
+cd $workspace
+git clone https://github.com/ceph/ceph.git
+cd ceph
+git reset --hard v12.2.2
+git submodule update --init --recursive
+./install-deps.sh
+./do_cmake.sh
+cd build
+make
+
+ceph_rpm_build() {
+    show_stage "ceph rpm build"
+}
+
+ceph_deb_build() {
+    cd $workspace/ceph
+    dpkg-buildpackage
+    if [ ${?} -ne 0 ] ; then
+        echo "${0}: ceph build failed"
+        exit 1
+    fi
+}
+
+if [ $pkgtype == "centos" ];then
+   ceph_rpm_build
+elif [ $pkgtype == "ubuntu" ];then
+   ceph_deb_build
+   latest_ceph_build=`ls -rt $workspace | tail -1`
+   cp $workspace/$latest_ceph_build $build_dir/build_output
+fi