diff options
author | mei mei <meimei@huawei.com> | 2017-03-29 09:27:23 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-03-29 09:27:23 +0000 |
commit | 64b2f0789690153712c94b8fb9ffcbb446afb640 (patch) | |
tree | ac5c85ba2bbeba3fa72a860102525eede166e0cc /jjb | |
parent | d4d7b5821f6d9a783bed651441b9f73c5cf64cbc (diff) | |
parent | 3da6a45f0dbcfb13a5723a35c98049f4f99431d1 (diff) |
Merge "bugfix: Bottlencks cleanup docker-compose dockers"
Diffstat (limited to 'jjb')
-rw-r--r-- | jjb/bottlenecks/bottlenecks-cleanup.sh | 127 | ||||
-rw-r--r-- | jjb/bottlenecks/docker_cleanup.sh | 106 |
2 files changed, 123 insertions, 110 deletions
diff --git a/jjb/bottlenecks/bottlenecks-cleanup.sh b/jjb/bottlenecks/bottlenecks-cleanup.sh index 0ba042318..052f72eef 100644 --- a/jjb/bottlenecks/bottlenecks-cleanup.sh +++ b/jjb/bottlenecks/bottlenecks-cleanup.sh @@ -1,111 +1,18 @@ #!/bin/bash -set -e -[[ $GERRIT_REFSPEC_DEBUG == true ]] && redirect="/dev/stdout" || redirect="/dev/null" - -BOTTLENECKS_IMAGE=opnfv/bottlenecks -echo "Bottlenecks: docker containers/images cleaning up" - -dangling_images=($(docker images -f "dangling=true" | grep $BOTTLENECKS_IMAGE | awk '{print $3}')) -if [[ -n $dangling_images ]]; then - echo "Removing $BOTTLENECKS_IMAGE:<none> dangling images and their containers" - docker images | head -1 && docker images | grep $dangling_images - for image_id in "${dangling_images[@]}"; do - echo "Bottlenecks: Removing dangling image $image_id" - docker rmi -f $image_id >${redirect} - done -fi - -for image_id in "${dangling_images[@]}"; do - if [[ -n $(docker ps -a | grep $image_id) ]]; then - echo "Bottlenecks: Removing containers associated with dangling image: $image_id" - docker ps -a | head -1 && docker ps -a | grep $image_id - docker ps -a | grep $image_id | awk '{print $1}'| xargs docker rm -f >${redirect} - fi -done - -if [[ -n $(docker ps -a | grep $BOTTLENECKS_IMAGE) ]]; then - echo "Removing existing $BOTTLENECKS_IMAGE containers" - docker ps -a | grep $BOTTLENECKS_IMAGE | awk '{print $1}' | xargs docker rm -f >$redirect -fi - -if [[ -n $(docker images | grep $BOTTLENECKS_IMAGE) ]]; then - echo "Bottlenecks: docker images to remove:" - docker images | head -1 && docker images | grep $BOTTLENECKS_IMAGE - image_tags=($(docker images | grep $BOTTLENECKS_IMAGE | awk '{print $2}')) - for tag in "${image_tags[@]}"; do - echo "Removing docker image $BOTTLENECKS_IMAGE:$tag..." - docker rmi $BOTTLENECKS_IMAGE:$tag >$redirect - done -fi - -echo "Yardstick: docker containers/images cleaning up" -YARDSTICK_IMAGE=opnfv/yardstick - -dangling_images=($(docker images -f "dangling=true" | grep $YARDSTICK_IMAGE | awk '{print $3}')) -if [[ -n $dangling_images ]]; then - echo "Removing $YARDSTICK_IMAGE:<none> dangling images and their containers" - docker images | head -1 && docker images | grep $dangling_images - for image_id in "${dangling_images[@]}"; do - echo "Yardstick: Removing dangling image $image_id" - docker rmi -f $image_id >${redirect} - done -fi - -for image_id in "${dangling_images[@]}"; do - if [[ -n $(docker ps -a | grep $image_id) ]]; then - echo "Yardstick: Removing containers associated with dangling image: $image_id" - docker ps -a | head -1 && docker ps -a | grep $image_id - docker ps -a | grep $image_id | awk '{print $1}'| xargs docker rm -f >${redirect} - fi -done - -if [[ -n $(docker ps -a | grep $YARDSTICK_IMAGE) ]]; then - echo "Removing existing $YARDSTICK_IMAGE containers" - docker ps -a | grep $YARDSTICK_IMAGE | awk '{print $1}' | xargs docker rm -f >$redirect -fi - -if [[ -n $(docker images | grep $YARDSTICK_IMAGE) ]]; then - echo "Yardstick: docker images to remove:" - docker images | head -1 && docker images | grep $YARDSTICK_IMAGE - image_tags=($(docker images | grep $YARDSTICK_IMAGE | awk '{print $2}')) - for tag in "${image_tags[@]}"; do - echo "Removing docker image $YARDSTICK_IMAGE:$tag..." - docker rmi $YARDSTICK_IMAGE:$tag >$redirect - done -fi - -echo "InfluxDB: docker containers/images cleaning up" -INFLUXDB_IMAGE=tutum/influxdb - -dangling_images=($(docker images -f "dangling=true" | grep $INFLUXDB_IMAGE | awk '{print $3}')) -if [[ -n $dangling_images ]]; then - echo "Removing $INFLUXDB_IMAGE:<none> dangling images and their containers" - docker images | head -1 && docker images | grep $dangling_images - for image_id in "${dangling_images[@]}"; do - echo "InfluxDB: Removing dangling image $image_id" - docker rmi -f $image_id >${redirect} - done -fi - -for image_id in "${dangling_images[@]}"; do - if [[ -n $(docker ps -a | grep $image_id) ]]; then - echo "InfluxDB: Removing containers associated with dangling image: $image_id" - docker ps -a | head -1 && docker ps -a | grep $image_id - docker ps -a | grep $image_id | awk '{print $1}'| xargs docker rm -f >${redirect} - fi -done - -if [[ -n $(docker ps -a | grep $INFLUXDB_IMAGE) ]]; then - echo "Removing existing $INFLUXDB_IMAGE containers" - docker ps -a | grep $INFLUXDB_IMAGE | awk '{print $1}' | xargs docker rm -f >$redirect -fi - -if [[ -n $(docker images | grep $INFLUXDB_IMAGE) ]]; then - echo "InfluxDB: docker images to remove:" - docker images | head -1 && docker images | grep $INFLUXDB_IMAGE - image_tags=($(docker images | grep $INFLUXDB_IMAGE | awk '{print $2}')) - for tag in "${image_tags[@]}"; do - echo "Removing docker image $INFLUXDB_IMAGE:$tag..." - docker rmi $INFLUXDB_IMAGE:$tag >$redirect - done -fi
\ No newline at end of file +############################################################################## +# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +BASEDIR=`dirname $0` + +#clean up correlated dockers and their images +bash ${BASEDIR}/docker_cleanup.sh -d bottlenecks --debug +bash ${BASEDIR}/docker_cleanup.sh -d yardstick --debug +bash ${BASEDIR}/docker_cleanup.sh -d kibana --debug +bash ${BASEDIR}/docker_cleanup.sh -d elasticsearch --debug +bash ${BASEDIR}/docker_cleanup.sh -d influxdb --debug
\ No newline at end of file diff --git a/jjb/bottlenecks/docker_cleanup.sh b/jjb/bottlenecks/docker_cleanup.sh new file mode 100644 index 000000000..cfc8e8b0e --- /dev/null +++ b/jjb/bottlenecks/docker_cleanup.sh @@ -0,0 +1,106 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +usage="Script to clear up dockers and their images. + +usage: + bash $(basename "$0") [-h|--help] [-d|--docker <docker name>] [--debug] + +where: + -h|--help show the help text + -d|--docker specify dockers' name + <docker name> keyword of dockers' name used to find dockers + e.g. keyword "bottlenecks" to find "opnfv/bottlenecks:*" + --debug print debug information with default false + +examples: + $(basename "$0") + $(basename "$0") -d bottlenecks --debug" + +clnup_debug=false + +while [[ $#>0 ]]; do + clnup_docr="$1" + case $clnup_docr in + -h|--help) + echo "$usage" + exit 0 + shift + ;; + -d|--docker) + docker_name="$2" + shift + + if [[ $2 == "--debug" ]]; then + clnup_debug=true + shift + fi + ;; + --debug) + clnup_debug=true + shift + if [[ "$1" == "-d" || "$1" == "--docker" ]]; then + docker_name="$2" + shift + fi + ;; + *) + echo "unknow options $1 $2 $3" + exit 1 + ;; + esac + shift +done + + +# check if docker name is empty +if [[ $docker_name == "" ]]; then + echo empty docker name + exit 1 +fi + +# clean up dockers and their images with keyword in their names +[[ $clnup_debug == true ]] && redirect="/dev/stdout" || redirect="/dev/null" + +echo "$docker_name: docker containers/images cleaning up" + +dangling_images=($(docker images -f "dangling=true" | grep $docker_name | awk '{print $3}')) +if [[ -n $dangling_images ]]; then + echo "Removing $docker_name:<none> dangling images and their containers" + docker images | head -1 && docker images | grep $dangling_images + for image_id in "${dangling_images[@]}"; do + echo "$docker_name: Removing dangling image $image_id" + docker rmi -f $image_id >${redirect} + done +fi + +for image_id in "${dangling_images[@]}"; do + if [[ -n $(docker ps -a | grep $image_id) ]]; then + echo "$docker_name: Removing containers associated with dangling image: $image_id" + docker ps -a | head -1 && docker ps -a | grep $image_id + docker ps -a | grep $image_id | awk '{print $1}'| xargs docker rm -f >${redirect} + fi +done + +if [[ -n $(docker ps -a | grep $docker_name) ]]; then + echo "Removing existing $docker_name containers" + docker ps -a | head -1 && docker ps -a | grep $docker_name + docker ps -a | grep $docker_name | awk '{print $1}' | xargs docker rm -f >$redirect +fi + +if [[ -n $(docker images | grep $docker_name) ]]; then + echo "$docker_name: docker images to remove:" + docker images | head -1 && docker images | grep $docker_name + image_ids=($(docker images | grep $docker_name | awk '{print $3}')) + for image_id in "${image_ids[@]}"; do + echo "Removing docker image $docker_name:$tag..." + docker rmi $image_id >$redirect + done +fi |