Setup Vite + Flask App
The startup I recently began to work for is built on Heroku and both frontend and backend are hosted from single flask server. There is a dockerfile in the project but I don't want to use it right now, how can I control and view the build process? I have a procfile:
web: gunicorn app:app --timeout 90 --log-level=debug
worker: celery -A app.tasks worker --loglevel=INFO
But somehow I need to specify yarn install and poetry install etc. I just want to test out database branching and what not so I don't need anything to fancy to start with, but ideally I do want some build caching (part of why I dont' want to use docker right now).
12 Replies
Project ID:
N/A
railway will always use a Dockerfile is present, you would have to remove or rename it
but at a high level you will want a minimum of 3 railway services
a frontend service
a backend service
a celery service
and more services since you probably need database
I'm splitting the frontend and backend into separate services because it's not good practice to have your backend serve your frontend
once you separate the frontend and backend out in separate folder (isolated monorepo) railway should pick up that the frontend is using yarn and run the build and start scripts in your package.json automatically (though you will want to use an actual web server to serve the built vite app) and same for the backend it should pick up you are using poetry
RDS database right now, but I want to test branching so yeah I would certainly have a postgres service as well.
I agree on best practice but we aren't setup right now. I could use the vite dev server if it makes it easier to experment?
I still don't quite see how I define these services? is the correct way to do it via the web UI after selecting a repo?
personally I like to create an empty project, and then more empty services, get all my variables and service level configurations done, then add the repo last
Okay, so the configuration is generally done in railway not via some kind of file in the repo?
it would be super easy to split flask and vite into separate sub folder, and you could use the dev server for now yes, but I have a vite template you could reference to setup a proper web server for your vite app too
generally yes done through the UI, you can also use a railway.json file that the web UI generates for you
Ah okay I missed railway.json existance in docs, I'll look at that as well. Could you show me the template? I'm not really much of a web dev so my understanding of anything other the flask backend is pretty low (plus the project is a huge mess). Also is there a quick and easy way to import from RDS? Does railway automatically put the connection string for the ephemeral database instances into an env I can grab on the backend?
Lastly and probably least importantly, when having these database branches do you have any tips on working locally? Right now all developers, branches and heroku pull request environments use the same dev server (obviously this is causing huge problems and migrations are not possible with this system). I can see how I would give each PR a railway enviroment with it's own database (so migrations wouldn't be applied multiple times to the same dev db) but I don't really see how I do local testing cleanly.
Sorry for having so many questions 🙃
the template is here https://github.com/brody192/vite-react-template
it's for a react vite app but same concept applies.
as for databases and branching, railways databases don't do any branching, they are just plain databases docker images, no special sauce
What exactly happens then when an env is created? Does it copy the disk or create a totally blank db?
blank db
Ah okay I totally missunderstood in that case, so is the norm to run seed scripts when that's created? Is there an easy place to do that?
you could do it as a seed phase https://nixpacks.com/docs/guides/configuring-builds#new-phase