0

I have a Rails 5 app, and I'm trying to store my environment variables on a non Heroku server.

Therefore I created a config/application.yml file with my environment variables on the production server.

However, when I try to deploy my Rails app, the deployment fails because the environment variables can't be accessed.

Am I missing something?

Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
Toontje
  • 1,415
  • 4
  • 25
  • 43

1 Answers1

0

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

# lib/capistrano/tasks/uploader.rake
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.

Shiva
  • 11,485
  • 2
  • 67
  • 84