Environment variable to identify the server after a deploy happens

We scaled up our resources to have our server run 3 instances. Previously we had a script that would run when the app starts up - it worked okay for 1 instance but is now running 3 times (one on each service). Ideally we only run the script once after a deploy (it’s mostly idempotent but does have some interesting race conditions if run multiple times concurrently).

Couple things we were considering:

  1. Using a post deploy webhook where render tells us it is done deploying, then we run the script. Last I checked, this was not available yet
  2. Use some crude numbering system environment variable where we could denote that only a specific index or instance should run the script on startup. To do this, we would need an environment variable set per instance (we were thinking of a simple 0, 1, 2 index)

Are either of these possible? If not, do you have any other suggestions to handle the horizontal nature of multiple instances. We’re looking for a quick solution to this while we work on a more scalable solution that doesn’t involve running this script on app startup

We don’t have a post-deploy hook or environment variable indexes as of today. I’ll investigate some potential workarounds for you. But first to start with a potentially naive question: Is this something that can be done during the build process rather than the deploy process? That would ensure it’s only run once per deployment.

I think we tried something with this a while back but there were issues with needing to expose a bunch of the environment variables in our docker build process…this was a while back now so might be worth another look.

We can take a look to see if this is possible - let us know if you think of anything on the render side that could help with this. This isn’t super high priority for us, just something I wanted to ask if there was any other workaround that could fix the issue for us. Thanks for the help!