You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am wondering how to set 'cache-from' and 'cache-to' when using buildx to build multi-platform images.
I have a maven project in which several Docker images are being built and some of them depend on each other. Unfortunately, when a depending Docker image is being built, Docker tries to download the base Docker image (as defined by 'FROM' in the Dockerfile) instead of reusing the already built one. This obviously fails.
I have already tested if using 'dockerStateDir' helps, but it did not work either.
Because of this I would like to use the 'cache-from' and 'cache-to' option of buildx but do not know how to do this with the docker-maven-plugin (and if it is possible at all).
Does anybody have an idea how to solve this issue?
I'm not directly connected to the buildx implementation, but it sounds like a useful addition. @chonton maybe something that could be considered in the future ? Would this make sense ?
Maybe. The problem is that you get one export location per build - either the local filesystem or the registry. If we build the base image into the local filesystem, we can then build the dependent image and push that into registry. However, the base image will not be available in the registry. So you have to introduce another build that basically is a FROM base image and pushes to registry.
I wonder if a multi-stage build might work out. If the base stages are identical in the two dependents, then buildx is smart enough to use the cached layers. It is a build, but it is a fast build.
I also wonder if the problem is a side effect of how the build/push mojos are working. The build mojo builds the native image into the cache, not into the registry. The push mojo builds both native platform (fast build due to cache) and non-native platforms and pushes all platforms to the registry.
@owetterau Please comment on the docker cli commands you think would work for your use case.
Our builds already leverage layered Jars for our Spring Boot services, but lack of support for cache-from / cache-to causes our CI builds to always create full layers from scratch. As soon as we can use buildX caches, the layered Jars start bringing benefits of smaller images.
From what I can see, it should be straightforward to pass the config from Maven mojo into buildX command line arguments:
Yes, this PR is related. It provides existing configuration option into buildX --no-cache arg. My suggestion is to implement similar functionality for --cache-from and --cache-to args, adding new config to the plugin.
To me it sounds logical to include this configuration into buildX of image.build:
@owetterau : Sounds good to me (however, I would prefer these properties as maven mojo parameters rather than system properties), Shall I assign this issue to you?
Activity
rhuss commentedon Feb 14, 2023
I'm not directly connected to the buildx implementation, but it sounds like a useful addition. @chonton maybe something that could be considered in the future ? Would this make sense ?
chonton commentedon Feb 14, 2023
Maybe. The problem is that you get one export location per build - either the local filesystem or the registry. If we build the base image into the local filesystem, we can then build the dependent image and push that into registry. However, the base image will not be available in the registry. So you have to introduce another build that basically is a FROM base image and pushes to registry.
I wonder if a multi-stage build might work out. If the base stages are identical in the two dependents, then buildx is smart enough to use the cached layers. It is a build, but it is a fast build.
I also wonder if the problem is a side effect of how the build/push mojos are working. The build mojo builds the native image into the cache, not into the registry. The push mojo builds both native platform (fast build due to cache) and non-native platforms and pushes all platforms to the registry.
@owetterau Please comment on the docker cli commands you think would work for your use case.
orange-buffalo commentedon Nov 29, 2023
We would be interested in this feature.
Our builds already leverage layered Jars for our Spring Boot services, but lack of support for
cache-from/cache-tocauses our CI builds to always create full layers from scratch. As soon as we can use buildX caches, the layered Jars start bringing benefits of smaller images.From what I can see, it should be straightforward to pass the config from Maven mojo into buildX command line arguments:
docker-maven-plugin/src/main/java/io/fabric8/maven/docker/service/BuildXService.java
Lines 159 to 161 in 1b4dec5
Will maintainers accept the minimalist PR to pass the values through?
rohanKanojia commentedon Nov 29, 2023
@orange-buffalo : Do you think #1717 is related to this issue?
Do you propose to pass already existing property
cacheFromto buildx arguments? How would we configurecacheTo?orange-buffalo commentedon Nov 29, 2023
Yes, this PR is related. It provides existing configuration option into buildX
--no-cachearg. My suggestion is to implement similar functionality for--cache-fromand--cache-toargs, adding new config to the plugin.To me it sounds logical to include this configuration into
buildXofimage.build:And also add support to override them with system properties, like in the referenced PR:
docker-maven-plugin/src/main/java/io/fabric8/maven/docker/config/ConfigHelper.java
Lines 176 to 180 in 1b4dec5
rohanKanojia commentedon Nov 29, 2023
@owetterau : Sounds good to me (however, I would prefer these properties as maven mojo parameters rather than system properties), Shall I assign this issue to you?
orange-buffalo commentedon Nov 29, 2023
Sure, let's do that. I expect to provide a PR during the next week or two.
rohanKanojia commentedon Nov 29, 2023
@orange-buffalo : Thanks a lot!
feat: Adding support for `--cacheFrom` and `--cacheTo` buildX arguments
feat: Adding support for `--cacheFrom` and `--cacheTo` buildX arguments
ggjulio commentedon Sep 20, 2024
Having two
cacheFromis a common pattern but currently not supported by the plugin.I opened an issue #1822