-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from michael-yx-wu/develop
- Loading branch information
Showing
5 changed files
with
178 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
dockerclean | ||
=========== | ||
# dockerclean | ||
A simple utility to make it easier to cleanup Docker images and containers. | ||
|
||
Usage | ||
----- | ||
## Usage | ||
`dockerclean [OPTIONS]` | ||
|
||
- `-c PATTERN`: Remove all containers matched by `PATTERN` | ||
- `-d`: Remove all images tagged as `<none>` | ||
- `-e`: Remove all exited containers | ||
- `-r`: By default `dockerclean` executes in `dry-run` mode to give you a chance | ||
to preview any images or containers that will get deleted. Use the `-r` flag | ||
to remove matched images and containers. | ||
- `-t PATTERN`: Remove all images matched by `PATTERN` | ||
- `-i PATTERN`: Remove all images matched by `PATTERN` | ||
- `-h`: Print usage and options | ||
|
||
If `-e` and `-c` are used in conjunction, `dockerclean` will find all containers | ||
that have exited or match the `PATTERN` provided. | ||
|
||
## Build status | ||
![master](https://circleci.com/gh/michael-yx-wu/dockerclean/tree/master.png?style=shield&circle-token=810386c47ffeb705bf8c4e52a88c0d2177e82230) (master) | ||
|
||
![develop](https://circleci.com/gh/michael-yx-wu/dockerclean/tree/develop.png?style=shield&circle-token=810386c47ffeb705bf8c4e52a88c0d2177e82230) (develop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
machine: | ||
pre: | ||
- sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci' | ||
- sudo chmod 0755 /usr/bin/docker | ||
services: | ||
- docker | ||
|
||
dependencies: | ||
pre: | ||
- git clone https://github.com/sstephenson/bats.git; cd bats; sudo ./install.sh /usr/local | ||
- docker -v | ||
|
||
test: | ||
override: | ||
- bats tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
alpine26: | ||
container_name: alpine.26.dockerclean | ||
image: alpine:2.6 | ||
command: sleep 300 | ||
|
||
alpine32: | ||
container_name: alpine.32.dockerclean | ||
image: alpine:3.2 | ||
command: sleep 300 | ||
|
||
cirros030: | ||
container_name: cirros.030.dockerclean | ||
image: cirros:0.3.0 | ||
command: sleep 300 | ||
|
||
cirrosexited: | ||
container_name: cirros.exited.dockerclean | ||
image: cirros:0.3.0 | ||
command: sleep 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/usr/bin/env bats | ||
|
||
nothingRemoved() { | ||
run docker inspect alpine:2.6 | ||
[ "$status" -eq 0 ] | ||
run docker inspect alpine:3.2 | ||
[ "$status" -eq 0 ] | ||
run docker inspect cirros:0.3.0 | ||
[ "$status" -eq 0 ] | ||
run docker inspect alpine.26.dockerclean | ||
[ "$status" -eq 0 ] | ||
run docker inspect alpine.32.dockerclean | ||
[ "$status" -eq 0 ] | ||
run docker inspect cirros.030.dockerclean | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
alpineImagesRemoved() { | ||
run docker inspect alpine:2.6 | ||
[ "$status" -eq 1 ] | ||
run docker inspect alpine:3.2 | ||
[ "$status" -eq 1 ] | ||
run docker inspect cirros:0.3.0 | ||
[ "$status" -eq 0 ] | ||
run docker inspect alpine.26.dockerclean | ||
[ "$status" -eq 1 ] | ||
run docker inspect alpine.32.dockerclean | ||
[ "$status" -eq 1 ] | ||
run docker inspect cirros.030.dockerclean | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
alpineContainersRemoved() { | ||
run docker inspect alpine:2.6 | ||
[ "$status" -eq 0 ] | ||
run docker inspect alpine:3.2 | ||
[ "$status" -eq 0 ] | ||
run docker inspect cirros:0.3.0 | ||
[ "$status" -eq 0 ] | ||
run docker inspect alpine.26.dockerclean | ||
[ "$status" -eq 1 ] | ||
run docker inspect alpine.32.dockerclean | ||
[ "$status" -eq 1 ] | ||
run docker inspect cirros.030.dockerclean | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
setup() { | ||
docker-compose -f tests/docker-compose.yml -p dockerclean-tests up -d | ||
sleep 5 | ||
export alpine_26_image_id=$(docker inspect --format={{.Id}} alpine:2.6) | ||
export alpine_latest_image_id=$(docker inspect --format={{.Id}} alpine:3.2) | ||
export cirros_latest_image_id=$(docker inspect --format={{.Id}} cirros:0.3.0) | ||
export alpine_26_container_id=$(docker inspect --format={{.Id}} alpine.26.dockerclean) | ||
export alpine_latest_container_id=$(docker inspect --format={{.Id}} alpine.32.dockerclean) | ||
export cirros_latest_container_id=$(docker inspect --format={{.Id}} cirros.030.dockerclean) | ||
export cirros_exited_container_id=$(docker inspect --format={{.Id}} cirros.exited.dockerclean) | ||
} | ||
|
||
@test "matches containers without removing" { | ||
results=$(./dockerclean -c alpine) | ||
num_results=$(echo "$results" | grep alpine | wc -l) | ||
[ "$num_results" -eq 2 ] | ||
|
||
alpine_26_matched_container_id=$(docker inspect --format={{.Id}} $(echo "$results" | grep alpine | grep "2\.6" | awk '{print $1}')) | ||
alpine_latest_matched_container_id=$(docker inspect --format={{.Id}} $(echo "$results" | grep alpine | grep "3\.2" | awk '{print $1}')) | ||
[ "$alpine_26_matched_container_id" = "$alpine_26_container_id" ] | ||
[ "$alpine_latest_matched_container_id" = "$alpine_latest_container_id" ] | ||
|
||
nothingRemoved | ||
} | ||
|
||
@test "matches exited containers without removing" { | ||
results=$(./dockerclean -e) | ||
num_results=$(echo "$results" | grep cirros | grep Exited | wc -l) | ||
[ "$num_results" -eq 1 ] | ||
cirros_exited_matched_container_id=$(docker inspect --format={{.Id}} $(echo "$results" | grep cirros | grep Exited | awk '{print $1}')) | ||
[ "$alpine_exited_matched_container_id" = "$alpine_exited_container_id" ] | ||
|
||
nothingRemoved | ||
} | ||
|
||
@test "matches images without removing" { | ||
results=$(./dockerclean -i alpine) | ||
num_results=$(echo "$results" | grep alpine | wc -l) | ||
[ "$num_results" -eq 2 ] | ||
|
||
alpine_26_matched_image_id=$(docker inspect --format={{.Id}} $(echo "$results" | grep alpine | grep "2\.6" | awk '{print $3}')) | ||
alpine_latest_matched_image_id=$(docker inspect --format={{.Id}} $(echo "$results" | grep alpine | grep "3\.2" | awk '{print $3}')) | ||
[ "$alpine_26_matched_image_id" = "$alpine_26_image_id" ] | ||
[ "$alpine_latest_matched_image_id" = "$alpine_latest_image_id" ] | ||
|
||
nothingRemoved | ||
} | ||
|
||
@test "removes containers" { | ||
skip "CircleCI does not allow deletion of containers" | ||
|
||
results=$(./dockerclean -r -c alpine) | ||
alpineContainersRemoved | ||
} | ||
|
||
@test "removes images (after removing containers)" { | ||
skip "CircleCI does not allow deletion of containers" | ||
|
||
run ./dockerclean -r -c alpine | ||
[ "$status" -eq 0 ] | ||
|
||
results=$(./dockerclean -r -i alpine) | ||
sleep 1 | ||
alpineImagesRemoved | ||
} |