设置Heroku环境变量而不重新启动应用程序

时间:2022-11-26 23:02:50

Is it possible to set a Heroku environment variable without restarting the app?

是否可以在不重新启动应用程序的情况下设置Heroku环境变量?

My app connects out to different online services via OAuth2. For each service I connect to, I need to set an OAuth2 ID and secret. To keep these configuration variables outside of my code, I'm using environment variables, and reading them in on process.env (node.js).

我的应用通过OAuth2连接到不同的在线服务。对于我连接的每个服务,我需要设置OAuth2 ID和密码。为了将这些配置变量保留在我的代码之外,我正在使用环境变量,并在process.env(node.js)中读取它们。

Each time I add a new service to my app, I need to add the corresponding environment variables for the ID and secret. I need to do this before pushing the latest code, so that when the app next starts up with the new service connection, the OAuth2 ID and secret variables are available.

每次我向我的应用添加新服务时,我都需要为ID和机密添加相应的环境变量。我需要在推送最新代码之前执行此操作,以便当应用程序下次启动新服务连接时,OAuth2 ID和秘密变量可用。

Currently my workflow is as follows:

目前我的工作流程如下:

  1. Set the environment variables using the Heroku toolbelt: heroku config:set <SERVICE>_ID=foo <SERVICE>_SECRET=bar
  2. 使用Heroku工具带设置环境变量:heroku config:set _ID = foo _SECRET = bar

  3. Push the latest code: git push heroku master
  4. 推送最新代码:git push heroku master

Currently, both of these operations will restart the app. I'd really prefer the first operation to not restart the app, as the changes to these config vars don't need to take effect until step 2). By restarting at step 1) my app will experience unnecessary downtime.

目前,这两个操作都将重新启动应用程序。我真的更喜欢第一个操作不重启应用程序,因为这些配置变量的更改不需要在步骤2)之前生效。通过在步骤1)重新启动,我的应用程序将遇到不必要的停机时间。

So, is there any way to prevent step 1) from restarting the app?

那么,有没有办法阻止步骤1)重新启动应用程序?

1 个解决方案

#1


7  

According to this article it pretty explicitly states that

根据这篇文章,它非常明确地指出了这一点

Whenever you set or remove a config var, your app will be restarted.

无论何时设置或删除config var,您的应用都将重新启动。

Personally I also wish there was a way to do what you're asking. On larger apps, a system-wide hard restart can be painful when you have many process types running. Many times I set environment variables that aren't crucial for the app to grab ahold of immediately, such as that involving future functionality, or settings that are OK having the old value but you want the new value to take effect in a rolling-restart fashion.

就个人而言,我也希望有办法做你所要求的。在较大的应用程序上,当您运行许多进程类型时,系统范围的硬重启可能会很痛苦。很多时候我设置的环境变量对应用程序来说并不是至关重要的,例如涉及未来功能的环境变量,或者具有旧值但是希望新值在滚动重启中生效的设置时尚。

#1


7  

According to this article it pretty explicitly states that

根据这篇文章,它非常明确地指出了这一点

Whenever you set or remove a config var, your app will be restarted.

无论何时设置或删除config var,您的应用都将重新启动。

Personally I also wish there was a way to do what you're asking. On larger apps, a system-wide hard restart can be painful when you have many process types running. Many times I set environment variables that aren't crucial for the app to grab ahold of immediately, such as that involving future functionality, or settings that are OK having the old value but you want the new value to take effect in a rolling-restart fashion.

就个人而言,我也希望有办法做你所要求的。在较大的应用程序上,当您运行许多进程类型时,系统范围的硬重启可能会很痛苦。很多时候我设置的环境变量对应用程序来说并不是至关重要的,例如涉及未来功能的环境变量,或者具有旧值但是希望新值在滚动重启中生效的设置时尚。