Can't use cache mounts on shared Dockerfiles

truffleclock
PRO

a year 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?

Solved

1 Replies

a year 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 11 months ago


Railway
BOT

a month ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway about 1 month ago