4 days ago
My project has one service that auto-deploys from GitHub branch main in its production environment. I want a staging environment, created by duplicating production, that deploys only when I push to a separate branch, staging, and never otherwise.
- When I duplicate production, are the staging service's volumes new and empty, or copies of production's with its data?
- Is the duplicated service still connected to main? While its staged changes are unapproved, would a push to main deploy it?
- If I approve the staged changes, what does that first deploy build: the head of the connected branch, or the image production is running?
- When I change the staging service's source branch to staging, does that start a deployment immediately, wait as a staged change for approval, or wait for the next push to staging?
- Does changing the branch in staging leave production's branch and auto-deploy settings unchanged?
- Is there a way to create the staging environment and its service with nothing deploying until the first push to staging?
3 Replies
4 days ago
Each environment has its own branch setting for a service, so you can have staging deploy from staging and production from main. Branch and settings changes are scoped to the environment you make them in, so changing staging's branch leaves production's alone.
To create staging with nothing deploying, the public API's environmentCreate mutation accepts sourceEnvironmentId (to clone production's settings and variables), skipInitialDeploys (no deployments on creation) and stageInitialChanges (stage the changes instead of applying them). See Manage Environments with the API. In the dashboard, holding Alt while clicking Deploy on staged changes commits them without a redeploy (Staged Changes). So one way to get the setup you describe is: create the duplicate, change the staging service's branch to staging, then commit with Alt held. The first push to staging will then do the first build.
We haven't confirmed four things: whether a duplicated volume starts empty or with a copy of production's data, whether a push to main would deploy the duplicated service while its changes are still staged, what the first deploy builds when you apply staged changes normally, and whether a branch change alone starts a deploy once applied. Because the answers affect your data and deploys, try this in a throwaway environment before you rely on it.
Status changed to Awaiting User Response Railway • 4 days ago
4 days ago
Thanks. Could someone from the Railway team confirm the four points the assistant couldn't: (1) whether a duplicated environment's volume starts empty or with a copy of production's data, (2) whether a push to main deploys the duplicated service while its changes are still staged, (3) what the first deploy builds when staged changes are applied normally, and (4) whether a branch change alone starts a deploy once applied?
Status changed to Awaiting Railway Response Railway • 4 days ago
4 days ago
On the first point: duplicating an environment does not copy volume data. Each stateful service in the new environment gets a brand new, empty volume, and database credentials such as DATABASE_URL are generated fresh for that environment. Production's data stays in production. If you want that data in staging, you need to copy it over yourself, for example with a dump from production restored into the staging database.
We can't confirm the other three yet: whether a push to main deploys the duplicated service while its changes are still staged, whether a normal apply builds the branch head or reuses production's image, and whether applying a branch change alone starts a deploy.
You don't need those answers if you take the path from our earlier reply. Duplicate production, set the staging service's branch to staging before you apply anything, then hold Alt while clicking Deploy so the changes are committed without a redeploy. Once committed, staging is connected only to the staging branch, so the first push there does the first build. Because staging starts with empty volumes, you can try this flow safely and watch whether anything deploys before you push to staging.
Status changed to Awaiting User Response Railway • 4 days ago