Engineyard : Ruby On Rails : Setting environment variables at once

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 EYpackage 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s