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

Have API in jib-core to control base image caching #1870

Closed
chanseokoh opened this issue Jul 25, 2019 · 12 comments
Closed

Have API in jib-core to control base image caching #1870

chanseokoh opened this issue Jul 25, 2019 · 12 comments

Comments

@chanseokoh
Copy link
Member

chanseokoh commented Jul 25, 2019

#1840 introduced the optimization to skip downloading base image layers that exist in a target registry. The only way to disable it is through a system property jib.alwaysCacheBaseImage. Add an API to jib-core to control this behavior.

@rajovictor
Copy link
Contributor

@chanseokoh Is this API still needed since we already have jib.alwaysCacheBaseImage?
If yes, as you have mentioned in https://github.com/GoogleContainerTools/jib/pull/1840/files/4d35db603797445a7eac029317456a7b0601ea67#r307533038, should it be created in a different class? And can you also please point me to the steps where this property should be used?

@chanseokoh
Copy link
Member Author

Hi @rajovictor,

Is this API still needed since we already have jib.alwaysCacheBaseImage?

That's a good question. Not sure, but I guess it makes sense to have an API.

And can you also please point me to the steps where this property should be used?

I think you can just set System.setProperty("jib.alwaysCacheBaseImage", "true") before running Jib. Is this what you were asking?

@rajovictor
Copy link
Contributor

rajovictor commented Oct 14, 2019

Hi @chanseokoh,
My question was, once the jib.alwaysCacheBaseImage jib.cacheBaseImage API is added, where and how do we use it in the StepsRunner to cache or not the base images?
Or does this issue only cover, adding this API to the JibSystemProperties class?

@chanseokoh
Copy link
Member Author

If jib.alwaysCacheBaseImage is set, Jib will automatically pick up it and do the right thing. The code in StepsRunner reads in this property.

  public StepsRunner registryPushSteps() {
    rootProgressDescription = "building image to registry";
    boolean layersRequiredLocally = JibSystemProperties.alwaysCacheBaseImage();

If the property is not set, Jib (and jib-core) will do the skip-base-image-downloading optimization (for registry pushes) by default. If set, the images will always be downloaded.

And this issue wasn't about adding the API to JibSystemProperties, but adding (for example) .alwaysCacheBaseImage(boolean) to Containerizer.

@rajovictor
Copy link
Contributor

Ok, using jib.cacheBaseImage and then reverting it to jib.alwaysCacheBaseImage caused the confusion for me - I think I spent too much time reading the comments in #1840.

Now, jib.alwaysCacheBaseImage is used inregistryPushSteps() which is called from to(RegistryImage registryImage). Thats when an instance of Containerizer is created fro the first time, but the jib.alwaysCacheBaseImage property is not part of the to object to set alwaysCacheBaseImage(boolean) of Containerizer.

Could you please advise me on how to proceed here?

@chanseokoh
Copy link
Member Author

chanseokoh commented Oct 14, 2019

Sorry, I'm still confused too. Maybe we are not on the same page.

I assume

  • You are writing a Java program that uses jib-core 0.11.0, to build some Docker image and push it to a remote registry.
  • That said, I believe you are probably doing something like
        Containerizer containerizer = Containerizer.to(RegistryImage.named("example.com/my/repository"));
        Jib.from("example.com/my/base/image").containerize(containerizer);
  • For whatever reason, you want to turn off the base image cache optimization. (But why?) That is, setting the jib.alwaysCacheBaseImage property and forcing jib-core to always download base images.

So, what you can do (for now, until this issue to add an API is closed) is

    System.setProperty("jib.alwaysCacheBaseImage", "true");
    Containerizer containerizer = Containerizer.to(RegistryImage.named("example.com/my/repository"));
    Jib.from("example.com/my/base/image").containerize(containerizer);

And note that jib.alwaysCacheBaseImage is relevant only for remote registry push; for building to local Docker daemon or building a tar, jib-core will always cache base images.

However, do note that setting the system property will affect the whole JVM. That's another reason to have an API to control this.

@rajovictor
Copy link
Contributor

I understood the above part fine.
The part which is not clear to me is, once the API for this property is added, how do I use it in StepsRunner which currently does not access Containerizer class.

Function<BuildConfiguration, StepsRunner> stepsRunnerFactory =
        buildConfiguration -> StepsRunner.begin(buildConfiguration).registryPushSteps();

Sorry if I am asking basic questions.

@TadCordle
Copy link
Contributor

TadCordle commented Oct 14, 2019

StepsRunner and BuildConfiguration aren't in the api package and thus aren't considered part of jib-core's formal API, so if you intend on using these classes (which I can't recommend, since we often refactor internals), it'll depend on how we propagate the property internally when we implement it. If I had to guess, it'd likely be accessible from BuildConfiguration or Cache (from buildConfiguration.getBaseImageLayersCache()).

@rajovictor
Copy link
Contributor

rajovictor commented Oct 14, 2019

@TadCordle Thank you for stepping in. I will be working on the changes and create a PR.

@chanseokoh chanseokoh removed the question User inquiries label Oct 14, 2019
@rajovictor
Copy link
Contributor

Submitted the PR #2065.

@chanseokoh
Copy link
Member Author

Fixed by #2065.

@chanseokoh
Copy link
Member Author

Will add a CHANGELOG.

@chanseokoh chanseokoh added this to the v0.12.0-core milestone Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants