Unable to deploy a Node application
Hi, I've been trying to deploy a simple Medusa.js app to Railway for quite some time. I wasn't successful. Another dev working with me unfortunately met the same fate. There's very little documentation on Railway, and none for mounts for using Dockerfile.
[Region: us-west1]
Cache mount ID is not prefixed with cache key
I'm an experienced developer. I usually host on AWS, but I wanted to try something new. What is cache mount id prefix? What's cache key?
Thank you
108 Replies
Project ID:
26dc4f5f-e728-4eb9-aaf6-126e6e687fed
26dc4f5f-e728-4eb9-aaf6-126e6e687fed
i take it you are deploying from a Dockerfile?
Yes
I also tried deploying using NIX but I don't have the skillset necessary
Also I'm sorry for my tone I'm just very tired
send your Dockerfile please
thank you for that, but please going forward try to keep a cool tone
Dockerfile for the app:
https://pastebin.com/rz8CuwBM
Pastebin
syntax=docker/dockerfile:1# Comments are provided throughout this...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
first off, where you able to deploy your app without any of the cache mount stuff?
I used https://docs.medusajs.com/create-medusa-app to create the project and
docker init
(Docker desktop) to create the Dockerfile template. I'm using PNPM. The project build locally, the container also builds locally from the Dockerfile. I can verify it runs fine outside of RailwayInstall Medusa with create-medusa-app | Medusa
Learn how to create a composable commerce platform using Medusa. This quickstart guide will help you set up your Medusa backend and the admin dashboard.
No it resulted in package.json missing despite being present
I would very much like to keep the cache mounts
But I can switch to just copying all the project files and try that. I tried modyfing the code and running it without the mounts, tried a couple variants. But I'm not a docker expert
Railway returns very concise error messages or doesn't return any at all. When I try just copying the files instead of cache mounts, it doesn't say anything just build failed
railway does not support the bind mount type, i know that its sometimes recommended to do that vs copying in the file, but the gains are negligible at best
I found a discussion saying that it does, that's what confused me the most
https://www.answeroverflow.com/m/1104400912149123152
Cache mount ID is not prefixed with cache key when deploying test i...
Hello all,
today I tried to boot up my test instance but every attempt at doing so lead the deploys to fail immediately with the error
Cache mount ID is not prefixed with cache key
(no further information are present in build logs).
The Dockerfile used to build the project is the following (as copied from GitHub https://github.com/Stickerifie...<1104400912149123152/1108081571665281085>
im sorry but im not seeing where its mentioned that the bind mount type is supported, im only seeing talk about the cache mount type
Alright. What is confusing me is that it only complains about Cache ID
When I remove cache mounts and keep bind mounts still says
Cache mount ID is not prefixed with cache key
bind mounts are not supported, lets get this dockerfile working without any mounts first please
one step at a time
instead of bind mounts, copy the file in with
COPY
COPY package.json pnpm-lock.yaml ./
Is it possible to run
railway up
using local code not the github repository? I have like 20 commits just for todayyep thats exactly what its for
I though so but it only seems to redeploy once I push the changes to the repository?
and just for a future question to get it out of the way, in your Dockerfile you have
<service-id>
but you are replacing that with your actual service id right?I may have possibly misconfigured the environments but still
Yes
I tried both in case railway had some magic regex replacement
railway up will deploy the code from your local project that you are running railway up from
they dont, though i have asked long ago for it
At least it should be in an environment variable
Or passed as an argument
there is a service id environment variable, but theres no way to dynamically replace it within the dockerfile
Oh okay, good to know though
Possibly NIX would be able to pass the value to the Dockerfile and then build it
thats what it does do
Why can't I use it then
${SERVICE_ID}
you arent using nixpacks, you are using a dockerfile
How does Railway build the dockerfile
buildx is what i think they use
oh okay
nixpacks is not involved when a dockerfile is used
Okay
Maybe they could release the config somewhere so I could test locally
For docker build
but nixpacks does generate an intermediary dockerfile with the correct cache id automatically
Oh okay that sounds interesting at least
but you said you didnt have any luck with nixpacks
I removed the bind mounts
did you remove all mount types?
Yes because I have no experience with it. Also Medusa is kind off specific
can you send your new dockerfile?
Okay so I was able to build including the cache mounts now
Updated Dockerfile
https://pastebin.com/KrAhE25e
Pastebin
syntax=docker/dockerfile:1# Comments are provided throughout this...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
some of your stages are missing a WORKDIR, but otherwise looks fine
Damn. I was using the Dockefile generated by
docker init
didn't bother to review those parts properly
Still the deploy failed
Build succeeded
Do you think you could help me with binding ports pleasei assume you are getting a 503 error?
My app runs on 9000 and the port is exposed. I am using a custom domain and I have it configured correctly
No because it failed right after it deployed
I've set up a health check, medusa has a health check on base-url/health
Here's the Railway config for reference
some of that isnt valid syntax
but please send the logs
Build and deploy logs here
https://pastebin.com/P5DyPb9r
Pastebin
[Region: us-west1]=========================Using Detected Dockerfil...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
can you please configure your app to listen on the
PORT
environment variable that is automatically generated by railwayNetworking config
Can I use that in the Dockerfile though?
So that I could EXPOSE it
there no need to
Okay I suppose it will expose it automatically?
quite a misleading name
EXPOSE
does nothing to expose the port, it is purely informativeOh okay then hm weird
The app should already use the env PORT variable
But it seems it falls back to 9000
maybe thats evacuated during build when no PORT env exists, you can just set a PORT service variable in that case
Wdym PORT service var?
Most probably yes
Yes but what value should I use. 9000?
yes
Deploying now
Still the same issue
Health check failed
is your app listening on 0.0.0.0?
No it's listening on the custom domain
It's using a config variable for that
it needs to listen on 0.0.0.0
Alright. I hope it won't complain
Is it possible to disable those automatic redeployments everytime I change the service variables
click cancel on the popup
Damn okay
Also the health checks are running too soon, before the app fully loads
But they have a timeout long enough
I will disable them for now
But I would like to somehow delay them
i dont see a point in delaying them, they will run for 5 minutes
okay
if a few checks fail before your app is live thats totally fine
I may have another issue
With CORS
I don't know how Railway proxies the traffic
To the container
I will set all CORS to * for now
But it is a security risk
railway sets the host header likey any proxy would
https://utilities.up.railway.app/raw
Host: utilities.up.railway.app
Okay I hope so
X-Forwarded-For present that's a good sign
I had configured nginx this way and it worked so it should work just fine now
yep, standard proxy stuff, nothing special
Also the app is running with
express
, thought I should mention that
Standard config nothing too specialdeploying
with 0.0.0.0
Still no luck damn
healthcheck is removed?
No
I will remove it now
medusa failed: No such file or directory
Originates from project config
medusa migrations run && npm run start:server
are you installing medusa?
I just need to add it to the path it is installed by pnpm
Or prefix it with pnpm
yeah whatever the equivalent to npx is for pnpm
Weird though because locally it worked, I probably don't need a start command at all
pnpx but that behaves weird
you may have it installed globally locally?
No only as a dev dep in the project
pnpm maybe does some unseen magic
this is the issue
When not using NIX I don't probably need a start command right?
This is probably why it fails before a health check is sucessfull even
the start command you set in your config file does overwrite the CMD in the dockerfile
oh okay weird though
simplified the start command
"start": "NODE_ENV=production && node dist/main.js",
pnpm start
should all work nowfamous last words
removed the health checks for now too
debugging is removing stuff until it's just a skeleton and then even that breaks
process of elimination works wonders, most of the time lol
"all that's left now is to push"
"I will just merge this PR and I'm done"
"wow this script will really set everything up for me and definitely not break anything"
"I just refactored a simple function"
those are all my last words
"let me just run this migration"
I removed the start command and somehow it came back?
oh okay
the redeploy used code from the repo
it seems to work now
I will test it
sounds good
Okay now it fails but Railway doesn't know that :D
I am unable to load the env variables inside the app
have you set the appropriate service variables?
Yes
I don't see a jwt service variable?
okay my bad
but the db didn't seem to load either
I need to review the config
what makes you think that? from my perspective it exited before any database related stuff happened
I have a Vercel integration and vercel has those vars
but it doesn't sync both ways probably
only to vercel
yeah it's only railway to vercel, not bidirectional
Is it possible to make the deployment fail if the app throws errors like this?
you would need it to exit with an error code of 1.
yes I see the logs that say it did, but if the status is complete then it did not exit with 1
Okay I will make it exit with 1
ON any errors
Alright it works now
Thank you very much for your time
no problem!
If you need help with Vue or TypeScript or SST, AWS feel free to reach out to me
and if you need help with railway, you know where to find me
oh and next time, don't wait 2 days!