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

Using <external> properties in image configuration disables Docker cache during build #1455

Closed
brenuart opened this issue Apr 19, 2021 · 4 comments
Milestone

Comments

@brenuart
Copy link
Contributor

Using an external configuration of type "properties" seems to disable the Docker cache.

To illustrate the issue, I took the "multi-assembly" sample available at https://github.com/fabric8io/docker-maven-plugin/tree/master/samples/multi-assembly. After a first execution to warm up the cache, the second mvn clean package gives the following output for the docker build stage:

[INFO] DOCKER> Step 1/5 : FROM fabric8/java-centos-openjdk8-jdk:1.5.6
[INFO] DOCKER> 
[INFO] DOCKER> ---> 34854f349ada
[INFO] DOCKER> Step 2/5 : EXPOSE 8080
[INFO] DOCKER> 
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> 9a4ab427263d
[INFO] DOCKER> Step 3/5 : COPY deps /app/lib/
[INFO] DOCKER> 
[INFO] DOCKER> ---> Using cache
[INFO] DOCKER> ---> d5a69097ec70
[INFO] DOCKER> Step 4/5 : COPY maven /app/
[INFO] DOCKER> 
[INFO] DOCKER> ---> 05c4ea19f56d
[INFO] DOCKER> Step 5/5 : CMD java -jar /app/dmp-sample-multi-assembly-0.35.0.jar
[INFO] DOCKER> 
[INFO] DOCKER> ---> Running in 2ea4994a3863
[INFO] DOCKER> Removing intermediate container 2ea4994a3863
[INFO] DOCKER> ---> f9b7fb8d7949
[INFO] DOCKER> Successfully built f9b7fb8d7949
[INFO] DOCKER> Successfully tagged fabric8/dmp-sample-multi-assembly:latest

Notice the Using cache messages for step 2 & 3 that tell me the docker cache is effectively used.

Then I modified the image configuration slightly and added the following declaration in the configuration:

...
<image>
    <name>${docker.user}/dmp-sample-multi-assembly</name>
    <external>
       <type>properties</type>
       <prefix>docker</prefix>
       <mode>skip</mode>
    </external>
...

Note that <mode> is set to skip which according to the documentation should be the same as not specifying any <external> at all (car. https://dmp.fabric8.io/#combining-property-config).

Executing mvn clean package with this new configuration gives:

[INFO] DOCKER> Step 1/5 : FROM fabric8/java-centos-openjdk8-jdk:1.5.6
[INFO] DOCKER> 
[INFO] DOCKER> ---> 34854f349ada
[INFO] DOCKER> Step 2/5 : EXPOSE 8080
[INFO] DOCKER> 
[INFO] DOCKER> ---> Running in 50aba02ca6f6
[INFO] DOCKER> Removing intermediate container 50aba02ca6f6
[INFO] DOCKER> ---> 3392cbee719f
[INFO] DOCKER> Step 3/5 : COPY deps /app/lib/
[INFO] DOCKER> 
[INFO] DOCKER> ---> 4ac1a3d57e81
[INFO] DOCKER> Step 4/5 : COPY maven /app/
[INFO] DOCKER> 
[INFO] DOCKER> ---> 134c5f2e1d8b
[INFO] DOCKER> Step 5/5 : CMD java -jar /app/dmp-sample-multi-assembly-0.35.0.jar
[INFO] DOCKER> 
[INFO] DOCKER> ---> Running in 660e1931ebb8
[INFO] DOCKER> Removing intermediate container 660e1931ebb8
[INFO] DOCKER> ---> add7db665841
[INFO] DOCKER> Successfully built add7db665841
[INFO] DOCKER> Successfully tagged fabric8/dmp-sample-multi-assembly:latest

Now the build seems to not be using the cache at all - no Using cache messages anymore.
In addition, I also noticed the build is now removing a layer (Removing intermediate container 50aba02ca6f6) at the end of Step2 which it didn't do with the orignal configuration without any declaration.

Of course the same happens with other than skip which I used here only for the sake of this test scenario.
I'm puzzled...


  • docker-maven-plugin version : 0.35.0
  • Maven version (mvn -v) :
Maven home: /opt/apache-maven-3.6.3
Java version: 1.8.0_281, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home/jre
Default locale: en_BE, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
  • Docker version :20.10.5
@brenuart
Copy link
Contributor Author

After some investigations it seems that the problem comes from https://github.com/fabric8io/docker-maven-plugin/blame/master/src/main/java/io/fabric8/maven/docker/config/handler/property/PropertyConfigHandler.java#L147

BuildImageConfiguration#getCacheFrom() is a List and not a String. It compiles correctly because the builder proposes two variants of the cacheFrom method: one accepting a collection of string (which is what is expected here) and another with a varargs of String (which is the one actual used here).

With the code as it is written at the moment we effectively get the same result as:

builder
  .cacheFrom("[[myimage:latest]]")

IMHO, we should rather write:

builder
   .cacheFrom(valueProvider.getList(CACHE_FROM, config == null ? null : config.getCacheFrom()))

@rohanKanojia
Copy link
Member

@brenuart : Thanks a lot for your investigation! Would it be possible for you to submit a PR?

@brenuart
Copy link
Contributor Author

Thanks for the merge! Closing the issue now.

@rohanKanojia
Copy link
Member

@brenuart : Thanks for reporting this and helping our with review ❤️ . Hopefully I'll release tomorrow and you'll be able to use it too :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants