R
Railway11mo ago
hexrw

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
Percy
Percy11mo ago
Project ID: 26dc4f5f-e728-4eb9-aaf6-126e6e687fed
hexrw
hexrwOP11mo ago
26dc4f5f-e728-4eb9-aaf6-126e6e687fed
Brody
Brody11mo ago
i take it you are deploying from a Dockerfile?
hexrw
hexrwOP11mo ago
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
Brody
Brody11mo ago
send your Dockerfile please thank you for that, but please going forward try to keep a cool tone
hexrw
hexrwOP11mo ago
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.
Brody
Brody11mo ago
first off, where you able to deploy your app without any of the cache mount stuff?
hexrw
hexrwOP11mo ago
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 Railway
Install 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.
hexrw
hexrwOP11mo ago
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
Brody
Brody11mo ago
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
hexrw
hexrwOP11mo ago
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...
hexrw
hexrwOP11mo ago
<1104400912149123152/1108081571665281085>
Brody
Brody11mo ago
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
hexrw
hexrwOP11mo ago
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
Brody
Brody11mo ago
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 ./
hexrw
hexrwOP11mo ago
Is it possible to run railway up using local code not the github repository? I have like 20 commits just for today
Brody
Brody11mo ago
yep thats exactly what its for
hexrw
hexrwOP11mo ago
I though so but it only seems to redeploy once I push the changes to the repository?
Brody
Brody11mo ago
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?
hexrw
hexrwOP11mo ago
I may have possibly misconfigured the environments but still Yes I tried both in case railway had some magic regex replacement
Brody
Brody11mo ago
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
hexrw
hexrwOP11mo ago
At least it should be in an environment variable Or passed as an argument
Brody
Brody11mo ago
there is a service id environment variable, but theres no way to dynamically replace it within the dockerfile
hexrw
hexrwOP11mo ago
Oh okay, good to know though Possibly NIX would be able to pass the value to the Dockerfile and then build it
Brody
Brody11mo ago
thats what it does do
hexrw
hexrwOP11mo ago
Why can't I use it then ${SERVICE_ID}
Brody
Brody11mo ago
you arent using nixpacks, you are using a dockerfile
hexrw
hexrwOP11mo ago
How does Railway build the dockerfile
Brody
Brody11mo ago
buildx is what i think they use
hexrw
hexrwOP11mo ago
oh okay
Brody
Brody11mo ago
nixpacks is not involved when a dockerfile is used
hexrw
hexrwOP11mo ago
Okay Maybe they could release the config somewhere so I could test locally For docker build
Brody
Brody11mo ago
but nixpacks does generate an intermediary dockerfile with the correct cache id automatically
hexrw
hexrwOP11mo ago
Oh okay that sounds interesting at least
Brody
Brody11mo ago
but you said you didnt have any luck with nixpacks
hexrw
hexrwOP11mo ago
I removed the bind mounts
Brody
Brody11mo ago
did you remove all mount types?
hexrw
hexrwOP11mo ago
Yes because I have no experience with it. Also Medusa is kind off specific
Brody
Brody11mo ago
can you send your new dockerfile?
hexrw
hexrwOP11mo ago
Okay so I was able to build including the cache mounts now
hexrw
hexrwOP11mo ago
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.
Brody
Brody11mo ago
some of your stages are missing a WORKDIR, but otherwise looks fine
hexrw
hexrwOP11mo ago
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 please
Brody
Brody11mo ago
i assume you are getting a 503 error?
hexrw
hexrwOP11mo ago
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
hexrw
hexrwOP11mo ago
I've set up a health check, medusa has a health check on base-url/health Here's the Railway config for reference
[build]
builder = "DOCKERFILE"
nixpacksPlan = {"repo":"webspen/lafat"}
watchPatterns = ["packages/medusa/**/*"]
dockerfilePath = "packages/medusa/Dockerfile"

[deploy]
region = "us-west1"
numReplicas = 1
startCommand = "medusa migrations run && npm run start:server"
healthcheckPath = "/health"
sleepApplication = false
restartPolicyType = "ALWAYS"
healthcheckTimeout = 10
[build]
builder = "DOCKERFILE"
nixpacksPlan = {"repo":"webspen/lafat"}
watchPatterns = ["packages/medusa/**/*"]
dockerfilePath = "packages/medusa/Dockerfile"

[deploy]
region = "us-west1"
numReplicas = 1
startCommand = "medusa migrations run && npm run start:server"
healthcheckPath = "/health"
sleepApplication = false
restartPolicyType = "ALWAYS"
healthcheckTimeout = 10
Brody
Brody11mo ago
some of that isnt valid syntax but please send the logs
hexrw
hexrwOP11mo ago
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.
Brody
Brody11mo ago
can you please configure your app to listen on the PORT environment variable that is automatically generated by railway
hexrw
hexrwOP11mo ago
Networking config Can I use that in the Dockerfile though? So that I could EXPOSE it
Brody
Brody11mo ago
there no need to
hexrw
hexrwOP11mo ago
Okay I suppose it will expose it automatically?
Brody
Brody11mo ago
quite a misleading name EXPOSE does nothing to expose the port, it is purely informative
hexrw
hexrwOP11mo ago
Oh okay then hm weird
const port = process.env.PORT ?? configModule.projectConfig.port ?? 9000
const port = process.env.PORT ?? configModule.projectConfig.port ?? 9000
The app should already use the env PORT variable But it seems it falls back to 9000
Brody
Brody11mo ago
maybe thats evacuated during build when no PORT env exists, you can just set a PORT service variable in that case
hexrw
hexrwOP11mo ago
Wdym PORT service var? Most probably yes
hexrw
hexrwOP11mo ago
Yes but what value should I use. 9000?
Brody
Brody11mo ago
yes
hexrw
hexrwOP11mo ago
Deploying now Still the same issue Health check failed
Brody
Brody11mo ago
is your app listening on 0.0.0.0?
hexrw
hexrwOP11mo ago
No it's listening on the custom domain It's using a config variable for that
Brody
Brody11mo ago
it needs to listen on 0.0.0.0
hexrw
hexrwOP11mo ago
Alright. I hope it won't complain Is it possible to disable those automatic redeployments everytime I change the service variables
Brody
Brody11mo ago
click cancel on the popup
hexrw
hexrwOP11mo ago
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
Brody
Brody11mo ago
i dont see a point in delaying them, they will run for 5 minutes
hexrw
hexrwOP11mo ago
okay
Brody
Brody11mo ago
if a few checks fail before your app is live thats totally fine
hexrw
hexrwOP11mo ago
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
Brody
Brody11mo ago
railway sets the host header likey any proxy would https://utilities.up.railway.app/raw
Host: utilities.up.railway.app
hexrw
hexrwOP11mo ago
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
Brody
Brody11mo ago
yep, standard proxy stuff, nothing special
hexrw
hexrwOP11mo ago
Also the app is running with express, thought I should mention that Standard config nothing too special
hexrw
hexrwOP11mo ago
deploying with 0.0.0.0 Still no luck damn
Publish time: 28.32 seconds
====================
Starting Healthcheck
Path: /health
Retry window: 10s

