ARG RAILWAY_SERVICE_ID in Dockerfile
pabloreyes
HOBBYOP

a year ago

Hi,

I have a single Dockerfile that I use in two different services, so to properly set the service_id in the cache mount (https://docs.railway.com/guides/dockerfiles#cache-mounts) , I went with the build time variables ARG RAILWAY_SERVICE_ID (https://docs.railway.com/guides/dockerfiles#using-variables-at-build-time).

That didn't work and I found that the $RAILWAY_SERVICE_ID variable cannot be used (https://station.railway.com/questions/is-the-cache-id-with-the-id-of-the-servi-a28aae85, https://station.railway.com/questions/docker-build-cache-issue-b2b13274) in the Dockerfile (some sort of exception I guess? Should be stated on the docs).

So, apart from hardcoding it (which I can't since I have 2 services using the same Dockerfile with different commands), what would be the best way to do it? Since apparently I can use user-defined-variables, couldn't I declare a variable USER_SERVICE_ID in each of the services with the value of $RAILWAY_SERVICE_ID and use $USER_SERVICE_ID in my Dockerfile? Sounds like a way to overcome that restriction, although I do not know the implications.

Thanks!

Solved

2 Replies

I am a little confused, is this just for caching?

We do that automatically on the Railway builder side.


Status changed to Awaiting User Response Railway 12 months ago


angelo-railway

I am a little confused, is this just for caching?We do that automatically on the Railway builder side.

pabloreyes
HOBBYOP

a year ago

Well, I thought since the code between the two process is mostly shared, I could reuse the same Dockerfile and just pass different CMD. I have change it to just use two different dockerfiles, so it works fine now.


Status changed to Awaiting Railway Response Railway 12 months ago


Status changed to Solved jake 12 months ago


Loading...