2 # Copyright 2017 Sandvine
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # A helper routine that cleans up old container images based
17 # on an input prefix to check. Jenkins builds will add an incrementing
18 # build suffix (build number) to the prefix
21 #$1 container prefix name
26 # keep the first build
27 keep
=$
(lxc list |
grep $prefix |
awk '{print $2}' |
sort -rn |
head -n$keep_number)
28 for container
in $
(lxc list |
grep $prefix |
awk '{print $2}' |
sort -rn); do
29 if [ "$container" != "$keep" ]; then
30 echo "deleting old container $container"
31 lxc delete
$container --force