Unable to deploy turborepo + astro + payload + pnpm monorepo
Thanks in
I've been able to get as far as building the application, but I'm not able to deploy it.
stack is:
- turborepo
- pnpm workspaces
- payloadcms
- astro
- mongodb atlas
When using
nixpacks build . --name my-project
locally it builds, however I am unable to start the application using docker run -it my-project
as my apps don't seem to pick up the variables from the .env
file.
Moreover, when the project deploys to Railway, the project builds ok, but when it comes to serving the applications, astro defaults to serving at localhost. here is the problem line from the deploy logs: @project/web:start: 01:19:21 AM [@astrojs/node] Server listening on http://127.0.0.1:3001
- but I've set PUBLIC_URL to https://my-project-production.up.railway.app
in the railway variables.
Here are my relevant files to help understand where I'm going wrong:61 Replies
Project ID:
5c47585a-3af2-4850-9344-92e188bd6eea
5c47585a-3af2-4850-9344-92e188bd6eea
here is my
./turborepo.json
:
./package.json
./apps/web/astro.config.ts
deployment log:
does
turbo start
start everything?I think the key things im doing wrong are how I access environment variables in development and in railway. hence the nixpacks build not giving me the ability to serve locally (or on railway)
locally yes:
pnpm turbo start
how many services are in this repo?
at the moment just two:
- payloadcms (./apps/api) utillising mongodb atlas via connections string in ENV
- astro as nodejs standalone+hybrid mode
payload is called api and web is the astro app?
yes
- api (payload)
- web (astro)
api because im using payload in localapi mode in my astro application
project structure:
I actually used your payload template as a reference for the payload app (replaced dotenv with cross-env)
okay, two services, so that means you need two railway services
- each of these services will deploy from the same github repo
- in one of the services settings youd set the build command to
pnpm run build:api
and the start command to pnpm run start:api
this will be the payload service, so name the railway service appropriately
- in the other service youd set a build command to pnpm run build:web
and a start command to pnpm run start:web
this is the web service, so name that appropriately too
- as for astro listening on 127.0.0.1
instead of 0.0.0.0
like it needs to, you can server.host
to 0.0.0.0
in your astro config file, like so https://github.com/brody192/astrowind-template/blob/main/astro.config.mjs#L38-L40ok, maybe I misunderstood how to do that part in the docs https://docs.railway.app/deploy/monorepo#shared-monorepo
I'll give that a go now
yeah you need two services since these is no way to expose two apps with only one railway service
I thought that may be the case. I was hoping otherwise, but it makes sense
well if you want all access to come and go though one service that can be arranged, but that requires two services for your apps and then a proxy service
like so https://railway.app/project/35d8d571-4313-4049-9699-4e7db7f02a2f
I have a template for that too, but let's get your services running first
happy to send you a coffee when done
awh thank you 🙂
ok, some progress.
payload built successfully, and deployed, but I think I may need to add railway IP's to mongodb atlas.
when navigating to my app, I get a blank white page
seems I already have
0.0.0.0/0
(allow from anywhere). At this point it seems like I should also just provision a mongodb in railway.railway deployments have dynamic ips, so you cant whitelist any single one, you would need to whilelist all the cidr ranges for the region, heres them all for railways default region https://utilities.up.railway.app/cidr-list?value=us-west1
0.0.0.0/0 works too
do you get any errors in the payload's deployment logs?
no, I think I may have been hasty, I can hit the /admin endpoint, but it's complaining
fetching user failed: failed to fetch
which would mean it cant get the mongodo a quick test and disable private networking
no joy
can you send the logs? https://bookmarklets.up.railway.app/log-downloader/
build logs
hmmm not much going on here, can i see a screenshot of your service variables?
I've set
PORT
to the same port as PAYLOAD_PORT
assuming railway needs to expose it and not pick up the latterpayload should listen on the auto assigned PORT, its must since i didnt define a PORT in my template, but you are getting a white screen so railway can access your app so thats good
and your code is setup to read from the environment, and not just variables loaded from a .env file?
you have the payload public server url set to your railway domain right?
I'm able to hit payload and see a loading gif, so the app is running.
apart from package.json which is virtually a clone of your own from the template,
I load ENV's like this:
./apps/api/src/server.ts
Nothing in the app is referencing .env
everything assumes its reading from processbut admin is still white?
can you send me the link?
but not white, so progress!!
let me know when you have it
what do you have set for the payload url?
the same link, but just
http
as opposed to https
you want https
railway is https only
ok
set it to this
https://${{RAILWAY_PUBLIC_DOMAIN}}
this will render out to the domain of the service so if you ever changed the domain or add a custom domain you wouldnt have to change the environment variable manually and youd only have to redepleoy the service for the new variable to take effectwoop woop!!
that did the trick
where can I send you that coffee?
if you insist, theres a link in my bio, you dont have to though
I spent a week smashing my head trying to deploy on vercel, no one responded in community forums. came here and within a couple of hours you've helped me out.
more than happy to oblige. you've really helped me out
thank you
done. coffee fund topped up 🙌🏾
thank you so much 🙂
we still got that astro app to tackle though!
its 4:43am here, (GMT+0)
fading slowly!
no worries, we can pick this back up another time! (im EST)
the truth is I haven't even started to build the astro frontend yet, I have been going in circles just trying to get this up and running
yeah best to just tackle one service/app at a time
but, I have a /health endpoint, so if I can hit that, then I can try figure out the localapi stuff after
I've set it all up in railway, how can I trigger a redeployment? I cancelled the first
would also be a good idea to have railway hit the healthcheck too! https://docs.railway.app/deploy/healthchecks
yep, set that up
you can give this a shot https://bookmarklets.up.railway.app/service-redeploy/ but due to limitations with railways api it doesnt always work as intended, otherwise just disable the git deploy trigger in the settings and then connect enviroment to branch
i have been begging railway to slap in a "deploy now" button for a long time
I could do this and push to my repo:
oh yeah that works too
forgot about that trick
I always forget, had to turn it into a gist https://gist.github.com/Demwunz/6be3f3929fc56ad84404970310c51347
this shuold be pinned
that is usefull
I'll be writing all the above up into a tutorial and sticking it online soon.
It's the only way I'll remember how to do it again
thats a pretty smart way of doing things!
ok, astro deployed, I got a response back from /health. I'll build out some pages tomorrow.
The next thing will be trying to connect to payload via localapi (https://payloadcms.com/docs/local-api/overview), but thats a different issue to tackle.
Thanks again @Brody you've been amazing.
no problem! happy to help!