I'm using Capistrano 3.1.4, with capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/faster_assets'
require 'capistrano/rails/migrations'
I've setup my gems to use figaro and devise. When I ssh to the box, and ran (with .bash_profile export RAILS_ENV=production)
bundle install # works fine
bundle exec rake db:migrate # works fine
But when I execute:
cap production deploy:compile
I get the error stating devise secret key not set, is it because bash -login was not running on server?
** Invoke deploy:compile_assets (first_time)
** Invoke deploy:set_rails_env
** Execute deploy:compile_assets
** Invoke deploy:assets:precompile (first_time)
** Execute deploy:assets:precompile
DEBUG [05812cf9] Running /usr/bin/env if test ! -d /home/user1/rails/releases/20150507175646; then echo "Directory does not exist '/home/user1/rails/releases/20150507175646'" 1>&2; false; fi as [email protected]
DEBUG [05812cf9] Command: if test ! -d /home/user1/rails/releases/20150507175646; then echo "Directory does not exist '/home/user1/rails/releases/20150507175646'" 1>&2; false; fi
DEBUG [05812cf9] stdin: is not a tty
DEBUG [05812cf9] Finished in 0.458 seconds with exit status 0 (successful).
DEBUG [4713c277] Running /usr/bin/env ls -xr /home/user1/rails/releases as [email protected]
DEBUG [4713c277] Command: cd /home/user1/rails/releases/20150507175646 && ( RAILS_ENV=production /usr/bin/env ls -xr /home/user1/rails/releases )
DEBUG [4713c277] stdin: is not a tty
DEBUG [4713c277] 20150507175646 20150507175448 20150507173408 20150507171913 20150507162459
DEBUG [4713c277] 20150507161419 20150507155316 20150507153253 20150507151908 20150507150428
DEBUG [4713c277] 20150507145904 20150507142928 20150507104745 20150504061059 20150504051818
DEBUG [4713c277] 20150429060420 20150417025054
DEBUG [4713c277] Finished in 0.404 seconds with exit status 0 (successful).
INFO [f226806f] Running /usr/bin/env ls /home/user1/rails/releases/20150507175448/assets_manifest_backup as [email protected]
DEBUG [f226806f] Command: cd /home/user1/rails/releases/20150507175646 && ( RAILS_ENV=production /usr/bin/env ls /home/user1/rails/releases/20150507175448/assets_manifest_backup )
DEBUG [f226806f] stdin: is not a tty
DEBUG [f226806f] ls:
DEBUG [f226806f] cannot access /home/user1/rails/releases/20150507175448/assets_manifest_backup
DEBUG [f226806f] : No such file or directory
DEBUG [f226806f]
INFO [07c227d5] Running /usr/local/rvm/bin/rvm default do bundle exec rake assets:precompile as [email protected]
DEBUG [07c227d5] Command: cd /home/user1/rails/releases/20150507175646 && ( RAILS_ENV=production /usr/local/rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [07c227d5] stdin: is not a tty
DEBUG [07c227d5] rake aborted!
DEBUG [07c227d5] Devise.secret_key was not set. Please add the following to your Devise initializer:
DEBUG [07c227d5]
DEBUG [07c227d5] config.secret_key = '2b23a31ec3325533df50c4384f2b0d62fa8430c606adb7d24259cbdadd329e3d659a2c0dd2b42c19cc7761b836e9200ed413a3d0d1ab530369bf20198d9c39c7'
DEBUG [07c227d5]
DEBUG [07c227d5] Please ensure you restarted your application after installing Devise or setting the key.
DEBUG [07c227d5] /home/user1/rails/shared/bundle/ruby/2.1.0/gems/devise-3.3.0/lib/devise/rails/routes.rb:483:in `raise_no_secret_key'
DEBUG [07c227d5] /home/user1/rails/shared/bundle/ruby/2.1.0/gems/devise-3.3.0/lib/devise/rails/routes.rb:209:in `devise_for'
DEBUG [07c227d5] /home/user1/rails/releases/20150507175646/config/routes.rb:91:in `block in <top (required)>'
DEBUG [07c227d5] /home/user1/rails/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
DEBUG [07c227d5] /home/user1/rails/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
DEBUG [07c227d5] /home/user1/rails/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:315:in `draw'
DEBUG [07c227d5] /home/user1/rails/releases/20150507175646/config/routes.rb:1:in `<top (required)>'
...
it turned out that my figaro tasks was not executed before the assets:precompile. ive changed my event to before :updated to fix the issue. here are the example of a working figaro in config/deploy.rb
cap production deploy --trace # will be useful for debuggging
more on capistrano flow
namespace :figaro do
desc "SCP transfer figaro configuration to the shared folder"
task :setup do
on roles(:app) do
upload! "config/application.yml", "#{shared_path}/application.yml", via: :scp
end
end
desc "Symlink application.yml to the release path"
task :symlink do
on roles(:app) do
execute "ln -sf #{shared_path}/application.yml #{release_path}/config/application.yml"
end
end
end
namespace :deploy do
before :updated, "figaro:setup"
before :updated, "figaro:symlink"
end
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