Jib: Support scratch image

Created on 10 Feb 2019  路  11Comments  路  Source: GoogleContainerTools/jib

Hi guys,

with jlink, java will also use scratch image in FROM clause but ImageReference does not enable that. Is it possible to support it somehow?

arejib-core

Most helpful comment

We added a Jib.fromScratch method, which will be available in the next release of jib-core.

All 11 comments

Can you provide some more detail? Maybe an example of a workflow?

yes, basically I build with maven a native java image with jlink plugin so I get a custom java distro (of 17M in my case), then I use jib-core in a groovy script to create the image but scratch image is not supported and I have to use forks to workaround the limitation of jib.
The jib setup is simply to add the jlink zip exploded and set the right entry point.

Ah yes, I guess we force the user to select a FROM. Just curious: does the final jre generated by jlink really require nothing? I suspect it would at least need glibc?

Do you have an equivalent Dockerfile that works here?

Otherwise I would think that you would at least need to use FROM gcr.io/distroless/base?

Hmm, this can be the short term impl, if scratch -> switch to that. I didn't check if libc is needed or not, that's a good point!

A quick test with distroless/base ends with:

bin/java: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

edit: I can confirm glibc is required too
edit2: guess it is linked to https://github.com/GoogleContainerTools/distroless/issues/217, wdyt?

As a side note, here's a way to make your own scratch image to use:

Dockerfile:

FROM bash as base
RUN mkdir /empty
FROM scratch
COPY --from=base /empty /
docker build -t <image on your own registry> .
docker push <image on your own registry>

We will support using scratch as the base image in Jib. Using scratch will skip any base image steps in the Jib build.

I don't know if we should use a keyword like scratch in the core if that's what you're suggesting. Maybe just a mechanism to do this pro grammatically by augmenting the api.

Ah, @chanseokoh just educated me on the special keyword scratch in docker : https://hub.docker.com/_/scratch

So we are just mimicking that behavior. :+1:

Yea, another option is to add a Jib.fromScratch method for this. The support for keyword scratch is just to match the expected behavior of using the official scratch "image" so that if users use it they don't just break.

We added a Jib.fromScratch method, which will be available in the next release of jib-core.

Was this page helpful?
0 / 5 - 0 ratings