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 package bisq.gradle.docker.image_builder
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
import java.io.File
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
abstract class DockerBuildTask : DefaultTask() { abstract class DockerBuildTask : DefaultTask() {
@get:InputDirectory @get:InputDirectory
abstract val dockerDirectory: Property<File> abstract val dockerDirectory: DirectoryProperty
@get:Input
abstract val imageTag: Property<String>
@TaskAction @TaskAction
fun build() { fun build() {
val processBuilder = ProcessBuilder( val processBuilder = ProcessBuilder(
"docker", "build", "docker", "build",
"--tag", "bisq/seednode:latest", "--tag", imageTag.get(),
dockerDirectory.get().absolutePath dockerDirectory.asFile.get().absolutePath
) )
processBuilder.redirectErrorStream(true) 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 installDistTask: TaskProvider<Sync> = project.tasks.named("installDist", Sync::class.java)
val distTarTask: TaskProvider<Tar> = project.tasks.named("distTar", Tar::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") { val copyTask = project.tasks.register<Copy>("copyDistTar") {
from(distTarTask.flatMap { it.archiveFile }) from(distTarTask.flatMap { it.archiveFile })
into(project.layout.buildDirectory.dir("docker")) into(seednodeBuildDir)
} }
project.tasks.register<CreateDockerfileTask>("generateDockerfile") { project.tasks.register<CreateDockerfileTask>("generateDockerfile") {
@ -38,8 +39,10 @@ class DockerImageBuilderPlugin : Plugin<Project> {
outputFile.set(project.layout.buildDirectory.file("docker/Dockerfile")) outputFile.set(project.layout.buildDirectory.file("docker/Dockerfile"))
} }
project.tasks.register<DockerBuildTask>("dockerImage") { project.tasks.register<DockerBuildTask>("seednodeDockerImage") {
dockerDirectory.set(copyTask.map { it.destinationDir }) dependsOn(copyTask)
imageTag.set("bisq/seednode:latest")
dockerDirectory.set(seednodeBuildDir)
} }
} }
} }