Setting environment variables in engineyard

社会主义新天地 提交于 2019-12-04 07:29:19

We ran into the same issue and asked EngineYard for some assistance. Jim Neath from EY came back with the following response:

Unfortunately, passenger does not get passed environment variables from the system. What you need to do is create a ruby wrapper that defines your environment variables and launch passenger using this, as described here:

http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger/

I have created you a basic custom chef recipe that will do just this:

https://github.com/jimneath/ey-cloud-recipes/tree/master/cookbooks/passenger_env_vars

You will need to update the following file with your environment variables:

/ey-cloud-recipes/blob/master/cookbooks/passenger_env_vars/templates/default/env.custom.erb

I don't think you can =/.

One work-around that we use with our Rails applications is to ssh (ey ssh) to EngineYard and create a file in vim /data/your_app_name/shared/config/exports.rb. This file can look something like this:

ENV["AWS_ACCESS_KEY_ID"] = "your key"
ENV["AWS_SECRET_ACCESS_KEY"] = "your secret"
ENV["AWS_BUCKET"] = "your bucket"

Then in config/boot.rb you require the file:

require File.expand_path('./exports', File.dirname(__FILE__))

This is neither pretty, nor effortless. It however let you use secrets in your app that you should not check into source control!

Vlado Cingel

This is pretty simple for Unicorn using env.custom. Take a look at my answer here https://stackoverflow.com/a/13741463/1520775

If you want to run a rake task (i.e. cron job) that needs these environmental variables, store the variables in /data/my_app/shared/config/env.custom

source /data/my_app/shared/config/env.custom && cd /data/my_app/current/ && bundle exec rake my_rake_task

I was also using Heroku previously now I moved to Engineyard. This is how I get my ENvironemnt variables in Heroku I added gem figaro. This gem basically needs file application.yml in app/config directory. When Rails app is initialized, it gets executed and loads the key value pair set in YAML format into memory. In Heroku Figaro has option to set the content of application.yml.

$ figaro heroku:set -e production

However, In Engineyard we need to manually copy the application.yml using SCP option of EY package and rest thing will be done by figaro.

First include the gem figaro in gemfile and install the gem.
Then we need to use engineyard-hooks to copy the file /data/[your_app]/shared/config/application.yml to /data/[your_app]/current/config/application.yml. we need to use before_restart hook

# 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

Commit your changes and push to your github repo or somewhere.

Upto here, there doesnot exists the file /data/[your_app]/shared/config/application.yml. Now use the following command to copy the file from local to servers

# 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

Now you can deploy your app and you get all your environment variables.

Note : You need to invoke the above command to copy file to server every time you boot the enviroment. Means if you stop the staging (for example) and after some time boot it up then you need to invoke the command above

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