Attempt #1 failed with service unavailable. Continuing to retry for 9s
[FATAL tini (7)] exec medusa failed: No such file or directory
[FATAL tini (7)] exec medusa failed: No such file or directory
[FATAL tini (6)] exec medusa failed: No such file or directory
[FATAL tini (7)] exec medusa failed: No such file or directory
Attempt #2 failed with service unavailable. Continuing to retry for 8s
[FATAL tini (7)] exec medusa failed: No such file or directory
Attempt #3 failed with service unavailable. Continuing to retry for 3s

1/1 replicas never became healthy!
Healthcheck failed!
[FATAL tini (7)] exec medusa failed: No such file or directory
Build failed
Publish time: 28.32 seconds
====================
Starting Healthcheck
Path: /health
Retry window: 10s

Attempt #1 failed with service unavailable. Continuing to retry for 9s
[FATAL tini (7)] exec medusa failed: No such file or directory
[FATAL tini (7)] exec medusa failed: No such file or directory
[FATAL tini (6)] exec medusa failed: No such file or directory
[FATAL tini (7)] exec medusa failed: No such file or directory
Attempt #2 failed with service unavailable. Continuing to retry for 8s
[FATAL tini (7)] exec medusa failed: No such file or directory
Attempt #3 failed with service unavailable. Continuing to retry for 3s

1/1 replicas never became healthy!
Healthcheck failed!
[FATAL tini (7)] exec medusa failed: No such file or directory
Build failed
Brody
Brody11mo ago
healthcheck is removed?
hexrw
hexrwOP11mo ago
No I will remove it now
Brody
Brody11mo ago
medusa failed: No such file or directory
hexrw
hexrwOP11mo ago
Originates from project config medusa migrations run && npm run start:server
Brody
Brody11mo ago
are you installing medusa?
hexrw
hexrwOP11mo ago
I just need to add it to the path it is installed by pnpm Or prefix it with pnpm
Brody
Brody11mo ago
yeah whatever the equivalent to npx is for pnpm
hexrw
hexrwOP11mo ago
Weird though because locally it worked, I probably don't need a start command at all pnpx but that behaves weird
Brody
Brody11mo ago
you may have it installed globally locally?
hexrw
hexrwOP11mo ago
No only as a dev dep in the project pnpm maybe does some unseen magic
# Dockerfile
CMD pnpm start
# Dockerfile
CMD pnpm start
# Config
[deploy]
startCommand = ...
# Config
[deploy]
startCommand = ...
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
Brody
Brody11mo ago
the start command you set in your config file does overwrite the CMD in the dockerfile
hexrw
hexrwOP11mo ago
oh okay weird though simplified the start command "start": "NODE_ENV=production && node dist/main.js", pnpm start should all work now
Brody
Brody11mo ago
famous last words
hexrw
hexrwOP11mo ago
removed the health checks for now too debugging is removing stuff until it's just a skeleton and then even that breaks
Brody
Brody11mo ago
process of elimination works wonders, most of the time lol
hexrw
hexrwOP11mo ago
"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
Brody
Brody11mo ago
sounds good
hexrw
hexrwOP11mo ago
Okay now it fails but Railway doesn't know that :D I am unable to load the env variables inside the app
Brody
Brody11mo ago
have you set the appropriate service variables?
hexrw
hexrwOP11mo ago
Yes
Brody
Brody11mo ago
I don't see a jwt service variable?
hexrw
hexrwOP11mo ago
okay my bad but the db didn't seem to load either I need to review the config
Brody
Brody11mo ago
what makes you think that? from my perspective it exited before any database related stuff happened
hexrw
hexrwOP11mo ago
I have a Vercel integration and vercel has those vars but it doesn't sync both ways probably only to vercel
Brody
Brody11mo ago
yeah it's only railway to vercel, not bidirectional
hexrw
hexrwOP11mo ago
Is it possible to make the deployment fail if the app throws errors like this?
Brody
Brody11mo ago
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
hexrw
hexrwOP11mo ago
Okay I will make it exit with 1 ON any errors Alright it works now Thank you very much for your time
Brody
Brody11mo ago
no problem!
hexrw
hexrwOP11mo ago
If you need help with Vue or TypeScript or SST, AWS feel free to reach out to me
Brody
Brody11mo ago
and if you need help with railway, you know where to find me oh and next time, don't wait 2 days!
Want results from more Discord servers?
Add your server