Skip to content

Commit ac01c80

Browse files
committed
chore: jib plugin changes
1 parent a457e5e commit ac01c80

File tree

4 files changed

+56
-36
lines changed

4 files changed

+56
-36
lines changed

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ otel-instr-alpha = "2.16.0-alpha"
7474
otel-semconv = "1.32.0"
7575
otel-contrib = "1.46.0-alpha"
7676
otel-kotlin = "0.1.1"
77-
okio = "3.11.0"
77+
okio = "3.12.0"
7878
sslcontext-kickstart = "9.1.0"
7979
ksp-auto-service = "1.2.0"
8080
zip-prefixer = "0.3.1"
@@ -95,7 +95,7 @@ oshi = "6.8.1"
9595
junit = "5.13.0-RC1"
9696
koin = "4.1.0-RC1"
9797
koin-annotations = "2.0.1-RC1"
98-
metro = "0.3.3"
98+
metro = "0.3.4"
9999
kotest = "6.0.0.M4"
100100
mockk = "1.14.2"
101101
mokkery = "2.8.0"
@@ -234,7 +234,7 @@ nexus-publish = "2.0.0"
234234
vanniktech-publish = "0.32.0"
235235
gradle-publish = "1.3.1"
236236
shadow = "9.0.0-beta13"
237-
spotless = "7.0.3"
237+
spotless = "7.0.4"
238238
semver-plugin = "0.8.0"
239239
gratatouille = "0.0.8"
240240
vercraft = "0.6.0"

plugins/project/src/main/kotlin/common/ProjectExtns.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,19 @@ val Project.defaultJarManifest
187187
}
188188
}
189189

190+
val Project.containerLabels
191+
get() =
192+
mapOf(
193+
"maintainer" to project.githubUser,
194+
"org.opencontainers.image.authors" to project.githubUser,
195+
"org.opencontainers.image.title" to project.name,
196+
"org.opencontainers.image.description" to "🐳 ${project.description}",
197+
"org.opencontainers.image.version" to project.version.toString(),
198+
"org.opencontainers.image.vendor" to project.githubUser,
199+
"org.opencontainers.image.url" to project.githubRepo,
200+
"org.opencontainers.image.source" to project.githubRepo,
201+
"org.opencontainers.image.licenses" to "Apache-2.0")
202+
190203
val Project.defaultJvmArgs
191204
get() = buildList {
192205
addAll(libs.versions.java.jvmargs.get().split(",", " ").filter(String::isNotBlank))
@@ -578,6 +591,7 @@ fun KotlinSourceSet.ksp(dependencyNotation: Any) {
578591
listOf(
579592
KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME,
580593
KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME) -> "commonMainMetadata"
594+
581595
name.endsWith("Main") -> name.substringBeforeLast("Main")
582596
else -> name
583597
}.replaceFirstChar { it.uppercaseChar() }

plugins/project/src/main/kotlin/dev.suresh.plugin.common.gradle.kts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
1+
import com.github.ajalt.mordant.rendering.TextColors
12
import com.github.ajalt.mordant.rendering.TextColors.*
2-
import me.saket.bytesize.decimalBytes
3+
import com.google.cloud.tools.jib.gradle.BuildDockerTask
4+
import me.saket.bytesize.*
5+
import org.gradle.kotlin.dsl.*
36

47
tasks {
8+
pluginManager.withPlugin("com.google.cloud.tools.jib") {
9+
withType<BuildDockerTask>().configureEach {
10+
doLast {
11+
val indent = " ".repeat(9)
12+
val portMapping =
13+
jib?.container?.ports.orEmpty().joinToString(" \\\n $indent") { "-p $it:$it" }
14+
val image = jib?.to?.image ?: project.name
15+
val tag = jib?.to?.tags?.firstOrNull() ?: "latest"
16+
val env =
17+
jib?.container
18+
?.environment
19+
.orEmpty()
20+
.map { "-e ${it.key}=${it.value}" }
21+
.joinToString(" \\\n $indent")
22+
23+
val cmd = buildString {
24+
appendLine("To run the container,")
25+
appendLine("$ docker run \\")
26+
appendLine("$indent -it --rm \\")
27+
appendLine("$indent --name ${project.name} \\")
28+
if (portMapping.isNotBlank()) {
29+
appendLine("$indent $portMapping \\")
30+
}
31+
if (env.isNotBlank()) {
32+
appendLine("$indent $env \\")
33+
}
34+
appendLine("$indent $image:$tag")
35+
}
36+
logger.lifecycle(TextColors.cyan(cmd))
37+
}
38+
}
39+
}
40+
541
register("printArtifacts") {
642
doLast {
743
val configsWithArtifacts =

plugins/project/src/main/kotlin/dev.suresh.plugin.kotlin.jvm.gradle.kts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import com.github.ajalt.mordant.rendering.TextColors
21
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
3-
import com.google.cloud.tools.jib.gradle.BuildDockerTask
42
import com.google.devtools.ksp.gradle.KspAATask
53
import common.*
64
import java.io.*
@@ -176,9 +174,8 @@ tasks {
176174
logger.quiet(
177175
"""
178176
|Application modules for OpenJDK-${javaRelease.get()} are,
179-
|${modules.split(",")
180-
.mapIndexed { i, module -> " ${(i + 1).toString().padStart(2)}) $module" }
181-
.joinToString(System.lineSeparator())}
177+
|${modules.split(",").mapIndexed { i, module -> " ${(i + 1).toString()
178+
.padStart(2)}) $module" }.joinToString(System.lineSeparator())}
182179
"""
183180
.trimMargin())
184181
}
@@ -207,33 +204,6 @@ tasks {
207204
}
208205

209206
processResources { dependsOn(copyOtelAgent) }
210-
211-
// Docker command to run the image
212-
withType<BuildDockerTask>().configureEach {
213-
doLast {
214-
val portMapping =
215-
jib?.container?.ports.orEmpty().joinToString(" \\\n ") { "-p $it:$it" }
216-
val image = jib?.to?.image ?: project.name
217-
val tag = jib?.to?.tags?.firstOrNull() ?: "latest"
218-
val env =
219-
jib?.container
220-
?.environment
221-
.orEmpty()
222-
.map { "-e ${it.key}=${it.value}" }
223-
.joinToString(" \\\n ")
224-
logger.lifecycle(
225-
TextColors.cyan(
226-
"""
227-
|Run: docker run \
228-
| -it --rm \
229-
| --name ${project.name} \
230-
| $portMapping \
231-
| $env \
232-
| $image:$tag
233-
"""
234-
.trimMargin()))
235-
}
236-
}
237207
}
238208

239209
pluginManager.withPlugin("org.jetbrains.kotlinx.binary-compatibility-validator") {

0 commit comments

Comments
 (0)