From 04a66a586cc90b2be310d2323d526e11c95ab258 Mon Sep 17 00:00:00 2001 From: zeyu zhu Date: Tue, 29 Nov 2016 20:09:59 +0800 Subject: Implement of build script in Escalator Change-Id: I1296eec05c59f253ee5ce73d2477825689997275 Signed-off-by: zeyu zhu --- ci/build.sh | 8 ++++++ ci/build_rpm/Dockerfile | 29 ++++++++++++++++++++ ci/build_rpm/build_rpms.sh | 58 +++++++++++++++++++++++++++++++++++++++ ci/build_rpm/build_rpms_docker.sh | 46 +++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100755 ci/build.sh create mode 100644 ci/build_rpm/Dockerfile create mode 100755 ci/build_rpm/build_rpms.sh create mode 100755 ci/build_rpm/build_rpms_docker.sh (limited to 'ci') diff --git a/ci/build.sh b/ci/build.sh new file mode 100755 index 0000000..5a6ad73 --- /dev/null +++ b/ci/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# TODO: Let JJB to pass $WORKDIR instead of $BUILD_OUTPUT +ESCALATORDIR=$1/../ +OPNFV_ARTIFACT_VERSION=$2 + +cd ci/build_rpm +./build_rpms.sh $ESCALATORDIR $OPNFV_ARTIFACT_VERSION diff --git a/ci/build_rpm/Dockerfile b/ci/build_rpm/Dockerfile new file mode 100644 index 0000000..48e254f --- /dev/null +++ b/ci/build_rpm/Dockerfile @@ -0,0 +1,29 @@ +FROM centos:7 +LABEL escalator_image_version=1.0 +RUN yum -y update +RUN yum -y install centos-release-openstack-newton +RUN yum -y install \ + wget \ + coreutils \ + which \ + gawk \ + grep \ + git \ + intltool \ + make \ + rpm \ + rpm-build \ + python-sphinx \ + python2-oslo-sphinx \ + python2-oslo-messaging \ + python2-oslo-concurrency \ + python2-oslo-sphinx \ + python-devel \ + python-d2to1 \ + python-django-compressor \ + python-django-openstack-auth \ + python-django-pyscss \ + python-lesscpy \ + python-migrate \ + python-pint \ + python-routes diff --git a/ci/build_rpm/build_rpms.sh b/ci/build_rpm/build_rpms.sh new file mode 100755 index 0000000..81443ca --- /dev/null +++ b/ci/build_rpm/build_rpms.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -eux +ESCALATORDIR=$1 +OPNFV_ARTIFACT_VERSION=$2 + +function build_rpm_pkg { + # Cleanup prev build resutls + rm -rf $ESCALATORDIR/build_output + mkdir -p $ESCALATORDIR/build_output + + sudo docker build -t escalator_rpm . + sudo docker run --rm -v $ESCALATORDIR:/opt/escalator -v $CACHE_DIRECTORY:/home/cache -t escalator_rpm \ + /opt/escalator/ci/build_rpm/build_rpms_docker.sh $OPNFV_ARTIFACT_VERSION + + # Here to collect build result from $ESCALATORDIR/build_output +} + +function cleanup_container { + containers_to_kill=$(sudo docker ps --filter "label=escalator_image_version" \ + --format "{{.Names}}" -a) + + if [[ -z "$containers_to_kill" ]]; then + echo "No containers to cleanup." + else + volumes_to_remove=$(sudo docker inspect -f \ + '{{range .Mounts}} {{printf "%s\n" .Name }}{{end}}' \ + ${containers_to_kill} | egrep -v '(^\s*$)' | sort | uniq) + echo "Stopping containers... $containers_to_kill" + sudo docker stop -t 2 ${containers_to_kill} >/dev/null 2>&1 + + echo "Removing containers... $containers_to_kill" + sudo docker rm -v -f ${containers_to_kill} >/dev/null 2>&1 + + if [[ -z "$volumes_to_remove" ]]; then + echo "No volumes to cleanup." + else + echo "Removing volumes... $volumes_to_remove" + sudo docker volume rm ${volumes_to_remove} >/dev/null 2>&1 + fi + fi +} + +function cleanup_docker_image { + images_to_delete=$(sudo docker images -a --filter "label=escalator_image_version" \ + --format "{{.ID}}") + + echo "Removing images... $images_to_delete" + if [[ -z "$images_to_delete" ]]; then + echo "No images to cleanup" + else + sudo docker rmi -f ${images_to_delete} >/dev/null 2>&1 + fi +} + +cleanup_container +cleanup_docker_image +build_rpm_pkg diff --git a/ci/build_rpm/build_rpms_docker.sh b/ci/build_rpm/build_rpms_docker.sh new file mode 100755 index 0000000..9b2454d --- /dev/null +++ b/ci/build_rpm/build_rpms_docker.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +OPNFV_ARTIFACT_VERSION=$1 +rpm_build_dir=/opt/escalator +rpm_output_dir=$rpm_build_dir/build_output +tmp_rpm_build_dir=/root/escalator + +cp -r $rpm_build_dir $tmp_rpm_build_dir +cd $tmp_rpm_build_dir + +echo "#########################################################" +echo " systemctl info: " +echo "#########################################################" +echo "###Uname: $(uname)" +echo "###Hostname: $(hostname)" + +maxcount=3 +cnt=0 +rc=1 +while [ $cnt -lt $maxcount ] && [ $rc -ne 0 ] +do + cnt=$[cnt + 1] + echo -e "\n\n\n*** Starting build attempt # $cnt" + + cd api + python setup.py sdist + + cd .. + cd client + python setup.py sdist + + echo "######################################################" + echo " done " + echo "######################################################" + if [ $rc -ne 0 ]; then + echo "### Build failed with rc $rc ###" + else + echo "### Build successfully at attempt # $cnt" + fi +done +cd $rpm_output_dir +mkdir upload_artifacts +cp api/dist/escalator-* $rpm_output_dir/upload_artifacts +cp client/dist/escalatorclient-* $rpm_output_dir/upload_artifacts +tar zcvf opnfv-$OPNFV_ARTIFACT_VERSION.tar.gz upload_artifacts +exit $rc -- cgit 1.2.3-korg