Skip to content

Commit

Permalink
add prune sub-command for containers and images
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellix committed Dec 29, 2016
1 parent c6c4680 commit 796d540
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
10 changes: 5 additions & 5 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ buildscript {
}

dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.3.2'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3'
classpath 'net.saliman:gradle-cobertura-plugin:2.4.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.7.1'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
}
Expand Down Expand Up @@ -47,7 +47,7 @@ dependencies {
compile 'com.squareup.okhttp3:okhttp:3.5.0'
testCompile 'com.squareup.okhttp3:mockwebserver:3.5.0'

compile 'org.apache.commons:commons-compress:1.12'
compile 'org.apache.commons:commons-compress:1.13'

compile('com.kohlschutter.junixsocket:junixsocket-native-common:2.0.4') {
exclude module: 'log4j'
Expand All @@ -56,7 +56,7 @@ dependencies {
exclude module: 'log4j'
}

compile 'org.bouncycastle:bcpkix-jdk15on:1.55'
compile 'org.bouncycastle:bcpkix-jdk15on:1.56'

testCompile project(':testutil')

Expand All @@ -69,7 +69,7 @@ dependencies {

testCompile 'net.jodah:failsafe:1.0.0'

testCompile 'joda-time:joda-time:2.9.6'
testCompile 'joda-time:joda-time:2.9.7'
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ interface DockerClient {

def cleanupImages()

def pruneImages()

def pruneImages(query)

def cleanupContainers(Closure shouldKeepContainer)

def pruneContainers()

def pruneContainers(query)

def cleanupVolumes(Closure shouldKeepVolume)

def ping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ class DockerClientImpl implements DockerClient {
}
}

@Override
pruneContainers(query = [:]) {
log.info "docker container prune"
def actualQuery = query ?: [:]
jsonEncodeFilters(actualQuery)
def response = getHttpClient().post([path : "/containers/prune",
query: actualQuery])
responseHandler.ensureSuccessfulResponse(response, new IllegalStateException("docker container prune failed"))
return response
}

@Override
cleanupImages() {
images([filters: [dangling: ["true"]]]).content.each { image ->
Expand All @@ -82,6 +93,17 @@ class DockerClientImpl implements DockerClient {
}
}

@Override
pruneImages(query = [:]) {
log.info "docker image prune"
def actualQuery = query ?: [:]
jsonEncodeFilters(actualQuery)
def response = getHttpClient().post([path : "/images/prune",
query: actualQuery])
responseHandler.ensureSuccessfulResponse(response, new IllegalStateException("docker image prune failed"))
return response
}

@Override
cleanupVolumes(Closure shouldKeepVolume) {
def allVolumes = volumes([filters: [dangling: ["true"]]]).content.Volumes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,15 @@ class DockerClientImplSpec extends Specification {
0 * dockerClient.rmVolume(_)
}

def "pruneContainers removes stopped containers"() {
when:
dockerClient.pruneContainers()

then:
1 * httpClient.post([path : "/containers/prune",
query: [:]]) >> [status: [success: true]]
}

def "cleanupStorage removes dangling images"() {
when:
dockerClient.cleanupStorage { container -> false }
Expand All @@ -1808,6 +1817,19 @@ class DockerClientImplSpec extends Specification {
0 * dockerClient.rmVolume(_)
}

def "pruneImages removes unused images"() {
given:
def filters = [dangling: true]
def expectedFilterValue = new JsonBuilder(filters).toString()

when:
dockerClient.pruneImages([filters: filters])

then:
1 * httpClient.post([path : "/images/prune",
query: [filters: expectedFilterValue]]) >> [status: [success: true]]
}

def "cleanupStorage doesn't remove dangling volumes by default"() {
when:
dockerClient.cleanupStorage { container -> false }
Expand Down
7 changes: 4 additions & 3 deletions roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ check out the project at [Java Docker API Client](https://github.com/docker-java
* [x] `docker container ps`: List containers (alias for `ls`, `list`)
* [x] `docker container pause <container>`: Pause all processes within one or more containers
* [ ] `docker container port`: List port mappings or a specific mapping for the container
* [ ] `docker container prune`: Remove all stopped containers
* [x] `docker container prune`: Remove all stopped containers
* [x] `docker container rename <container>`: Rename a container
* [x] `docker container restart <container>`: Restart one or more containers
* [x] `docker container rm <container>`: Remove one or more containers
Expand All @@ -66,7 +66,7 @@ check out the project at [Java Docker API Client](https://github.com/docker-java
* [x] `docker image inspect <image>`: Display detailed information on one or more images
* [x] `docker image load`: Load a tarball with a set of images and tags into docker
* [x] `docker image ls`: List Images
* [ ] `docker image prune`: Remove unused images (POST /images/prune)
* [x] `docker image prune`: Remove unused images
* [x] `docker image pull`: Pull an image or a repository from a registry
* [x] `docker image push <image>`: Push an image or a repository to a registry
* [x] `docker image rm <image>`: Remove one or more images
Expand Down Expand Up @@ -134,9 +134,10 @@ check out the project at [Java Docker API Client](https://github.com/docker-java
* [ ] `docker plugin create`: Create a plugin from a rootfs and config `POST /plugins/create`
* [ ] `docker plugin disable`: Disable a plugin `POST /plugins/{name:.*}/disable`
* [ ] `docker plugin enable`: Enable a plugin `POST /plugins/{name:.*}/enable`
* [ ] `docker plugin inspect`: Inspect a plugin `GET /plugins/{name:.*}`
* [ ] `docker plugin inspect`: Inspect a plugin `GET /plugins/{name:.*}/json`
* [ ] `docker plugin install`: Install a plugin (equivalent to pull + enable)
* [ ] `docker plugin ls`: List plugins `GET /plugins`
* [ ] Get plugin privileges `GET /plugins/privileges`
* [ ] `docker plugin push`: Push a plugin `POST /plugins/{name:.*}/push`
* [ ] Pull a plugin `POST /plugins/pull`
* [ ] `docker plugin rm`: Remove a plugin `DELETE /plugins/{name:.*}`
Expand Down

0 comments on commit 796d540

Please sign in to comment.