blob: b8d1934b3fcb606ae0080d64364451a06b8e6dbd [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#
Mike Marchettid235f502017-05-31 16:33:02 -040020#
Mike Marchetti6930bc02017-05-31 16:33:02 -040021#$1 container prefix name
22
23keep_number=1
24prefix=$1
25
26# keep the first build
27keep=$(lxc list | grep $prefix | awk '{print $2}' | sort -rn | head -n$keep_number)
28for 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
32 fi
33done