1

I created a base image for a Java application using Jib which I want to extend using Jib. (The Java application provides extensibility by loading additional Jars from the classpath)

In the extending gradle project, I did this:

jib {
    ....
    container {
        entrypoint = 'INHERIT'
        
    }
    ...
}

It allowed me to reuse the entrypoint and args attributes added in the base image but I also want to extend/reuse the base classpath file. As Jib creates /app/jib-classpath-file in the extending gradle project, the base layer /app/jib-classpath-file is not visible ( I would assume). To workaround the issue, I added this in extending container configuration block.

extraClasspath = ['/app/libs/*']

Is there an idiomatic way of achieving this in Jib? One option I was thinking is to specify unique classpath files in base and extending projects and use them like this in the Java command line: java -cp @/app/jib-BASE-classpath-file @/app/jib-EXTENDED-classpath-file, but I am not finding the option of specifying the classpath file. What is the recommended way? Thanks

Santi
  • 67
  • 7
  • One idea (that may or may not work for you) is to configure `jib.container.appRoot` to change the default app root from `/app` to something else in either image so that the two `jib-classpath-file` files don't end up in the same `/app` directory. – Chanseok Oh Feb 24 '22 at 18:58

1 Answers1

0

Not a total solution but this shows how to remove the jvm args layer from the child image build altogether.

//build.gradle.kts

buildscript {
  dependencies {
    classpath("com.google.cloud.tools:jib-layer-filter-extension-gradle:0.1.0")
  }
}

...

jib {
  ...
  pluginExtensions {
    pluginExtension {
      implementation = "com.google.cloud.tools.jib.gradle.extension.layerfilter.JibLayerFilterExtension"
      configuration (Action<com.google.cloud.tools.jib.gradle.extension.layerfilter.Configuration> {
        filters { filter { glob ="**/jib-*-file" } }
      })
    }
  }
}

This filters out files added in any given layer of a given jib build. If all the files from a layer are filtered out as in this case then the layer is never added to the image.

Sadly this does not let you see the contents of the java-classpath-file in the base image, which you would need to be able to extend it.

References:

Gabriel
  • 1,679
  • 3
  • 16
  • 37