geedeecee: fix DockerEnvUpdateTask
This commit is contained in:
parent
c01c19a8e2
commit
b171f88435
5 changed files with 101 additions and 29 deletions
|
|
@ -1,27 +1,95 @@
|
|||
package dev.adamko.geedeecee
|
||||
|
||||
import java.io.File
|
||||
import java.nio.charset.Charset
|
||||
import java.util.Properties
|
||||
import javax.inject.Inject
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.MapProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.WriteProperties
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Optional
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
|
||||
@CacheableTask
|
||||
open class DockerEnvUpdateTask @Inject constructor(
|
||||
objects: ObjectFactory
|
||||
) : WriteProperties() {
|
||||
abstract class DockerEnvUpdateTask @Inject constructor(
|
||||
) : DefaultTask() {
|
||||
|
||||
@Internal
|
||||
// internal and not abstract so that it can delegate to `super.outputFile` in `init {}`
|
||||
val dotEnvFile: RegularFileProperty = objects.fileProperty()
|
||||
@get:Input
|
||||
abstract val envProperties: MapProperty<String, String>
|
||||
|
||||
@get:Input
|
||||
@get:Optional
|
||||
abstract val comment: Property<String>
|
||||
|
||||
@get:Input
|
||||
@get:Optional
|
||||
abstract val charset: Property<Charset>
|
||||
|
||||
@get:OutputFile
|
||||
abstract val dotEnvFile: RegularFileProperty
|
||||
|
||||
init {
|
||||
group = GDCPlugin.GCD_TASK_GROUP
|
||||
super.setOutputFile(dotEnvFile)
|
||||
super.getLogging().captureStandardOutput(LogLevel.LIFECYCLE)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun writeProperties() {
|
||||
val dotEnvFile: File = dotEnvFile.get().asFile
|
||||
val charset: Charset = charset.orNull ?: Charsets.UTF_8
|
||||
|
||||
val comment: String = comment.orNull
|
||||
?: " Do not edit manually. This file was created with task '$name'"
|
||||
|
||||
|
||||
dotEnvFile.writer(charset).use { writer ->
|
||||
val properties = Properties()
|
||||
properties.putAll(envProperties.get())
|
||||
properties.store(writer, comment)
|
||||
}
|
||||
|
||||
// make the file reproducible by sorting and filtering lines in the file
|
||||
val lines = dotEnvFile.useLines(charset) { lines ->
|
||||
lines
|
||||
.filterNot { it.isBlank() }
|
||||
.sorted()
|
||||
.toList()
|
||||
}
|
||||
|
||||
// first comment is our comment
|
||||
// second comment is the auto generated timestamp - which we will filter out, so the file is reproducible
|
||||
val parsedComment = lines.firstOrNull { it.isComment() } ?: ""
|
||||
val parsedLines = lines.filterNot { it.isComment() }.joinToString(separator = "\n")
|
||||
|
||||
dotEnvFile.writeText(
|
||||
charset = charset,
|
||||
text = """
|
||||
|$parsedComment
|
||||
|
|
||||
|$parsedLines
|
||||
|
|
||||
""".trimMargin()
|
||||
)
|
||||
}
|
||||
|
||||
fun envProperties(configure: MapProperty<String, String>.() -> Unit) {
|
||||
envProperties.configure()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmName("putProvider")
|
||||
fun <K : Any, V : Any> MapProperty<K, V>.put(entry: Pair<K, Provider<V>>) =
|
||||
put(entry.first, entry.second)
|
||||
|
||||
@JvmName("putValue")
|
||||
fun <K : Any, V : Any> MapProperty<K, V>.put(entry: Pair<K, V>) =
|
||||
put(entry.first, entry.second)
|
||||
|
||||
private fun String.isComment(): Boolean = trim().startsWith('#')
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ abstract class GDCPlugin @Inject constructor(
|
|||
val dockerComposeEnvUpdate by target.tasks.registering(DockerEnvUpdateTask::class) {
|
||||
dotEnvFile.set(gdcSettings.srcDir.file(".env"))
|
||||
|
||||
envProperties.convention(gdcSettings.dotEnv)
|
||||
// properties(
|
||||
// "COMPOSE_PROJECT_NAME" to gdcSettings.composeProjectName,
|
||||
// "KAFKATORIO_VERSION" to gdcSettings.composeProjectVersion,
|
||||
|
|
|
|||
|
|
@ -59,10 +59,12 @@ val kafkatorioServerToken: String by project
|
|||
|
||||
|
||||
tasks.dockerComposeEnvUpdate {
|
||||
properties(
|
||||
"FACTORIO_VERSION" to libs.versions.factorio.get(),
|
||||
"KAFKATORIO_TOKEN" to kafkatorioServerToken,
|
||||
)
|
||||
envProperties.put("FACTORIO_VERSION", libs.versions.factorio)
|
||||
envProperties.put("KAFKATORIO_TOKEN", kafkatorioServerToken)
|
||||
envProperties {
|
||||
put("FACTORIO_VERSION" , libs.versions.factorio)
|
||||
put("KAFKATORIO_TOKEN" , kafkatorioServerToken)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,15 +9,16 @@ geedeecee {
|
|||
}
|
||||
|
||||
tasks.dockerComposeEnvUpdate {
|
||||
properties(
|
||||
"GRAFANA_VERSION" to libs.versions.grafana,
|
||||
"PROMETHEUS_VERSION" to libs.versions.prometheus,
|
||||
"KAFKA_VERSION" to libs.versions.kafka,
|
||||
"KAFKA_DL_URL" to libs.versions.kafka.map { ver ->
|
||||
envProperties {
|
||||
put("GRAFANA_VERSION", libs.versions.grafana)
|
||||
put("PROMETHEUS_VERSION", libs.versions.prometheus)
|
||||
put("KAFKA_VERSION", libs.versions.kafka)
|
||||
put("KAFKA_DL_URL", libs.versions.kafka.map { ver ->
|
||||
"https://dlcdn.apache.org/kafka/$ver/kafka_2.13-$ver.tgz"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Limit JVM Heap Size
|
||||
// Limit JVM Heap Size
|
||||
// "KAFKA_BROKER_HEAP_OPTS" to "-XX:MaxRAMPercentage=70.0",
|
||||
// "KAFKA_CONNECT_HEAP_OPTS" to "-XX:MaxRAMPercentage=70.0",
|
||||
// "SCHEMA_REGISTRY_HEAP_OPTS" to "-XX:MaxRAMPercentage=70.0",
|
||||
|
|
@ -29,7 +30,7 @@ tasks.dockerComposeEnvUpdate {
|
|||
// "KAFKA_CONNECT_MEM_LIMIT" to "512m",
|
||||
// "KAFKA_KSQL_MEM_LIMIT" to "256m",
|
||||
// "SCHEMA_REGISTRY_MEM_LIMIT" to "256m",
|
||||
)
|
||||
// )
|
||||
}
|
||||
|
||||
val runKafkaCluster by tasks.registering {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
||||
|
||||
import dev.adamko.geedeecee.DockerEnvUpdateTask.Companion.put
|
||||
|
||||
plugins {
|
||||
id("kafkatorio.conventions.lang.kotlin-js")
|
||||
|
|
@ -120,10 +120,10 @@ geedeecee {
|
|||
}
|
||||
|
||||
tasks.dockerComposeEnvUpdate {
|
||||
properties(
|
||||
"KAFKATORIO_VERSION" to project.version,
|
||||
"REGISTRY_HOST" to "dcr.adamko.dev:5000",
|
||||
)
|
||||
envProperties {
|
||||
put("KAFKATORIO_VERSION" to project.version.toString())
|
||||
put("REGISTRY_HOST" to "dcr.adamko.dev:5000")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.assemble { dependsOn(tasks.dockerComposeEnvUpdate) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue