Monorepo? Docker compose?
What is the best "config by code" approach for a monorepo or am I better off splitting up my project? I'm really far from a devop so I'm not sure what the best way to go about any of this is. I've got a flask backend and a vite frontend (currently flask hosts the vite dist as static files), using aws RDS for database and heroku cloud ampq. Using heroku PR environments as well.
The goal is to setup database branching(maybe neon.tech or postgres.io) (at least get this working for PR env, prod and dev although ideally find a solution for testing migrations and working locally as well, no idea how that normally works) and properly integrate alembic migrations and move to a faster cheaper better host (railway).
What is the best starting point? Should I be aiming for a monorepo and docker-compose (would that be faster or slower to build than nixpacks and what not)? or can I use the railway.toml to define multiple services (not clear to me), how can I hookup database branching with railway PR environments? Or should I plan to go for seeding/copying with obfuscation instead? How can I make local development and quick testing of migrations possible?
Thank you!
36 Replies
Project ID:
N/A
N/A
I still don't know how to do anything related to database branching, so I can't answer that side of the question unfortunately.
as for the monorepo question, railway does not support docker-compose or infrastructure as code yet, you would manually have to setup an individual railway service for each app in your mono repo
I seems like a single railway.json cannot do that is that correct?
railway.json is used to configure just a single service
For branching I really just need like a place that a script can be run when an env is created and when one is destroyed. That has the ability to set envs I guess, but I couldn't quite figure out how that would work.
I can't think of any straight forward way to do that unfortunately
. how would you advise you setup multiple services for each app?
create multiple railway services within the same project, and then set the root directory service setting accordingly in each service, each service would deploy from the same repo
Ah I see okay, and generlaly peaking are build times faster using the nixpacks? My understanding is that there is build caching when using them that likely wouldn't be present with a single dockerfile.
they likely wouldn't be too dissimilar for medium sized projects, there is still layer caching after all, but my recommendation for nixpacks vs. dockerfile is don't use a Dockerfile unless you have a specific reason to
Okay sounds good, do you know of anyone using railway PR envs with a migration tool? I'm not sure how it's possible without db branching/copying.
I don't sorry, I'm not really using different environments on Railway so my knowledge on that side of things isnt great
I see okay
i can help you setup the monorepo services though 🙂
Okay, going to do a bit more research first. Don't want to spend too much time without solving migrations since that's the primary driving force behind the move form heroku. Might be best to just get a dedi and build a nest of scripts lol
sounds good, let me know if you need help with the monorepo stuff when you get to that!
@Brody Hey do you know if there is a list of nixpack phases that railway calls?
I think somewhere you mentioned there might be a seeding phase.
entirely dependent on what language it's using, you can see the phases in the build table at the top of the build
can you tell me the usecase though?
Well I was just wondering if there was a phase called when the image is terminated
the phases are for building the image, do you perhaps mean a webhook
Oh well that would actually work too, I was just looking at heroku and they have a "cleanup" phase in their procfile which seemed excellent.
https://discord.com/channels/713503345364697088/1171917067486773288/1171921000233963560
what would you want to run in this cleanup phase?
Ah wow, okay maybe I can use these! How do you recommend I interact with them? Should I run a seperate railway service that listens to webhooks and runs scripts/makes calls to railway api? Or would it be best to host that on another server?
well first
I was thikning during build phase I would clone/branch/seed a database.
Then on cleanup I would remove that fork (assuming it isn't running within railway)
I see, then I like your idea of running another railway service to handle these events
How would I avoid having the service duplicate itself for each enviroment?
wouldn't you want the service to duplicate itself so that it can handle the webhooks for each environment?
Ah okay maybe ha!
I'll pla yaround thanks for pointing me in the right direction.
I'd use webhook.site to first see what the webhooks payloads actually contains, hint, they contain way more information than that example json does
Ah intersting okay, do you have any examples of apps using the webhooks for various things?
I actually never used the webhooks for my own things and haven't seen anything public that uses them
Ah okay sounds good, do you happen to know if the webhooks block the build process?
For example if the database needs time to start and provide a database string can I call to set the service enviroment variables and be sure they are set bfeore the app starts up.
nope they are fired asynchronously
bummer okay