0

I'm trying to update an app (Rails 4.1.12; ruby 1.9.3p484) by deploying changes from development to production using capistrano. Below is log (I masked the IP address and suggested secret key).

Previously never had a problem running a deploy. Have searched and found posts with similar errors but have not found a solution. I did follow the instructions to add Devise.secret_key to the Devise initializer and restarted the application (dev and prod). Next attempt to deploy received same error with suggestion for different secret key.

All help, hints, suggestions are greatly appreciated. Thanks.

UPDATE:I just tried to deploy using bundle exec cap production deploy and did not get errors but still get errors when running cap production deploy

UPDATE 2: I used Figaro to generate an application.yml file (and append to gitignore). In the devise.rb file I created a line config.secret_key = ENV["config.secret_key"] In the application.yml file I created a line config.secret_key: 'random_128_chr_string' I then restarted the development server and ran cap production deploy Unfortunately got same error.

cap production deploy
.
.
.
[deploy:migrate] Run `rake db:migrate`
[e0c2c251] Running bundle exec rake db:migrate as deployer@123.123.123.12
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer@123.123.123.12: rake exit status: 1
rake stdout: Nothing written
rake stderr: rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = 'looong_string_of_numbers_and_letters'
Please ensure you restarted your application after installing Devise or setting the key. 

deploy.rb:

lock '>=3.2.1'

set :application, 'pepperslice'
set :repo_url, 'git@github.com:jeffaltman/pepperslice.git'
set :linked_dirs, %w{log tmp public/images/uploaded}
set :linked_files, %w{config/database.yml config/initializers/devise.rb config/initializers/smtp_settings.rb}

set :format, :pretty
set :log_level, :info

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute "sudo /usr/sbin/service unicorn restart"
    end
  end

  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end
end

capfile:

# Load DSL and Setup Up Stages
require 'capistrano/setup'

# Includes default deployment tasks
require 'capistrano/deploy'

# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
# require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
#require 'capistrano/ssh_doctor'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
JeffA
  • 166
  • 1
  • 17
  • How did you add the Devise key into the initializer? Did you use environment vars? – CV-Gate Aug 15 '17 at 23:42
  • @CV-Gate: I added the line `config.secret_key = 'config.secret_key = '5067772487f76f8c11ac3b6b3e1ff45b6f3...'` – JeffA Aug 16 '17 at 00:11
  • Is that a typo or you are including `config.secret_key = ` into your key? Also, you should use environment vars. Have a look at this: https://github.com/bkeepers/dotenv – CV-Gate Aug 16 '17 at 00:15
  • That is not a typo. The initializer had a commented out line with `config-secret_key=...` in it. I uncommented the line and used the error log recommended secret key. Also, I didn't set up the development environment and am pretty much a noob in this area. I'll look at the link. In addition, please note the update to my original question. That may be a clue to what is happening. Thanks for responding. – JeffA Aug 16 '17 at 00:21
  • You should use a valid key, if you want to generate one easily go into your rails console and type `SecureRandom.hex(64)`. I also read your edit and there is nothing wrong using `bundle exec`, doing that you are using the gems that are in your Gemfile with their corresponding versions. Maybe you are not getting any error just because of that, but the problem with your Devise secret key remains. – CV-Gate Aug 16 '17 at 00:33
  • I generated the key and changed the `config.secret_key` in the initializer to the generated key. Same error with different suggested key. Also, I looked at the link the you sent but that will take me awhile to digest. I'm the only developer in this case - not sure if that makes a difference. – JeffA Aug 16 '17 at 01:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152080/discussion-between-jeffa-and-cv-gate). – JeffA Aug 16 '17 at 18:01

0 Answers0