summaryrefslogtreecommitdiffstats
path: root/ci/build_rpm/build_rpms.sh
diff options
context:
space:
mode:
authorzeyu zhu <zhu.zeyu@zte.com.cn>2016-11-29 20:09:59 +0800
committerzeyu zhu <zhu.zeyu@zte.com.cn>2016-12-14 14:28:24 +0800
commit04a66a586cc90b2be310d2323d526e11c95ab258 (patch)
tree528422e0b41e9c853b9fb76ebb50959d219822eb /ci/build_rpm/build_rpms.sh
parent6963d16b32f0c40ea45be66bbd189d2d5bb070fb (diff)
Implement of build script in Escalator
Change-Id: I1296eec05c59f253ee5ce73d2477825689997275 Signed-off-by: zeyu zhu <zhu.zeyu@zte.com.cn>
Diffstat (limited to 'ci/build_rpm/build_rpms.sh')
-rwxr-xr-xci/build_rpm/build_rpms.sh58
1 files changed, 58 insertions, 0 deletions
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