Skip to content

Commit f83f5bc

Browse files
committed
chore: refactor jib plugin support
1 parent 946a406 commit f83f5bc

File tree

7 files changed

+58
-61
lines changed

7 files changed

+58
-61
lines changed

backend/jvm/build.gradle.kts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,7 @@ jib {
7676
mainClass = application.mainClass.get()
7777
expandClasspathDependencies = true
7878
format = ImageFormat.OCI
79-
80-
labels =
81-
mapOf(
82-
"maintainer" to project.githubUser,
83-
"org.opencontainers.image.authors" to project.githubUser,
84-
"org.opencontainers.image.title" to project.name,
85-
"org.opencontainers.image.description" to "🐳 ${project.description}",
86-
"org.opencontainers.image.version" to project.version.toString(),
87-
"org.opencontainers.image.vendor" to project.githubUser,
88-
"org.opencontainers.image.url" to project.githubRepo,
89-
"org.opencontainers.image.source" to project.githubRepo,
90-
"org.opencontainers.image.licenses" to "Apache-2.0")
79+
labels = project.containerLabels
9180
}
9281

9382
containerizingMode = "packaged"

backend/native/build.gradle.kts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,7 @@ jib {
104104
ports = listOf("8080", "9898")
105105
args = listOf(project.name, project.version.toString())
106106
format = ImageFormat.OCI
107-
labels =
108-
mapOf(
109-
"maintainer" to project.githubUser,
110-
"org.opencontainers.image.authors" to project.githubUser,
111-
"org.opencontainers.image.title" to project.name,
112-
"org.opencontainers.image.description" to "🐳 ${project.description}",
113-
"org.opencontainers.image.version" to project.version.toString(),
114-
"org.opencontainers.image.vendor" to project.githubUser,
115-
"org.opencontainers.image.url" to project.githubRepo,
116-
"org.opencontainers.image.source" to project.githubRepo,
117-
"org.opencontainers.image.licenses" to "Apache-2.0")
107+
labels = project.containerLabels
118108
mainClass = "MainKt"
119109
}
120110
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Gradle
2-
org.gradle.jvmargs=-Xmx4g --enable-native-access=ALL-UNNAMED
2+
org.gradle.jvmargs=-Xmx6g --enable-native-access=ALL-UNNAMED
33
org.gradle.parallel=true
44
org.gradle.caching=true
55
org.gradle.configureondemand=true
@@ -17,7 +17,7 @@ org.gradle.daemon=true
1717

1818
## Kotlin
1919
kotlin.code.style=official
20-
kotlin.daemon.jvmargs=-Xmx4096m --enable-native-access=ALL-UNNAMED
20+
kotlin.daemon.jvmargs=-Xmx6g --enable-native-access=ALL-UNNAMED
2121
kotlin.jvm.target.validation.mode=warning
2222
kotlinx.atomicfu.enableJvmIrTransformation=true
2323
kotlinx.atomicfu.enableNativeIrTransformation=true

gradle/build-logic/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))
@@ -581,6 +594,7 @@ fun KotlinSourceSet.ksp(dependencyNotation: Any) {
581594
listOf(
582595
KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME,
583596
KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME) -> "commonMainMetadata"
597+
584598
name.endsWith("Main") -> name.substringBeforeLast("Main")
585599
else -> name
586600
}.replaceFirstChar { it.uppercaseChar() }

gradle/build-logic/src/main/kotlin/dev.suresh.plugin.common.gradle.kts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1+
import com.github.ajalt.mordant.rendering.TextColors
12
import com.github.ajalt.mordant.rendering.TextColors.*
3+
import com.google.cloud.tools.jib.gradle.BuildDockerTask
24
import me.saket.bytesize.*
3-
import org.gradle.api.internal.artifacts.result.*
45
import org.gradle.kotlin.dsl.*
56

67
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+
741
register("printArtifacts") {
842
doLast {
943
val configsWithArtifacts =
@@ -53,7 +87,7 @@ tasks {
5387
configuration
5488
.flatMap { it.incoming.artifacts.resolvedArtifacts }
5589
.get()
56-
.filterIsInstance<DefaultResolvedArtifactResult>()
90+
.filterIsInstance<ResolvedArtifactResult>()
5791
logger.lifecycle("Found ${allResolvedArtifacts.size} resolved artifacts")
5892
}
5993
}

gradle/build-logic/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") {

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ ldaptive = "2.4.1"
194194
chicory = "1.3.0"
195195
weh-bindings = "0.5"
196196
wasm2class = "0.3"
197-
zerofs = "0.0.1"
197+
zerofs = "0.1.0"
198198
quickjs4j = "0.0.4"
199199
log4k = "0.50.0"
200200
rwmutex = "1.0.0"
@@ -228,7 +228,7 @@ swagger-style = "https://unpkg.com/[email protected]/them
228228
benmanes = "0.52.0"
229229
caupain = "1.1.1"
230230
foojay-resolver = "1.0.0"
231-
gradle-develocity = "4.0.1"
231+
gradle-develocity = "4.0.2"
232232
nmcp = "0.1.5"
233233
nexus-publish = "2.0.0"
234234
vanniktech-publish = "0.32.0"

0 commit comments

Comments
 (0)