I was reading from this article that you can create a config/local_env.yml
with environment variables and then use config/application.rb
to read it to replace/take priority before the environment variables that you export in your .bashrc
. What then is the .env
used for then? Does it serve the same purpose as the config/local_env.yml
?
我正在读这篇文章,您可以使用环境变量创建config / local_env.yml,然后使用config / application.rb读取它以替换/获取您在.bashrc中导出的环境变量之前的优先级。那么.env用于什么呢?它是否与config / local_env.yml具有相同的用途?
1 个解决方案
#1
1
All of these methods are used to feed environment variables to your rails application. So, from an app's point of view, it serves the same purpose whether you export it from .env
or .bashrc
or config/local_env.yml
files.
所有这些方法都用于将环境变量提供给rails应用程序。因此,从应用程序的角度来看,无论是从.env还是.bashrc或config / local_env.yml文件导出它,它都有相同的用途。
The differences in these methods are really a matter of personal choice among the team members involved in maintaining the app's development and deployment environments. However, here are few things to consider while opting for either of these choices.
这些方法的差异实际上是参与维护应用程序开发和部署环境的团队成员的个人选择问题。但是,在选择其中任何一种选择时,需要考虑以下几点。
.bashrc
- Use this if you manually configure deployment servers and really comfortable with linux/unix command line system administration. This configuration file is specific to bash shell (Bourne Again Shell). You need to configure different file if your server uses different shell (for example: .zshrc
if it uses Z Shell)
.bashrc - 如果您手动配置部署服务器并且非常熟悉linux / unix命令行系统管理,请使用此选项。此配置文件特定于bash shell(Bourne Again Shell)。如果服务器使用不同的shell,则需要配置不同的文件(例如:如果使用Z Shell,则为.zshrc)
.env
- Use this if you want to keep your app centric environment variables within the app itself while maintaining different variations of environment variables for different runtime environments of your rails app. For example: .env.development
and .env.test
files with specific values of the environment variables for your development and test environments respectively. This gives you more control of your app's environment variables and do not have to rely on the platform (terminal shell) you want to deploy your app.
.env - 如果要在应用程序本身中保留以应用程序为中心的环境变量,同时为rails应用程序的不同运行时环境维护环境变量的不同变体,请使用此选项。例如:.env.development和.env.test文件,分别包含开发和测试环境的特定环境变量值。这使您可以更好地控制应用程序的环境变量,而不必依赖于要部署应用程序的平台(终端shell)。
config/local_env.yml
- This is similar to .env
approach, which is provided out of the box by rails gem that allows you to configure environment variables for your app in yml format. This method also keeps your app's configuration within the app irrespective of the shell you are using to run your app.
config / local_env.yml - 这类似于.env方法,它由rails gem开箱即用,允许您以yml格式配置应用程序的环境变量。此方法还可以将应用程序的配置保留在应用程序中,而不管您用于运行应用程序的shell。
#1
1
All of these methods are used to feed environment variables to your rails application. So, from an app's point of view, it serves the same purpose whether you export it from .env
or .bashrc
or config/local_env.yml
files.
所有这些方法都用于将环境变量提供给rails应用程序。因此,从应用程序的角度来看,无论是从.env还是.bashrc或config / local_env.yml文件导出它,它都有相同的用途。
The differences in these methods are really a matter of personal choice among the team members involved in maintaining the app's development and deployment environments. However, here are few things to consider while opting for either of these choices.
这些方法的差异实际上是参与维护应用程序开发和部署环境的团队成员的个人选择问题。但是,在选择其中任何一种选择时,需要考虑以下几点。
.bashrc
- Use this if you manually configure deployment servers and really comfortable with linux/unix command line system administration. This configuration file is specific to bash shell (Bourne Again Shell). You need to configure different file if your server uses different shell (for example: .zshrc
if it uses Z Shell)
.bashrc - 如果您手动配置部署服务器并且非常熟悉linux / unix命令行系统管理,请使用此选项。此配置文件特定于bash shell(Bourne Again Shell)。如果服务器使用不同的shell,则需要配置不同的文件(例如:如果使用Z Shell,则为.zshrc)
.env
- Use this if you want to keep your app centric environment variables within the app itself while maintaining different variations of environment variables for different runtime environments of your rails app. For example: .env.development
and .env.test
files with specific values of the environment variables for your development and test environments respectively. This gives you more control of your app's environment variables and do not have to rely on the platform (terminal shell) you want to deploy your app.
.env - 如果要在应用程序本身中保留以应用程序为中心的环境变量,同时为rails应用程序的不同运行时环境维护环境变量的不同变体,请使用此选项。例如:.env.development和.env.test文件,分别包含开发和测试环境的特定环境变量值。这使您可以更好地控制应用程序的环境变量,而不必依赖于要部署应用程序的平台(终端shell)。
config/local_env.yml
- This is similar to .env
approach, which is provided out of the box by rails gem that allows you to configure environment variables for your app in yml format. This method also keeps your app's configuration within the app irrespective of the shell you are using to run your app.
config / local_env.yml - 这类似于.env方法,它由rails gem开箱即用,允许您以yml格式配置应用程序的环境变量。此方法还可以将应用程序的配置保留在应用程序中,而不管您用于运行应用程序的shell。