summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Bjurel <jonas.bjurel@ericsson.com>2015-10-07 16:10:16 +0200
committerJonas Bjurel <jonas.bjurel@ericsson.com>2015-10-08 12:52:11 +0000
commit3826a75ae3060b350ecefbc0eb20b4e81786638d (patch)
tree36e0daca80c0346d61b89492986f85f2fff571d1
parent57962daaf850d64580d20ffc1f076f3f2fbea9e2 (diff)
CAN MERGE
VERIFIED Description: Improved handling of docker clean-up JIRA: FUEL-71 Change-Id: I565f77e227da2dcbaecd86582ab6890508726607 Signed-off-by: Jonas Bjurel <jonas.bjurel@ericsson.com>
-rwxr-xr-xfuel/build/docker/runcontext37
1 files changed, 27 insertions, 10 deletions
diff --git a/fuel/build/docker/runcontext b/fuel/build/docker/runcontext
index 52b46ad14..77e4921e1 100755
--- a/fuel/build/docker/runcontext
+++ b/fuel/build/docker/runcontext
@@ -1,4 +1,5 @@
#!/bin/bash
+set -e
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# stefan.k.berg@ericsson.com
@@ -9,27 +10,43 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
#
+
+############################################################################
+# BEGIN of Exit handlers
+#
+
+do_exit () {
+ CID=`cat $CID_FILE`
+ rm -f $CID_FILE
+ set +e
+ docker kill $CID > /dev/null 2>&1
+ docker rm -f $CID > /dev/null 2>&1
+ docker rmi -f $IID > /dev/null 2>&1
+ set -e
+}
+
+#
+# End of Exit handlers
+############################################################################
+
+trap do_exit SIGINT SIGTERM EXIT
context=$1
shift
GID=`id -g`
USER=`whoami`
-res=`docker build -q --rm - <<EOF
+res=`docker build -q --force-rm - <<EOF
FROM $context
RUN date || date
RUN /root/setcontext $USER $UID $GID $HOME
EOF`
GITROOT=`git rev-parse --show-toplevel`
-CID=`echo $res | sed 's/.* //'`
-
- RUN_CONTEXT_OPT="--privileged=true --rm -i -e HOME=$HOME -u $USER -w $PWD -v ${HOME}/.ssh:${HOME}/.ssh -v $GITROOT:$GITROOT"
+IID=`echo $res | sed 's/.* //'`
+CID_FILE=`mktemp -u -t runcontext.XXXXXXXXXX`
+RUN_CONTEXT_OPT="--cidfile $CID_FILE --privileged=true --rm -i -e HOME=$HOME -u $USER -w $PWD -v ${HOME}/.ssh:${HOME}/.ssh -v $GITROOT:$GITROOT"
if [ "${INTERACTIVE}" != "FALSE" ]; then
RUN_CONTEXT_OPT+=" -t"
fi
-echo command: docker run ${RUN_CONTEXT_OPT} $CID "$@"
-docker run ${RUN_CONTEXT_OPT} $CID "$@"
-
-rc=$?
-docker rmi -f $CID > /dev/null
-exit $rc
+echo command: docker run ${RUN_CONTEXT_OPT} $IID "$@"
+docker run ${RUN_CONTEXT_OPT} $IID "$@"