Mount host directory as cache during docker build (buildkit)

235 views Asked by At

Build Kit has given us a range of new options for mounts during build. However I'm struggling to workout the correct way (if it's even possible) to mount a host directory as cache during a build step.

Essentially I have a dockerfile like:

FROM node:18

WORKDIR /app
ADD package.json yarn.lock .
RUN YARN_CACHE_FOLDER=/tmp/yarn yarn --frozen-lockfile
...

And I'd like to mount my local yarn cache at /tmp/yarn

Note: this is in a CI environment

Is there some variation of buildx options that supports this?

(I've tried a range of things, but can't seem to land on the right one. I'm currently tempted to find a way to ADD the cache since it's actually a multi-stage build and it won't impact the final image, but then I have to get the cache into the build context which is ugly)

0

There are 0 answers