R
Railway•13mo ago
Exerosis

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
Percy
Percy•13mo ago
Project ID: N/A
Exerosis
ExerosisOP•13mo ago
N/A
Brody
Brody•13mo ago
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
Exerosis
ExerosisOP•13mo ago
I seems like a single railway.json cannot do that is that correct?
Brody
Brody•13mo ago
railway.json is used to configure just a single service
Exerosis
ExerosisOP•13mo ago
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.
Brody
Brody•13mo ago
I can't think of any straight forward way to do that unfortunately
Exerosis
ExerosisOP•13mo ago
. how would you advise you setup multiple services for each app?
Brody
Brody•13mo ago
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
Exerosis
ExerosisOP•13mo ago
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.
Brody
Brody•13mo ago
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
Exerosis
ExerosisOP•13mo ago
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.
Brody
Brody•13mo ago
I don't sorry, I'm not really using different environments on Railway so my knowledge on that side of things isnt great
Exerosis
ExerosisOP•13mo ago
I see okay
Brody
Brody•13mo ago
i can help you setup the monorepo services though 🙂
Exerosis
ExerosisOP•13mo ago
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
Brody
Brody•13mo ago
sounds good, let me know if you need help with the monorepo stuff when you get to that!
Exerosis
ExerosisOP•13mo ago
@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.
Brody
Brody•13mo ago
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?
Exerosis
ExerosisOP•13mo ago
Well I was just wondering if there was a phase called when the image is terminated
Brody
Brody•13mo ago
the phases are for building the image, do you perhaps mean a webhook
Exerosis
ExerosisOP•13mo ago
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.
Brody
Brody•13mo ago
Exerosis
ExerosisOP•13mo ago
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?
Brody
Brody•13mo ago
well first
Exerosis
ExerosisOP•13mo ago
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)
Brody
Brody•13mo ago
I see, then I like your idea of running another railway service to handle these events
Exerosis
ExerosisOP•13mo ago
How would I avoid having the service duplicate itself for each enviroment?
Brody
Brody•13mo ago
wouldn't you want the service to duplicate itself so that it can handle the webhooks for each environment?
Exerosis
ExerosisOP•13mo ago
Ah okay maybe ha! I'll pla yaround thanks for pointing me in the right direction.
Brody
Brody•13mo ago
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
Exerosis
ExerosisOP•13mo ago
Ah intersting okay, do you have any examples of apps using the webhooks for various things?
Brody
Brody•13mo ago
I actually never used the webhooks for my own things and haven't seen anything public that uses them
Exerosis
ExerosisOP•13mo ago
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.
Brody
Brody•13mo ago
nope they are fired asynchronously
Exerosis
ExerosisOP•13mo ago
bummer okay
Want results from more Discord servers?
Add your server