gpt4 book ai didi

environment-variables - dotenv 是否与十二要素 App 相矛盾?

转载 作者:搜寻专家 更新时间:2023-10-31 22:47:06 26 4
gpt4 key购买 nike

我已经阅读了 Twelve Factor App's Config - Section III并在 NodeJS 中寻找一种方法。貌似大多数人推荐dotenv将配置存储在环境变量中。

但是,dotenv 似乎与十二因素应用程序相矛盾,如下所述:

Another approach to config is the use of config files which are not checked into revision control, such as config/database.yml in Rails. This is a huge improvement over using constants which are checked into the code repo, but still has weaknesses: it’s easy to mistakenly check in a config file to the repo; there is a tendency for config files to be scattered about in different places and different formats, making it hard to see and manage all the config in one place. Further, these formats tend to be language- or framework-specific.

The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard.

理解这个语句,似乎使用 dotenv,您将创建一个配置文件 .env,然后将它们导出为环境变量。

这不会违反十二要素应用程序,因为 .env 文件可能会被意外 checkin 代码库吗?

最佳答案

12factor 在有人真正提交并推送 .env 之前不会被违反 ;)

.env 文件也可以存储在 repo 本身之外,因为库或应用程序仍然需要读取 .env 文件并将变量推送到环境。根据您的实现,这可以像将路径从 ".env" 更改为 "../.env" 一样简单。

使用 .env 文件是一个很好的折衷方案,允许开发人员轻松管理环境,但在部署期间仍与更好的环境实践兼容。我可能有 30-40 个 12factor-flavored 应用程序在虚拟机中运行,如果没有像 .env 这样的“垫片”,必须单独管理每个环境是令人生畏的。

关于environment-variables - dotenv 是否与十二要素 App 相矛盾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43444781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com