I've just updated my Rails app to 5.2, and configured it to use the new config/credentials.yml.enc
file.
When I try to deploy, I get this error:
NameError: uninitialized constant Rails
/Users/me/Documents/project/config/deploy.rb:27:in `<top (required)>'
That's pointing to this line in my config/deploy.rb
file:
set :rollbar_token, Rails.application.credentials[:rollbar_token]
So it appears that while capistrano is running, it doesn't have access to Rails.application.credentials
.
How are you all handling this? I've got some ideas...
ENV
variable
Rails.application.credentials
config/deploy.rb
# config/deploy.rb
require File.expand_path("./environment", __dir__)
This include make constants like Rails.application
accessible in files like config/deploy/production.rb
. Now things like the following are possible:
# config/deploy/staging.rb
server "production.lan", user: "production", roles: %w{app db web}
set :stage, :production
set :branch, "development"
set :pg_password, Rails.application.credentials[:staging][:postgres][:password]
master.key
the file on the server (user read-only) like so:namespace :setup do
desc "setup: copy config/master.key to shared/config"
task :copy_linked_master_key do
on roles(fetch(:setup_roles)) do
sudo :mkdir, "-pv", shared_path
upload! "config/master.key", "#{shared_path}/config/master.key"
sudo :chmod, "600", "#{shared_path}/config/master.key"
end
end
before "deploy:symlink:linked_files", "setup:copy_linked_master_key"
end
Put it in your lib/capistrano/tasks/setup.rake
In deploy.rb
:
set :linked_files, fetch(:linked_files, []).push("config/master.key")
Make sure your Capfile
has the line
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
I solved the problem as follows:
set :rollbar_token, YAML.load(`rails credentials:show`)['rollbar_token']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With