Docker CI Images should cleanup in the event of an unclean exit.

Fixes #9279
This commit is contained in:
Andrew Cholakian 2018-03-22 16:00:11 -05:00
parent d2af7706bd
commit 6b026a27f4

View file

@ -11,17 +11,26 @@ if [ -z "$branch_specifier" ]; then
REMOVE_IMAGE=true
IMAGE_NAME="$1"
else
# Jenkins
IMAGE_NAME=$branch_specifier"-"$(date +%s%N)
fi
echo "Running Docker CI build for '$IMAGE_NAME' "
docker build -t $IMAGE_NAME .
# Remove old docker cid just in case
rm -f docker_cid
docker build -t $IMAGE_NAME .
exit_code=$?; [[ $exit_code != 0 ]] && exit $exit_code
cleanup() {
cat docker_cid | xargs docker rm --force -v
}
trap cleanup EXIT
# Run the command, skip the first argument, which is the image name
docker run --sig-proxy=true --rm $IMAGE_NAME ${@:2}
echo "Running tests in built docker image"
docker run --sig-proxy=true --cidfile=docker_cid --rm $IMAGE_NAME ${@:2}
exit_code=$?
[[ $REMOVE_IMAGE == "true" ]] && docker rmi $IMAGE_NAME
echo "exiting with code: '$exit_code'"
exit $exit_code #preserve the exit code from the test run
exit $exit_code #preserve the exit code from the test run