X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=jenkins%2Fsystem%2Fdelete_old_containers.sh;fp=jenkins%2Fsystem%2Fdelete_old_containers.sh;h=13c6df4241f5789ef88ae2215a458fa044786f35;hb=6930bc081efa6feb1a7ff8a9cded75eea807f6f5;hp=0000000000000000000000000000000000000000;hpb=6acd4dc92567bc7b4fab71399cb800afd10c6dea;p=osm%2Fdevops.git diff --git a/jenkins/system/delete_old_containers.sh b/jenkins/system/delete_old_containers.sh new file mode 100755 index 00000000..13c6df42 --- /dev/null +++ b/jenkins/system/delete_old_containers.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Copyright 2017 Sandvine +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# A helper routine that cleans up old container images based +# on an input prefix to check. Jenkins builds will add an incrementing +# build suffix (build number) to the prefix +# +#$1 container prefix name + +keep_number=1 +prefix=$1 + +# keep the first build +keep=$(lxc list | grep $prefix | awk '{print $2}' | sort -rn | head -n$keep_number) +for container in $(lxc list | grep $prefix | awk '{print $2}' | sort -rn); do + if [ "$container" != "$keep" ]; then + echo "deleting old container $container" + lxc delete $container --force + fi +done