Gradle: Generalize docker build task

This commit is contained in:
Alva Swanson 2023-10-05 19:43:03 +02:00
parent 86a359426d
commit aa984e6972
No known key found for this signature in database
GPG Key ID: 004760E77F753090
2 changed files with 14 additions and 7 deletions

View File

@ -1,23 +1,27 @@
package bisq.gradle.docker.image_builder
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.File
import java.util.concurrent.TimeUnit
abstract class DockerBuildTask : DefaultTask() {
@get:InputDirectory
abstract val dockerDirectory: Property<File>
abstract val dockerDirectory: DirectoryProperty
@get:Input
abstract val imageTag: Property<String>
@TaskAction
fun build() {
val processBuilder = ProcessBuilder(
"docker", "build",
"--tag", "bisq/seednode:latest",
dockerDirectory.get().absolutePath
"--tag", imageTag.get(),
dockerDirectory.asFile.get().absolutePath
)
processBuilder.redirectErrorStream(true)

View File

@ -20,9 +20,10 @@ class DockerImageBuilderPlugin : Plugin<Project> {
val installDistTask: TaskProvider<Sync> = project.tasks.named("installDist", Sync::class.java)
val distTarTask: TaskProvider<Tar> = project.tasks.named("distTar", Tar::class.java)
val seednodeBuildDir = project.layout.buildDirectory.dir("docker")
val copyTask = project.tasks.register<Copy>("copyDistTar") {
from(distTarTask.flatMap { it.archiveFile })
into(project.layout.buildDirectory.dir("docker"))
into(seednodeBuildDir)
}
project.tasks.register<CreateDockerfileTask>("generateDockerfile") {
@ -38,8 +39,10 @@ class DockerImageBuilderPlugin : Plugin<Project> {
outputFile.set(project.layout.buildDirectory.file("docker/Dockerfile"))
}
project.tasks.register<DockerBuildTask>("dockerImage") {
dockerDirectory.set(copyTask.map { it.destinationDir })
project.tasks.register<DockerBuildTask>("seednodeDockerImage") {
dependsOn(copyTask)
imageTag.set("bisq/seednode:latest")
dockerDirectory.set(seednodeBuildDir)
}
}
}