Skip to content

Commit

Permalink
Support multiple jib tags (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 authored Jan 27, 2025
1 parent 771fda9 commit e64ebbc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.bakdata.gradle

import org.gradle.api.Project
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.property

/**
Expand All @@ -36,7 +37,8 @@ open class JibImageConfigExtension(project: Project) {
}

val repository =
project.objects.property<String>().convention(System.getProperty("jibImage.repository")?.toString())
project.objects.property<String>().convention(System.getProperty("jibImage.repository"))
val name = project.objects.property<String>().convention(project.name)
val tag = project.objects.property<String>().convention(System.getProperty("jibImage.tag")?.toString())
val tags = project.objects.listProperty<String>()
.convention(System.getProperty("jibImage.tags")?.split(',')?.filter(String::isNotEmpty) ?: emptyList())
}
4 changes: 3 additions & 1 deletion jib/src/main/kotlin/com/bakdata/gradle/JibPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ class JibPlugin : Plugin<Project> {

afterEvaluate {
val repository = extension.repository.orNull?.let { "$it/" } ?: ""
val tag = extension.tag.orNull?.let { ":$it" } ?: ""
val allTags = extension.tags.getOrElse(emptyList())
val tag = allTags.firstOrNull()?.let { ":$it" } ?: ""
// The imageString should not contain any uppercase letters
// https://docs.docker.com/engine/reference/commandline/tag/#extended-description
val imageString = "${repository}${extension.name.get()}${tag}".lowercase(Locale.getDefault())
configure<JibExtension> {
to {
image = imageString
tags = if (allTags.isEmpty()) emptySet() else HashSet(allTags.subList(1, allTags.size))
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions jib/src/test/kotlin/com/bakdata/gradle/JibPluginIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal class JibPluginIT {
.withArguments(
"showJibImage",
"-DjibImage.repository=gcr.io/bakdata",
"-DjibImage.tag=a-tag"
"-DjibImage.tags=a-tag"
)
.withProjectPluginClassPath()
.build()
Expand All @@ -124,14 +124,20 @@ internal class JibPluginIT {
jibImage {
repository.set("gcr.io/bakdata")
name.set("jib-image")
tag.set("a-tag")
tags.set(listOf("a-tag", "another-tag"))
}
tasks.create("showJibImage") {
afterEvaluate {
print(jib.to.image)
}
}
tasks.create("showJibTags") {
afterEvaluate {
print(jib.to.tags) // this task somehow appends the additional tags to jib.to.image
}
}
""".trimIndent()
)

Expand All @@ -143,7 +149,7 @@ internal class JibPluginIT {

SoftAssertions.assertSoftly { softly ->
softly.assertThat(result.output)
.contains("gcr.io/bakdata/jib-image:a-tag")
.contains("gcr.io/bakdata/jib-image:a-tag[another-tag]")
}
}
}

0 comments on commit e64ebbc

Please sign in to comment.