mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
seednode: Create dynamically slim docker image
This commit is contained in:
parent
ed7587bc22
commit
c2875169c1
17
build-logic/docker-image-builder/build.gradle
Normal file
17
build-logic/docker-image-builder/build.gradle
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
plugins {
|
||||||
|
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
|
||||||
|
id 'org.gradle.kotlin.kotlin-dsl' version '2.4.1'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
simplePlugin {
|
||||||
|
id = 'bisq.gradle.docker.image_builder.DockerImageBuilderPlugin'
|
||||||
|
implementationClass = 'bisq.gradle.docker.image_builder.DockerImageBuilderPlugin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package bisq.gradle.docker.image_builder
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.file.RegularFileProperty
|
||||||
|
import org.gradle.api.provider.Property
|
||||||
|
import org.gradle.api.tasks.Input
|
||||||
|
import org.gradle.api.tasks.OutputFile
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
|
||||||
|
abstract class CreateDockerfileTask : DefaultTask() {
|
||||||
|
|
||||||
|
@get:Input
|
||||||
|
abstract val archiveFileName: Property<String>
|
||||||
|
|
||||||
|
@get:OutputFile
|
||||||
|
abstract val outputFile: RegularFileProperty
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun create() {
|
||||||
|
val dockerFileContent: String = readDockerFileTemplate()
|
||||||
|
.replace("'{{ ARCHIVE_PATH }}'", archiveFileName.get())
|
||||||
|
|
||||||
|
outputFile.asFile.get()
|
||||||
|
.writeText(dockerFileContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readDockerFileTemplate(): String {
|
||||||
|
this.javaClass.getResourceAsStream("/Dockerfile")
|
||||||
|
.use { inputStream ->
|
||||||
|
inputStream!!.bufferedReader()
|
||||||
|
.use { bufferedReader ->
|
||||||
|
return bufferedReader.readText()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package bisq.gradle.docker.image_builder
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.provider.Property
|
||||||
|
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>
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun build() {
|
||||||
|
val processBuilder = ProcessBuilder(
|
||||||
|
"docker", "build",
|
||||||
|
"--tag", "bisq/seednode:latest",
|
||||||
|
dockerDirectory.get().absolutePath
|
||||||
|
)
|
||||||
|
|
||||||
|
processBuilder.redirectErrorStream(true)
|
||||||
|
val process = processBuilder.start()
|
||||||
|
|
||||||
|
val isSuccess = process.waitFor(2, TimeUnit.MINUTES) && process.exitValue() == 0
|
||||||
|
if (!isSuccess) {
|
||||||
|
throw IllegalStateException("Couldn't build docker image.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package bisq.gradle.docker.image_builder
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.tasks.Copy
|
||||||
|
import org.gradle.api.tasks.TaskProvider
|
||||||
|
import org.gradle.api.tasks.bundling.Tar
|
||||||
|
import org.gradle.kotlin.dsl.register
|
||||||
|
|
||||||
|
class DockerImageBuilderPlugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
val distTarTask: TaskProvider<Tar> = project.tasks.named("distTar", Tar::class.java)
|
||||||
|
|
||||||
|
val copyTask = project.tasks.register<Copy>("copyDistTar") {
|
||||||
|
from(distTarTask.flatMap { it.archiveFile })
|
||||||
|
into(project.layout.buildDirectory.dir("docker"))
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.register<CreateDockerfileTask>("generateDockerfile") {
|
||||||
|
archiveFileName.set(distTarTask.flatMap { it.archiveFileName })
|
||||||
|
outputFile.set(project.layout.buildDirectory.file("docker/Dockerfile"))
|
||||||
|
}
|
||||||
|
|
||||||
|
project.tasks.register<DockerBuildTask>("dockerImage") {
|
||||||
|
dockerDirectory.set(copyTask.map { it.destinationDir })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
FROM azul/zulu-openjdk:11.0.20-11.66.15
|
||||||
|
|
||||||
|
COPY '{{ ARCHIVE_PATH }}' /
|
||||||
|
RUN tar xvf /seednode.tar
|
||||||
|
|
||||||
|
ENTRYPOINT ["bash", "/seednode/bin/seednode"]
|
@ -8,6 +8,7 @@ dependencyResolutionManagement {
|
|||||||
|
|
||||||
include 'app-start-plugin'
|
include 'app-start-plugin'
|
||||||
include 'commons'
|
include 'commons'
|
||||||
|
include 'docker-image-builder'
|
||||||
include 'gradle-tasks'
|
include 'gradle-tasks'
|
||||||
include 'packaging'
|
include 'packaging'
|
||||||
include 'regtest'
|
include 'regtest'
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'bisq.application'
|
id 'bisq.application'
|
||||||
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
|
id 'bisq.gradle.app_start_plugin.AppStartPlugin'
|
||||||
|
id 'bisq.gradle.docker.image_builder.DockerImageBuilderPlugin'
|
||||||
}
|
}
|
||||||
|
|
||||||
distTar.enabled = true
|
distTar.enabled = true
|
||||||
|
Loading…
Reference in New Issue
Block a user