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

Export classpath and mainClass as environment variables. #82

Merged

Conversation

thomasmey
Copy link
Contributor

Jib automatically determines the main class and sets the image'
entrypoint accordingly.
This extension exports these values also as environment variables
in the created image, so a custom entrypoint script can do some processing
and then jump into java with:
java -cp ${JIB_JAVA_CLASSPATH} ${JIB_JAVA_MAIN_CLASS}

See also issue GoogleContainerTools/jib#3147

@google-cla

This comment has been minimized.

@thomasmey
Copy link
Contributor Author

@googlebot I signed it

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the awesome contribution! This is indeed what many people have asked for multiple times and what we really wanted to do eventually. This will be super useful!

And this extension can be expanded in the future so that not only it sets the environment variables but it directly substitutes these values for some keywords in an entrypoint.

    <pluginExtensions>
      <pluginExtension>
        <implementation>com.google.cloud.tools.jib.maven.extension.classpathmainclass.JibClasspathMainClassExtension</implementation>
        <configuration implementation="com.google.cloud.tools.jib.maven.extension.classpathmainclass.Configuration">

          <!-- extension configuration -->
          <entrypoint>java,-cp,JIB_JAVA_CLASSPATH:/my/classpath,-Dmy.prop=value,JIB_JAVA_MAIN_CLASS</entrypoint>
        </configuration>
      </pluginExtension>
    </pluginExtensions>

But that's another idea going forward, and I think this extension is already very useful!

@chanseokoh
Copy link
Member

And you can do ./gradlew build to run tests locally.

@chanseokoh
Copy link
Member

@thomasmey just checking in, will you keep working on this?

@thomasmey
Copy link
Contributor Author

Hi,

Yes, will do so.

I want to add some unit tests.
Can you please review the current state again, after forced push update?

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

first-party/settings.gradle Outdated Show resolved Hide resolved
}

dependencies {
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
Copy link
Member

@chanseokoh chanseokoh Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have a common project. The Maven and Gradle extensions will be published as separate JARs, so unless we publish the common project as another separate JAR, having a common package will result in split packages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, we should duplicate the code in Maven and Gradle, and that's fine.

@thomasmey
Copy link
Contributor Author

Hi, another update. now with tests! 😄

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good!

You will be able to see that ./gradlew build is failing on GitHub Actions unit tests. I think it can be fixed by copying necessary things from a build.gradle file in other first-party extensions.

@chanseokoh

This comment has been minimized.

@thomasmey

This comment has been minimized.

@chanseokoh

This comment has been minimized.

@codecov
Copy link

codecov bot commented Mar 25, 2021

Codecov Report

Merging #82 (2bbade9) into master (ad3293f) will decrease coverage by 1.88%.
The diff coverage is 58.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #82      +/-   ##
============================================
- Coverage     84.87%   82.98%   -1.89%     
- Complexity      152      160       +8     
============================================
  Files            14       18       +4     
  Lines           628      676      +48     
  Branches         73       81       +8     
============================================
+ Hits            533      561      +28     
- Misses           83       93      +10     
- Partials         12       22      +10     
Impacted Files Coverage Δ Complexity Δ
...spathmainclass/JibClasspathMainClassExtractor.java 50.00% <50.00%> (ø) 2.00 <2.00> (?)
...spathmainclass/JibClasspathMainClassExtractor.java 50.00% <50.00%> (ø) 2.00 <2.00> (?)
...spathmainclass/JibClasspathMainClassExtension.java 83.33% <83.33%> (ø) 2.00 <2.00> (?)
...spathmainclass/JibClasspathMainClassExtension.java 83.33% <83.33%> (ø) 2.00 <2.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad3293f...2bbade9. Read the comment docs.

Jib automatically determines the main class and sets the image'
entrypoint accordingly.
This extension exports these values also as environment variables
in the created image, so a custom entrypoint script can do some
processing
and then jump into java with:
  java -cp ${JIB_JAVA_CLASSPATH} ${JIB_JAVA_MAIN_CLASS}

See also issue GoogleContainerTools/jib#3147
@thomasmey

This comment has been minimized.

@thomasmey
Copy link
Contributor Author

please have a look again, look good to me now.
and thanks for your patience with me 😄

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. There are a few things to fix, but given the delay, I'll take care of it after merging this.

Thank you very much for this great contribution! It'll be very useful to many people.

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

Successfully merging this pull request may close these issues.

2 participants