Can't use cache mounts on shared Dockerfiles

truffleclockPRO

6 months ago

Hi,

I'm trying to find a way to use cache mounts in a Dockerfile that is shared between several different services:

RUN --mount=type=cache,id=s/${RAILWAY_SERVICE_ID}-/root/cache/uv,target=/root/.cache/uv \
    --mount=... \
    --mount=... \
    uv sync --frozen --no-install-project

The documentation says that RAILWAY_SERVICE_ID is available at both build and deploy time. But it isn't working. I see other users reported this same issue in the past and the recommendation was to hardcode the service ID.

However, since I have multiple services using this same image, I don't think I can put the ID itself in the Dockerfile. We would also like to avoid provider specific params in our code base whenever possible, so it's not an ideal solution.

Is there any other workaround for this?

Awaiting User Response

1 Replies

6 months ago

Hello,

Unfortunately we need the service ID in there to keep cache isolated from one service to another, hopefully you can see why it could be bad for us to not have such restrictions.

A downside to that is the mount flag and its arguments don't support variable expansion, hence why it's always been recommended to hardcode the service ID.

But like you pointed out, hardcoding a service ID is of course a problem when you want to deploy to multiple different services.

Meaning the solution here, although not ideal, is to not use cache mounts at all.


Status changed to Awaiting User Response railway[bot] 7 months ago


Can't use cache mounts on shared Dockerfiles - Railway Help Station