Rails : Upload secret files using Capistrano before booting

This answer is tested with Capistrano 3.6.1

Well, in that case, you would have to make capistrano upload your application.yml(database.yml if its ignored from git).

# in config/deploy.rb

# Default value for :linked_files is []
append :linked_files, 'config/database.yml', 'config/application.yml'

Now write some code to upload the files to the server

namespace :upload do
  desc 'Upload shared files to the server'
  task :yml_files do
    on roles(:web) do |host|
      fetch(:linked_files).each do |common_file|
        upload! common_file, "#{fetch(:deploy_to)}/shared/#{common_file}"
      end
    end
  end
end

Now you need to trigger the above mentioned capistrano task just before a very specific event.

# config/deploy.rb

before 'deploy:check:linked_files', 'upload:yml_files'

This will make sure the necessary environment variables are set before your deployed tries to boot your application in the production server.

Advertisements

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. Continue reading