Skip to content

Commit

Permalink
[CI] Cleanup Docker for CI Build (#731)
Browse files Browse the repository at this point in the history
* Cleanup jenkins for continous integration build

* Cleanup with more keywords

* fix bash syntax

* Delete metric image as well
  • Loading branch information
simon-mo committed Jun 12, 2019
1 parent b78bbdb commit 99e5239
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
30 changes: 21 additions & 9 deletions bin/cleanup_jenkins.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# This script will delete all testing containers and images
# available on this machine.
set -x

CLIPPER_REGISTRY=clippertesting

# best effort, ignore all errors
try_cleanup() {
(docker ps --all | grep "$@" | awk '{ print $1 }' | xargs docker kill) || true
(docker container ls --all | grep "$@" | awk '{ print $3 }' | xargs docker container rm) || true
(docker image ls --all | grep "$@" | awk '{ print $3 }' | xargs docker image rm -f) || true
docker image prune -f
}

try_cleanup_docker_volume() {
(docker volume ls -f dangling=true | awk '{ print $2 }' | xargs docker volume rm -f) || true
}
try_cleanup ${CLIPPER_REGISTRY} > /dev/null
try_cleanup shipyard > /dev/null
try_cleanup_docker_volume > /dev/null
KEYWORDS=(
${CLIPPER_REGISTRY}
clipper
redis
model
prometheus
fluentd
metric
)

echo "Docker Status Before"
docker ps

for i in "${KEYWORDS[@]}"
do
try_cleanup "$i"
done

echo "Docker Status After"
docker ps
15 changes: 14 additions & 1 deletion bin/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,29 @@ tag=$(<VERSION.txt)
clean_up_jenkins() {
bash ./bin/cleanup_jenkins.sh
}
unset do_cleanup

# Change the VERSION.txt to current sha_tag
sha_tag=$(git rev-parse --verify --short=10 HEAD)
# Jenkins will merge the PR, however we will use the unmerged
# sha to tag our image.
# https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
if [ -z ${ghprbActualCommit+x} ]
then echo "We are not in Jenkins"
then echo "We are not doing Jekins PRB"
else
sha_tag=`echo $ghprbActualCommit | cut -c-10`;
clean_up_jenkins
do_cleanup="true"
fi
echo $sha_tag > VERSION.txt

if [ -z ${BUILD_TAG+x} ]
then echo "We are not doing Jekins Regular Build"
else
clean_up_jenkins
do_cleanup="true"
fi

# Use shipyard to generate Makefile
bash ./bin/shipyard.sh
# Build Kubernetes containers first, travis will be waiting
Expand All @@ -52,3 +61,7 @@ make -j -f CI_build.Makefile all
make -j10 -f CI_test.Makefile unittest
make -j15 -f CI_test.Makefile integration_py2
make -j15 -f CI_test.Makefile integration_py3

if [ -z ${do_cleanup+x} ]
then clean_up_jenkins
fi

0 comments on commit 99e5239

Please sign in to comment.