deploy react+fastapi+postgresql+celery on railway
Hi, I have a github repo composed of fastapi as backend, and react as the frontend, and the postgreSQL as DB, all of them are dockerized, all of the dockers are configured to be running on local machine perfectly. now I am trying to deploy the full stack on railway, but I did not find much information to guide me through. my friend recommended me to railway instead of aws, it supposed to be straightforward to deploy such a typical stack. I am confused, am I misunderstood the way how railway is supposed to be used.
53 Replies
Project ID:
N/A
as simple as railway can be there is always going to be a learning curve, and that's what me and the rest of the community are here for!
I would love to help and you gave a decent bit of information, but for me to help you to the best of my abilities I would need to see exactly what you are working with, so please share your repo.
hi thx for the reply. the repo is here https://github.com/tianerphil/full-stack-fastapi-template.git
GitHub
GitHub - tianerphil/full-stack-fastapi-template: Full stack, modern...
Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more. - tianerphil/full-stack-fastapi-template
it is a just a test repo, doing nothing, just to try the deployment process of this type of stack.
I have tried to use railway cli to deploy to railway project id is 7c880d15-5696-4b26-8e79-fa845c36b0b5 but encounter some error, seems like I need to do some customization to the dockerfiles.
so just to make things clear, railway does not support docker compose
just wanna get that out of the way before we jump into this
can you show me a screenshot of your railway project?
hi, sorry I was offline earlier. the screenshot is here, it does nothing but a empty fastapi framework, with simple postgresql db holding the book information.
this is the screenshot running local dockers.
and this one is the one I tried to deploy to railway. I have installed railway cli, and used railway init, and railway up
just for your information if it may matter in some way, the final deployment will be a image generation service, I will deploy fastapi backend and react frontend here in railway, the backend will fetch the generation from runpod gpu serverless, store the metadata in postgresql hosted here in railway, all the tasks will be managed by redis and celery which will also host here in railway.
does that make any sense to you from the railway point of view?
yes
your docker compose file states you are using postgres 12, does it need to be an older version? would postgres 16 work?
sorry for the late reply, I was asleep
haha, I do not have a strict version requirement on the postgresql. at this very initial stage I'd rather to grab some main idea about the deployment process, and the spacific customization needed to ship the local docker orchestration to the railway platform. any guide or blog available? thx.
no worry at all, sleepping is good hobby haha
there is no good way to deploy a docker compose file to railway, you need to manually reconstruct services in your railway project, id be happy to try my best to walk you though it
ok thanks, how can we start?
deploy postgres into your project from the create button on your project canvas
deployed
please send a screenshot of your project canvas every time you make a change just so that i can follow along and make sure things are going smoothly
did you delete the fastapi service? where did it go?
I created a new, should I delete the previous project?
yeah delete the old project, we want everything inside of one project
deleted
open that project and change the project name to something more suitable
done
please remeber the screenshots
okay create a new empty service, name it properly as the backend, and configure any service variables it will need
yes, I am doing. do we have to create empty service and configure all the stuff again, or can we create a docker image and pull my configured docker image for the backend and frontend
is that more straightforward
pull from where?
docker hub
is it a public image?
I can set it to public
then yes, you can have the service pull the public image, but you still need to set service variables
so please go ahead and do this
it is a little bit late here, I cannot stay long as tomorrow need to drive 300km. do you have some blog or instruction for similar deployment that I can follow. I am brand new, do not want to keep you long.
damn thats a long drive, but no theres no blog or guide, i am the guide 🙂
so please dont worry about keeping me long, if i wasnt willing to help i wouldnt be helping you lol
thank you you are really generous. I will not be able to finish all today. let me do some homework before I ping you for your guidance again tomorrow. in general, can I understand the process like this: I have 5 dockers, db, frontend, backend, and adminer, and the traefic dockers. I can create docker image in railway one by one and pull the configured docker from docker hub respectively. configure the env variables required. and then do some railway specific setting about the reverse proxy and domain setup. is that so?
basically yes, but treafik is not going to work on railway, there is no way to do labels
ok, so there will be some railway specific reverse proxy service setup.
not really, you will have to redo the proxy with something better, like caddy
ok. sounds like you bring me out of comfort zone
but maybe you wont even need any reverse proxy, can you tell me why you had one to begin with?
I mean as a edge router, accepting the main request load, load balancer, ssl termination, internal service routing, middleware setup somthing like that.
no special
so at this point you understand that you will need a railway service for the frontend (react) and another service for the backend (fastapi), correct?
yes
is railway designed for frontend deployment or should I only put backend here and deploy frontend somewhere else
you have designed your own deployment, you use nginx to serve the frontend, so you are good to go
are you aware that railway handles ssl for you?
so solely nginx is enough for serving the frontend, no need traefic any more?
correct
on the frontend railway service you would set domain.com and on the backend service you would set api.domain.com and have your frontend simply make requests to the api.domain.com domain
ok, sounds like straightforward.
feel free to ping when you have more time to jump back into this
I feel railway is designed primarily for backend, is that true. should I put frontend to some where else?
railway is what you make of it, your frontend service uses nginx so serve the static files so you are set to deploy a frontend on railway without issues
ok, got it. thx. good night / good day. appreciate your kindly help
you too!