Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use the org.eclipse.jkube.kubernetes plugin in Gradle Kotlin DSL? #3174

Open
wjmwss opened this issue Jun 19, 2024 · 6 comments
Open
Labels
enhancement New feature or request

Comments

@wjmwss
Copy link

wjmwss commented Jun 19, 2024

How can I use the org.eclipse.jkube.kubernetes plugin in Gradle Kotlin DSL?

@rohanKanojia
Copy link
Member

@wjmwss : Hello, Could you please share more details on what you're trying to do? What configuration option do you want to use?

@arman-yekkehkhani
Copy link
Contributor

@wjmwss Here is an article by Rohan to get started using Jkube with Gradle Get started with Gradle plugins for Eclipse JKube. You might need to make slight adjustments to build script to compensate for the difference between Groovy and Koltin DSL.

@wjmwss
Copy link
Author

wjmwss commented Jun 21, 2024

@wjmwss : Hello, Could you please share more details on what you're trying to do? What configuration option do you want to use?

Thank you for your reply!

I'm a beginner in gradle kotlin dsl and now I hope to use the 'org.eclipse.jkube.kubernetes' plugin to quickly deploy my spring boot project to kubernetes.

I have referred to the official documentation of this plugin, the example in the documentation are all using gradle groovy dsl, I encountered difficulties in converting it to gradle kotlin dsl:
581718955956_ pic

No matter what I try, I cannot convert the example gradle groovy dsl in the documentation to gradle kotlin dsl:
591718956264_ pic

Can you please provide a complete example of using the 'org.eclipse.jkube.kubernetes' plugin about gradle kotlin dsl?

Thank you!

@wjmwss
Copy link
Author

wjmwss commented Jun 21, 2024

@wjmwss Here is an article by Rohan to get started using Jkube with Gradle Get started with Gradle plugins for Eclipse JKube. You might need to make slight adjustments to build script to compensate for the difference between Groovy and Koltin DSL.

Thank you for your reply!

I'm a beginner in gradle kotlin dsl, my biggest problem currently is not knowing how to convert gradle groovy dsl to gradle kotlin dsl.

In the source code of 'KubernetesExtension', I see that many of the input parameters to the f
unction are 'Closure'. 'Closure' in my understanding belongs to groovy syntax, and it seems that kotlin cannot be called?
601718956576_ pic

What can be called by kotlin is 'Action', and I see that all the functions of the 'KubernetesExtension', only the 'addImage' function use Action.
WX20240621-35926 PM@2x

Therefore, I cannot determine whether the 'org.eclipse.jkube.kubernetes' plugin supports kotlin DSL, and I am not sure if my understanding is correct.

@arman-yekkehkhani
Copy link
Contributor

@wjmwss Here is a minimal build script with similar configurations. I assume the Kotlin API may not be fully covered yet, so you can follow a general approach using builders to build your config object incrementally.

import org.eclipse.jkube.kit.common.Assembly
import org.eclipse.jkube.kit.common.AssemblyConfiguration
import org.eclipse.jkube.kit.common.AssemblyFileSet
import org.eclipse.jkube.kit.config.image.ImageConfiguration
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration

plugins {
    id("java")
    id("org.eclipse.jkube.kubernetes") version "1.16.2"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.9.1"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}

kubernetes {
    val assemblyConfig = AssemblyConfiguration.builder()
            .targetDir("/deployments")
            .layers(listOf(Assembly.builder()
                    .fileSets(listOf(AssemblyFileSet.builder()
                            .directory(file("${project.rootDir}/build/dependencies"))
                            .build())
                    ).build()))
            .build()

    val buildConfig = BuildConfiguration.builder()
            .from("quay.io/jkube/jkube-java:0.0.13")
            .assembly(assemblyConfig)
            .env(mapOf(
                    "JAVA_LIB_DIR" to "/deployments/dependencies/*",
                    "JAVA_MAIN_CLASS" to "org.apache.camel.cdi.Main",
            ))
            .labels(mapOf(
                    "labelWithValue" to "foo",
                    "version" to "${project.version}",
                    "artifactId" to project.name,
            ))
            .ports(listOf("8787"))
            .build()

    val image = ImageConfiguration.builder()
            .name("jkube/${project.name}:${project.version}")
            .alias("camel-service")
            .build(buildConfig)
            .build()

    images = listOf(image)
}

@wjmwss
Copy link
Author

wjmwss commented Jun 24, 2024

@wjmwss Here is a minimal build script with similar configurations. I assume the Kotlin API may not be fully covered yet, so you can follow a general approach using builders to build your config object incrementally.

import org.eclipse.jkube.kit.common.Assembly
import org.eclipse.jkube.kit.common.AssemblyConfiguration
import org.eclipse.jkube.kit.common.AssemblyFileSet
import org.eclipse.jkube.kit.config.image.ImageConfiguration
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration

plugins {
    id("java")
    id("org.eclipse.jkube.kubernetes") version "1.16.2"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(platform("org.junit:junit-bom:5.9.1"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
    useJUnitPlatform()
}

kubernetes {
    val assemblyConfig = AssemblyConfiguration.builder()
            .targetDir("/deployments")
            .layers(listOf(Assembly.builder()
                    .fileSets(listOf(AssemblyFileSet.builder()
                            .directory(file("${project.rootDir}/build/dependencies"))
                            .build())
                    ).build()))
            .build()

    val buildConfig = BuildConfiguration.builder()
            .from("quay.io/jkube/jkube-java:0.0.13")
            .assembly(assemblyConfig)
            .env(mapOf(
                    "JAVA_LIB_DIR" to "/deployments/dependencies/*",
                    "JAVA_MAIN_CLASS" to "org.apache.camel.cdi.Main",
            ))
            .labels(mapOf(
                    "labelWithValue" to "foo",
                    "version" to "${project.version}",
                    "artifactId" to project.name,
            ))
            .ports(listOf("8787"))
            .build()

    val image = ImageConfiguration.builder()
            .name("jkube/${project.name}:${project.version}")
            .alias("camel-service")
            .build(buildConfig)
            .build()

    images = listOf(image)
}

Your code example is very helpful to me, thank you so much!

@manusa manusa added the enhancement New feature or request label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants