Environment variables on production

痴心易碎 提交于 2019-12-19 09:00:27

问题


I’m currently deploying my Rails application on Amazon and I’m facing a problem with environment variables.

I'm using the dotenv gem on development and testing and it works just fine while trying to access my environment variables, but in production it does not seem to work. I read that the dotenv gem isn't meant to work on production. I have to set almost 20 different environment variables including API keys, etc., I'm deploying with rubber/capistrano.

How can I get this working in a clean way?


回答1:


You could use the figaro gem. I am using this and it works fine in production.




回答2:


The dotenv-deployment readme mentions how you can use it in a production environment:

If you're using Capistrano 3+:

Just add .env to your list of linked_files:

set :linked_files, %w{.env}

If you're using Capistrano 2.x.x version:

In your config/deploy.rb file:

require "dotenv/capistrano"

It will symlink the .env located in /path/to/shared in the new release.

Remember to add :production group to the dotenv-rails gem in your application's Gemfile:

gem 'dotenv-rails', :groups => [:development, :test, :production]



回答3:


In Capistrano 3 add require "dotenv/rails-now" to your Capfile. This will make sure that capistrano has access to the environment as well.

(We had issues with capistrano accessing the API token for appsignal, so capistrano wasn't able to notify appsignal when a new deploy was done)



来源:https://stackoverflow.com/questions/17150736/environment-variables-on-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!