我从heroku那里了解到,可以通过在本地运行heroku config:add MY_ENV_VAR=123来添加环境变量。如何使用engineyard实现相同的功能?
发布于 2015-07-22 11:15:12
我之前也在使用Heroku,现在我转到了Engineyard。这就是我在Heroku中获取ENvironemnt变量的方法,我添加了gem figaro。这个gem基本上需要app/config目录下的application.yml文件。在初始化Rails应用程序时,它将被执行并将以YAML格式设置的键值对加载到内存中。在Heroku中,Figaro可以选择设置application.yml的内容。
$ figaro heroku:set -e production然而,在Engineyard中,我们需要使用EY包的SCP选项手动复制application.yml,其余的工作将由figaro完成。
首先在gem文件中包含gem figaro并安装gem。
然后,我们需要使用engineyard-hooks将文件/data/[your_app]/shared/config/application.yml复制到/data/[your_app]/current/config/application.yml。我们需要使用before_restart钩子
# inside your project repo create a 'deploy' folder and
#   inside deploy/before_restart.rb paste the following code with or without modifications
# This file is executed everytime after deploy just before your app restarts
on_app_servers_and_utilities do
  # Copy the yaml files from `shared/config` to `current/config`
  ['application.yml'].each do |file_name|
    run "ln -nfs #{config.shared_path}/config/#{file_name} #{config.release_path}/config/#{file_name}"
  end
end提交您的更改并推送到您的github存储库或其他地方。
到目前为止,还不存在/data/[your_app]/shared/config/application.yml文件。现在使用以下命令将文件从本地复制到服务器
# This copies the application.yml to every instance like app_master, app_slave, utilities, database, etc    
$ ey scp config/application.yml HOST:/data/[your_app_name]/shared/config/ -e app_environment --all现在,您可以部署您的应用程序,并获得所有环境变量。
注意:每次引导环境时,都需要调用上面的命令将文件复制到服务器。这意味着如果您停止转移(例如),并在一段时间后启动它,那么您需要调用上面的
命令
https://stackoverflow.com/questions/12342612
复制相似问题