Slackbot
04/27/2022, 8:34 AMRobert Elliot
04/27/2022, 8:41 AM*.gradle etc files in one COPY which prevents the layer cache being invalidated unless you change one of those files:
https://github.com/Mahoney/lidalia-shell/blob/8a1f16960ff303512d02ecc3f2caeb35ed99fae0/Dockerfile#L42-L44Robert Elliot
04/27/2022, 8:44 AMRUN --mount=type=cache,target=<cache_dir> directive. If you point that at ~/.gradle/caches then you lose all the layer caching.ephemient
04/27/2022, 8:46 AMRobert Elliot
04/27/2022, 8:47 AMcaches dir is?ephemient
04/27/2022, 8:48 AMephemient
04/27/2022, 8:49 AMRobert Elliot
04/27/2022, 8:59 AMdoes that not accomplish what you want?No, I don't think it does. I'm building a multi-stage Dockerfile, so I can't mount a directory, I can only benefit from layer caching of the
/root/.gradle/caches/modules-2 directory.
I want to use the RUN --mount=type=cache,target=<cache_dir> directive so that repeat local docker build . calls benefit from build caching, which I think means that <cache_dir> has to be /root/.gradle/caches (if running FROM a container using the root user).
That blows away any layer cache inside /root/.gradle/caches/modules-2.
I might be able to benefit by running RUN --mount=type=cache,target=/root/.gradle/caches/7.4.2 but having to duplicate the gradle version in that path is just obviously going to be a maintenance fail.Vampire
04/27/2022, 9:00 AMRobert Elliot
04/27/2022, 10:54 AMVampire
04/27/2022, 12:10 PMMy imagination is failing me as to how unfortunately.Make a directory that you configure for that caching thing. Move the files / directories to be cached in there. Symlink the moved files / directories to the original places within Gradle user home