PR environments workflow practices
artivilla
HOBBYOP

10 months ago

Trying to figure out the best workflow to use PR environments. I'd like to test each deployed PR works as expected with separate env vars and fake data, which can just be development data.

I'm assuming I need to clone all the services for my project into a dev env - frontend, backend and db schema - such that the settings can use it as base environment?

But then I need to keep the dev up to date? and added costs? What are best practices for a single dev who wants to just build locally, test locally, test PRs in isolation and then merge PRs to production?

Solved

6 Replies

echohack
EMPLOYEE

10 months ago

It's alot easier than that. You just have to enable PR Environments and they'll automatically spin up each time you make a PR against your default branch on GitHub.

These do incur additional costs, but you only pay for what you use on Railway. Likely you won't be serving public traffic on these so the costs should be minimal compared to your production environment.

You can read the docs here: https://docs.railway.com/guides/environments#enable-pr-environments


Status changed to Awaiting User Response Railway 10 months ago


Status changed to Solved echohack 10 months ago


echohack

It's alot easier than that. You just have to enable PR Environments and they'll automatically spin up each time you make a PR against your default branch on GitHub.These do incur additional costs, but you only pay for what you use on Railway. Likely you won't be serving public traffic on these so the costs should be minimal compared to your production environment.You can read the docs here: https://docs.railway.com/guides/environments#enable-pr-environments

michael88
PRO

10 months ago

How can we change the environment variables per PR?

Say we wanna spin up a new database (on Neon) and apply the new database URI in the railway current environment.

Similarly we'd like to be able to take down the database when the pr gets merged.

Is there a script we could apply somewhere?

Cheers!


Status changed to Awaiting Railway Response Railway 10 months ago


echohack
EMPLOYEE

10 months ago

For that you'd need to do something more complex like this: https://docs.railway.com/tutorials/github-pr-environment-actions

Right now PR Environments uses the Variables of your main environment.


Status changed to Awaiting User Response Railway 10 months ago


Status changed to Solved echohack 10 months ago


michael88
PRO

10 months ago

Perfect! Just what I needed. Sorry for asking before having read that page.

Thank you!


Status changed to Awaiting Railway Response Railway 10 months ago


echohack

It's alot easier than that. You just have to enable PR Environments and they'll automatically spin up each time you make a PR against your default branch on GitHub.These do incur additional costs, but you only pay for what you use on Railway. Likely you won't be serving public traffic on these so the costs should be minimal compared to your production environment.You can read the docs here: https://docs.railway.com/guides/environments#enable-pr-environments

artivilla
HOBBYOP

10 months ago

this is perf. maybe I read quickly and glossed over the by default it won't copy the prod data (phew). so it automatically creates a db using DATABASE_URL so its just a fresh db.

follow up - to run tests against seeded data, I should just create a a new env with seed data and just run tests against it in railway. part of the reason i wanted a hosted option is there is no teardown so if there are any issues with db migrations against this, it would be caught before production.

still going to do migrations manually but I'm a backend noob. would rather not play with fire.


echohack
EMPLOYEE

10 months ago

Sounds great! Glad you're enjoying riding the Railway with us.


Status changed to Awaiting User Response Railway 10 months ago


Status changed to Solved echohack 10 months ago


Loading...