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}"

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.


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s