| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 1 | #!/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 Marchetti | d235f50 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 20 | # |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 21 | #$1 container prefix name |
| 22 | |
| 23 | keep_number=1 |
| 24 | prefix=$1 |
| 25 | |
| 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 |
| 32 | fi |
| 33 | done |