question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Every layer is rebuild even if there is no source code change

See original GitHub issue

I’m using jib-maven-plugin with version 3.1.2 and have the following added to my pom file:

<plugin>
 <groupId>com.google.cloud.tools</groupId>
 <artifactId>jib-maven-plugin</artifactId>
 <version>3.1.2</version>
</plugin>

and I use the following command to build and push an image:

mvn compile jib:build -Dimage=eu.gcr.io/project_id/image_name -Djib.to.tags=latest,another_tag -Djib.from.image=eu.gcr.io/project_id/image_name

in my Github Actions CI/CD pipeline.

But even if I don’t have any source code changes all layers are rebuild and the image is pushed:

Getting manifest for base image eu.gcr.io/project_id/image_name...
[INFO] Building dependencies layer...
[INFO] Building resources layer...
[INFO] Building classes layer...
[INFO] Building jvm arg files layer...

To my understanding no layer should be rebuild since there was no change and if I only change a dependency then only the dependency layer should be rebuild etc. I also tried adding a specific image digest for the base image but that didn’t help.

Is something wrong with the above command or is it not possible to pull the latest image from Google Container Registry, use it as base image and then have only the layers be rebuild where a change was?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chanseokohcommented, Aug 6, 2021

You misunderstood what a base image is. It doesn’t make sense to set both jib.from.image and jib.to image to the same image. You build a new image by adding layers of your application (classes, resources, …) on top of a base image. Then, what you did was to use that new image you just built as a base image and put the same application layers on top of that. That is, now you have duplicate layers. You have been repeating this process, and that is why your image size on GCR is progressively increasing.

When you are not specifying a base image, the default Jib uses is adoptopenjdk:8/11-jre, but you can choose whatever JDK image that you think works best for you.

0reactions
Alexander-Betzcommented, Aug 4, 2021

Thank you for the detailed example and information.

I see that you didn’t include -Djib.from.image=gcr.io/<GCP project>/foo in your command. But in my case this is necessary right?

Because how I understand it is that since I’m running Jib in my Github Actions workflow runs:

  • with -Djib.from.image=eu.gcr.io/project_id/image_name I’m pulling the latest image from GCR and use it as base image
  • with that Jib knows how the latest image looks like
  • then Jib rebuilds the image according to the changes in my commit
  • if there is no change it should rebuild very fast like in your case and it should upload the same image and not create a new one

Unfortunately that’s not what I’m experiencing. Here is how I’m running Jib in my workflow like mentioned in my first comment:

mvn compile jib:build -Djib.to.image=eu.gcr.io/project_id/image_name -Djib.from.image=eu.gcr.io/project_id/image_name

I just changed Dimage now to Djib.to.image and removed the tags.

I triggered my workflow 5 times (with dummy commits) and so I had Jib run 5 times. Here is the latest run:

[INFO] 
[INFO] Containerizing application to eu.gcr.io/project_id/image_name...
Warning:  Base image 'eu.gcr.io/project_id/image_name' does not use a specific image digest - build may not be reproducible
[INFO] Getting manifest for base image eu.gcr.io/project_id/image_name...
[INFO] Building dependencies layer...
[INFO] Building resources layer...
[INFO] Building classes layer...
[INFO] Building jvm arg files layer...
[INFO] The base image requires auth. Trying again for eu.gcr.io/project_id/image_name...
[INFO] Using credentials from Docker config (/home/runner/.docker/config.json) for eu.gcr.io/project_id/image_name
[INFO] Using credentials from Docker config (/home/runner/.docker/config.json) for eu.gcr.io/project_id/image_name
[INFO] Using base image with digest: sha256:44d62...
[INFO] 
[INFO] Container entrypoint set to [java, -cp, @/app/jib-classpath-file, path/to/class]
[INFO] 
[INFO] Built and pushed image as eu.gcr.io/project_id/image_name
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  16.783 s
[INFO] Finished at: 2021-08-04T16:18:13Z
[INFO] ------------------------------------------------------------------------

In GCR I see that there is always a new image added/created and for some reason the virtual size increases every time by approx. 50MB image

Do you have an idea why this is happening?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No rebuild after code change - Visual Studio Feedback
My project was migrated from VS2015 where it was compiling correctly for months. Under Visual Studio 2017, there are no problems after a...
Read more >
How to configure VS to compile only changed code
A setup project for example will always rebuilt, even if there are no changes made (due to this fact I normally exclude the...
Read more >
Watch code and automatically rebuild when something changes
Compose could watch your code and automatically kick off builds when something changes. This would mean: Code can be reloaded automatically regardless of ......
Read more >
Incremental Dev Container Rebuild | GitHub Changelog
The rebuild behavior prior to this change was full rebuild, which is slower but guarantees correctness because it removes all images from the ......
Read more >
Why Visual Studio keeps rebuilding my projects for no good ...
Did you ever feel like Visual Studio is rebuilding projects every single time, even when there were no changes to the code?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found