question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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')

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
chanseokohcommented, Jun 14, 2021

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

1reaction
chanseokohcommented, May 18, 2021

@NaitYoussef thanks for your interest!

As noted in https://github.com/GoogleContainerTools/jib/issues/3094#issuecomment-788064416,

  • Going forward, we decided to expose Property<?> in this particular way (#3034 and #3121) for new parameters. And perhaps this is not possible with existing parameters for compatibility reasons. (Could be revamped in a major version change.)

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy Configuration - Gradle User Manual
Lazy properties · Build authors can wire together Gradle models without worrying when a particular property's value will be known. · Build authors...
Read more >
google/jib - Gitter
I have a jibTarBuild (with the Gradle plugin) running as part of a Jenkins job (and Jenkins triggers the gradle build inside a...
Read more >
Create images using Jib Gradle plugin
Jib is a tool created by Google to create layered Docker and OCI images without a Docker file.
Read more >
Spring Native documentation
The Spring AOT plugin also requires a dedicated plugin repository in the pom.xml file for Maven and in the in the settings.gradle(.kts) for ......
Read more >
Gradle Docker Plugin User Guide & Examples - GitHub Pages
Gradle plugin for managing Docker images and containers using via its remote API. The heavy lifting of communicating with the Docker remote ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found