This message was deleted.
# community-support
s
This message was deleted.
r
Context - I'd like to benefit from docker layer caching for the shared caches. There's a trick you can do to get layer caching for the shared caches by copying across all the
*.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-L44
However, in order to benefit from the build cache when building locally you need to use the new
RUN --mount=type=cache,target=<cache_dir>
directive. If you point that at
~/.gradle/caches
then you lose all the layer caching.
r
Won't that just move where the
caches
dir is?
e
does that not accomplish what you want?
r
does 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.
v
Use symlinks?
r
My imagination is failing me as to how unfortunately. Not for the first time I feel like I'd really like to get a Gradle expert & a Docker expert in the same room to thrash out the best way to write a multi-stage Dockerfile that builds a Gradle project efficiently both locally and on GitHub Actions or similar. I must have spent weeks wrestling with this over the last couple of years.
v
My 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