GoogleContainerTools / jib-extensions

Apache License 2.0
118 stars 35 forks source link

Fix previously built module "leaking" file entries into subsequent build #119

Closed antonio-tomac closed 2 years ago

antonio-tomac commented 2 years ago

I'm creating just PR without opening separate issue so I'll explain the issue here.

Consider having maven multi-module project:

parent/
   shared-lib/  (skip docker build)
   service-a/   (build image)
   service-b/   (build image)

Various layer filters are defined on parent so that both service-a and service-b inherit configuration. Now, when doing maven reactor build in order: shared-lib, service-a, service-b Final result is that:

I'm not sure if this "leakage" is legit/desired in any scenario, if the answer is yes, then I would consider adding some configuration property (boolean) for this extension and then do clearing conditionally.

if (config.isClearFilteredLayers()) {  //better name
   newToLayers.clear();
}
elefeint commented 2 years ago

@antonio-tomac Thank you for the detailed description. Could you create a small reproducer project containing the project structure you've described that suffers from the leaking layers issue?

antonio-tomac commented 2 years ago

@elefeint sure, here it is https://github.com/antonio-tomac/jib-layer-filter-file-leak-demo

antonio-tomac commented 2 years ago

I've noticed that style check failed due to * import which my Intellij did without me noticing it so I reverted that change.

elefeint commented 2 years ago

@antonio-tomac There is a minor checkstyle issue -- could you run ./gradlew goJF to automatically fix it?

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

antonio-tomac commented 2 years ago

Would you be interested in sending a pull request with the fix for the same issue in jib-layer-filter-extension-gradle?

Sure, but I haven't checked how gradle behaves, maybe gradle creates new instances of plugins per every module being built so it woudn't be an issue. But I'm just guessing it at this point. I will try to reproduce it with gradle and if it suffers from issue, then I'll create PR for jib-layer-filter-extension-gradle too, or just post about my findings.

elefeint commented 2 years ago

I've tested it; same problem. Thank you!

elefeint commented 2 years ago

jib-layer-filter-extension-maven:0.3.0 released.