blob: 13c6df4241f5789ef88ae2215a458fa044786f35 [file] [log] [blame]
Mike Marchetti6930bc02017-05-31 16:33:02 -04001#!/bin/bash
2# Copyright 2017 Sandvine
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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.
15#
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
19#
20#$1 container prefix name
21
22keep_number=1
23prefix=$1
24
25# keep the first build
26keep=$(lxc list | grep $prefix | awk '{print $2}' | sort -rn | head -n$keep_number)
27for container in $(lxc list | grep $prefix | awk '{print $2}' | sort -rn); do
28 if [ "$container" != "$keep" ]; then
29 echo "deleting old container $container"
30 lxc delete $container --force
31 fi
32done