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

Convert Gradle config parameters (such as jib.container.labels) to use lazy evaluation #3094

Closed
remy-tiitre opened this issue Mar 1, 2021 · 8 comments

Comments

@remy-tiitre
Copy link

Just like there was an issue to make the jib.to.tags and jib.to.auth to be lazyly evaluated I would need to have the container.labels do the same. Even the reason is the same. I use com.gorylenko.gradle-git-properties Gradle plugin and would like to reuse its properties to add labels to my images. Something like that:

jib {
    container {
        labels = [
            'org.label-schema.vcs-url': project.ext.gitProps['git.remote.origin.url'],
            'org.label-schema.vcs-branch': project.ext.gitProps['git.branch'],
            'org.label-schema.vcs-ref': project.ext.gitProps['git.commit.id.abbrev']
        ]
    }
}

In our case I would make that configuration global and add this snipped to our custom gradle wrapper init script.

I did try something like this:

jib
    container {
        labels = [
            ...
            'org.label-schema.vcs-ref': "${-> project.ext.gitProps['git.commit.id.abbrev']}"
        ]
    }
}

But this errored out with this message:
> class org.codehaus.groovy.runtime.GStringImpl cannot be cast to class java.lang.String (org.codehaus.groovy.runtime.GStringImpl is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @47c62251; java.lang.String is in module java.base of loader 'bootstrap')

@chanseokoh
Copy link
Member

chanseokoh commented Mar 1, 2021

Thanks for your feedback! Given the use case, I think making labels (among other parameters) lazily configurable will be very useful.

We also welcome contributions.

Technical notes:

@chanseokoh
Copy link
Member

As an immediate workaround, I wonder if setting jib.container.labels in a project.afterEvalaute block can work for the com.gorylenko.gradle-git-properties plugin, like in this way.

@NaitYoussef
Copy link
Contributor

NaitYoussef commented May 14, 2021

Hello I would like to help with this issue

@chanseokoh
Copy link
Member

chanseokoh commented May 14, 2021

@NaitYoussef thanks for your interest!

As noted in #3094 (comment),

the way we decided to expose Gradle properties is to use Property<?> like this. That is, no setters but a getter will directly expose a Property<?>.

This GitHub issue is about jib.container.labels, so my guess is that this property labels should be changed to be of type MapProperty. This may not be fully backward-compatible, but I think should be fine most of the time.

@chanseokoh
Copy link
Member

chanseokoh commented Jun 4, 2021

Fixed by #3242.

@chanseokoh
Copy link
Member

chanseokoh commented Jun 9, 2021

@remy-tiitre @ChristianCiach @NaitYoussef Jib 3.1.1 is released with this support. Let us know if it doesn't work.

@jamesdh
Copy link

jamesdh commented Jul 8, 2021

@chanseokoh I believe you meant Fixed by #3242?

It might be worth mentioning somewhere that this can cause a breakage if using a Kotlin based build.gradle, causing a Val cannot be reassigned error.

@chanseokoh
Copy link
Member

@jamesdh I guess you'll have to use .set() in Kotlin? Is that the only possible way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants