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

Is it possible to do the same thing through pom as jib-cli ? #4207

Closed
daromnik opened this issue Mar 5, 2024 · 1 comment
Closed

Is it possible to do the same thing through pom as jib-cli ? #4207

daromnik opened this issue Mar 5, 2024 · 1 comment

Comments

@daromnik
Copy link

daromnik commented Mar 5, 2024

Hello.

Sorry that perhaps this is not the place to write.
I have a question, I couldn’t find information on it in the faq.

I'm using spring boot + proguard + jib.
I was able to get my jar to load into docker and run successfully via jib-cli.

ex: jib jar --target docker://myregistry/auth auth-0.0.1.jar --from baseimage

But is there a way to arrange all this through pom.xml of my service via jib-maven-plugin?

Here https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#i-want-to-containerize-a-jar it is written about
packaged.

But it doesn't give the same result.

@daromnik
Copy link
Author

daromnik commented Mar 7, 2024

Ultimately, I achieved the desired result with the help of the following changes in the settings of the jib-maven-plugin plugin:

  1. add dependency to the plugin jib-layer-filter-extension-maven - this is for managing layers when creating an image:
<dependencies>
    <dependency>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-layer-filter-extension-maven</artifactId>
        <version>0.3.0</version>
    </dependency>
</dependencies>
  1. Add extraDirectories so that fat jar formed by spring boot is included to the image:
<extraDirectories>
    <paths>
        <path>
            <from>target</from>
            <into>/app/classpath</into>
            <includes>*.jar</includes>
        </path>
    </paths>
</extraDirectories>
  1. Then in pluginExtensions we delete the old jar that created jib and delete libs, because all libs are in our fat jar from spring:
<pluginExtensions>
    <pluginExtension>
        <implementation>com.google.cloud.tools.jib.maven.extension.layerfilter.JibLayerFilterExtension</implementation>
        <configuration implementation="com.google.cloud.tools.jib.maven.extension.layerfilter.Configuration">
            <filters>
                <filter>
                    <glob>/app/classpath/*.original.jar</glob>
                </filter>
                <filter>
                    <glob>/app/libs/*.jar</glob>
                </filter>
            </filters>
        </configuration>
    </pluginExtension>
</pluginExtensions>
  1. And we add the correct entry point of our jar for spring (if we have spring boot >= 3.2, then the class will be different org.springframework.boot.loader.launch.JarLauncher):
<entrypoint>java,-cp,@/app/jib-classpath-file,org.springframework.boot.loader.JarLauncher</entrypoint>

As a result, fat jar will simply lie in /app/classpath folder.
If you do everything through jib-cli, then instead of fat jar there will be an unpacked jar in the /app folder.

@daromnik daromnik closed this as completed Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant