Skip to content

Commit

Permalink
removeImage option added
Browse files Browse the repository at this point in the history
  • Loading branch information
augi committed Jan 7, 2018
1 parent 1315c3d commit 1559cf1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Only `image` parameter is mandatory - it's name of the resulting image.
// username and password are used if the Docker Registry requires credentials for pushing
username = 'registry-username'
password = System.getenv('DOCKER_REGISTRY_PASSWORD')
removeImage = false // indicates if the image should be removed after publishing, default is true
}

The plugin can be also applied using [the new Gradle syntax](https://plugins.gradle.org/plugin/cz.augi.gradle.wartremover):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ class DockerJavaExtension implements DistDockerSettings, DockerPushSettings {
String username
String password
String getRegistry() { image.substring(0, image.indexOf('/')) }
Boolean removeImage = true
}
20 changes: 15 additions & 5 deletions src/main/groovy/cz/augi/gradle/dockerjava/DockerPushTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ class DockerPushTask extends DefaultTask {
@TaskAction
def push() {
def configFile = new File(project.buildDir, 'localDockerConfig')
project.exec {
it.commandLine 'docker', '--config', configFile.absolutePath, 'login', '-u', settings.username, '-p', settings.password, settings.registry
try {
project.exec {
it.commandLine 'docker', '--config', configFile.absolutePath, 'login', '-u', settings.username, '-p', settings.password, settings.registry
}
project.exec {
it.commandLine 'docker', '--config', configFile.absolutePath, 'push', settings.image
}
} finally {
configFile.delete()
}
project.exec {
it.commandLine 'docker', '--config', configFile.absolutePath, 'push', settings.image
if (settings.removeImage) {
project.exec {
it.commandLine 'docker', 'rmi', '--force', settings.image
}
}
configFile.delete()
}
}

Expand All @@ -38,4 +46,6 @@ interface DockerPushSettings {
String getPassword()
@Input
String getRegistry()
@Input
Boolean getRemoveImage()
}

0 comments on commit 1559cf1

Please sign in to comment.