Merge pull request #967 from alessio/develop

Really clean-up containers and images a-la-Docker
This commit is contained in:
Jose Diaz-Gonzalez
2015-02-19 14:54:00 -05:00
2 changed files with 37 additions and 2 deletions

4
dokku
View File

@@ -122,9 +122,9 @@ case "$1" in
cleanup)
# delete all non-running container
docker ps -a | grep 'Exit' | awk '{print $1}' | xargs docker rm &> /dev/null &
docker rm $(docker ps -a -f "status=exited" -q) &> /dev/null &
# delete unused images
docker images | grep '<none>' | awk '{print $3}' | xargs docker rmi &> /dev/null &
docker rmi $(docker images -f "dangling=true" -q) &> /dev/null &
;;
plugins)

35
tests/unit/cleanup.bats Normal file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env bats
load test_helper
setup() {
deploy_app
}
teardown() {
destroy_app
}
@test "remove exited containers" {
run dokku run $TEST_APP hostname
echo "output: "$output
echo "status: "$status
container="$output"
assert_success
run bash -c "docker ps -a -f 'status=exited' -q --no-trunc=false | grep -q $container"
echo "output: "$output
echo "status: "$status
assert_success
run dokku cleanup
echo "output: "$output
echo "status: "$status
assert_success
run bash -c "docker ps -a -f 'status=exited' -q --no-trunc=false | grep -q $container"
echo "output: "$output
echo "status: "$status
assert_failure
run bash -c "docker ps -a -f 'status=exited' -q --no-trunc=false"
echo "output: "$output
echo "status: "$status
assert_output ""
}