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