only run docker task if docker is running
This commit is contained in:
parent
c5e9e619b5
commit
2733dc4f62
1 changed files with 19 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ import org.gradle.api.file.RegularFileProperty
|
|||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.ProviderFactory
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
|
|
@ -16,15 +17,16 @@ import org.gradle.api.tasks.PathSensitive
|
|||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.SkipWhenEmpty
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.gradle.process.ExecOperations
|
||||
import org.gradle.work.Incremental
|
||||
import org.gradle.work.NormalizeLineEndings
|
||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||
|
||||
@CacheableTask
|
||||
abstract class DockerComposeExec @Inject constructor(
|
||||
private val executor: ExecOperations,
|
||||
private val objectFactory: ObjectFactory,
|
||||
private val objects: ObjectFactory,
|
||||
private val providers: ProviderFactory,
|
||||
) : DefaultTask() {
|
||||
|
||||
@get:InputDirectory
|
||||
|
|
@ -36,14 +38,28 @@ abstract class DockerComposeExec @Inject constructor(
|
|||
@get:Input
|
||||
abstract val command: Property<String>
|
||||
|
||||
@get:Input
|
||||
val dockerIsActive: Property<Boolean> = objects.property<Boolean>().convention(
|
||||
providers.exec {
|
||||
commandLine = parseSpaceSeparatedArgs("docker info")
|
||||
isIgnoreExitValue = true
|
||||
}.result.map {
|
||||
it.exitValue == 0
|
||||
}
|
||||
)
|
||||
|
||||
@get:OutputFile
|
||||
val stateFile: RegularFileProperty = objectFactory.fileProperty().convention {
|
||||
val stateFile: RegularFileProperty = objects.fileProperty().convention {
|
||||
temporaryDir.resolve("docker-files.md5")
|
||||
}
|
||||
|
||||
init {
|
||||
group = DOCKER_COMPOSE_GROUP
|
||||
logging.captureStandardOutput(LogLevel.LIFECYCLE)
|
||||
|
||||
super.onlyIf {
|
||||
it is DockerComposeExec && it.dockerIsActive.getOrElse(false)
|
||||
}
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue