~brianlbaird/charms/trusty/pcrf/trunk

« back to all changes in this revision

Viewing changes to trusty/pcrf/actions/clean-images

  • Committer: brian baird
  • Date: 2016-08-24 18:05:17 UTC
  • Revision ID: brianlbaird@gmail.com-20160824180517-uyp6100mfwuj6les
dt demo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# Destructive action - Destroys images on the host that are not running
 
4
 
 
5
untagged=$(action-get untagged)
 
6
images=$(docker images | grep "^<none>" | awk "{print $3}")
 
7
all_images=$(docker images -aq)
 
8
 
 
9
if [[ ! -z "$images" && "$untagged" == "True" ]]; then
 
10
    echo "Removing untagged images"
 
11
    docker rmi $images
 
12
    exit 0
 
13
fi
 
14
 
 
15
if [[ ! -z "$all_images" && "$untagged" ]]; then
 
16
    echo "Removing all non-running images"
 
17
    $(docker rmi $all_images)
 
18
    ret=$?
 
19
    if [ $ret > 0 ]; then
 
20
    echo "Not all containers removed, perhaps you need to juju action do $JUJU_UNIT_NAME clean-containers first?"
 
21
    action-set response.msg="Not all containers removed, perhaps you need to juju action do $JUJU_UNIT_NAME clean-containers first?"
 
22
        action-set response.result=$(docker rmi $all_images)
 
23
    fi
 
24
    exit 0
 
25
fi