-
Notifications
You must be signed in to change notification settings - Fork 19
/
docker.gradle
43 lines (33 loc) · 1.21 KB
/
docker.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
buildscript {
ext.docker_plugin_version = "0.19.2"
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:$docker_plugin_version"
}
}
apply plugin: com.palantir.gradle.docker.DockerRunPlugin
ext.dockerRunTask = tasks.find { it.name == "dockerRun" }
def DOCKER_GROUP = dockerRunTask.group
task dockerCleanRun(group: DOCKER_GROUP) {
doLast {
dockerStop.execute()
println("DOCKER $dockerRun.name has been STOPED")
dockerRemoveContainer.execute()
println("DOCKER $dockerRun.name has been REMOVED")
dockerRunTask.execute()
println("DOCKER $dockerRun.name has been STARTED")
}
}
static def dockerExists(String containerName) {
def result = "docker inspect $containerName".execute()
return result.waitFor() == 0
}
dockerRunTask.onlyIf { !dockerExists(dockerRun.name) }
dockerStop.onlyIf { dockerExists(dockerRun.name) }
dockerRemoveContainer.onlyIf { dockerExists(dockerRun.name) }
dockerRunTask.outputs.upToDateWhen { dockerExists(dockerRun.name) }
dockerRemoveContainer.outputs.upToDateWhen { !dockerExists(dockerRun.name) }