Welcome @carleton,
The problem here is a confusion that we often see arising and something we plan on addressing. Because your render.yaml
contains both your prod and staging services, when you push to prod we redeploy the entire blueprint and because you have a staging service listed it gets deployed as well.
You want to split your blueprint so it represents a single environment and then you have a blueprint deploy for your master branch (ie production env) and one for staging. Each of these blueprints would deploy its own set of services.
Pull requests would be made to your staging branch and then the preview environment would be triggered and when you merge staging into master that would trigger a deployment to production. NOTE: Something to watch out for is that Github defaults Pull requests against the default branch (typically master/main) so unless you change the default branch to staging you have to remember to change each PR to be against staging. I’ve seen customers doing things similar to this, in fact, one took master as ‘staging’ and then maintained a ‘prod’ branch.
When you create a new blueprint deployment for the master branch we’d create the services but then when you create the blueprint deployment for staging we’d detect the resources exist and this is where you’d pick ‘create new resources’ as opposed to ‘update existing resources’. We’d then create a NEW set of services suffixed with a random string. If this isn’t obvious enough when you see the service listed in the dashboard you can always create a new team, specifically for your staging environment and then deploy the blueprint there, because it’s an empty team the resources would be created without the suffix in the name but the service URLs would have a suffix appended.
However…
Because you want your staging environment to be NODE_ENV=staging you’re going to have to follow something like this…First up, setting NODE_ENV in your render.yaml with:
- key: NODE_ENV
sync:false
This will let you set it to staging
for your staging env in the dashboard - we default it to production so you wouldn’t need to explicitly set that one.
For your preview environments (we don’t provide a way to copy these vars into them at the moment) so you’re going to have to tweak the build and start commands to set the vars you need - changing these to be a script (that eventually runs the same command as already defined in your buildCommand and startCommand for your services) but before that in each have:
# /bin/render-build.sh
if [[ -z "${NODE_ENV:-}" ]]; then
if [[ "${IS_PULL_REQUEST:-}" == "true" ]]; then
export NODE_ENV=staging
else
echo "NODE_ENV not set"
exit 1
fi
fi
# Build command here
This will set NODE_ENV=staging if it’s not set and it’s being executed via a preview environment. The downside to this is that it won’t show in the dashboard as an environment variable, nor would it be set for the shell tab either.
I think this will achieve what you’re after here, let me know if you have any questions.