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 user1#example.com
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 user1#example.com
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 user1#example.com
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 user1#example.com
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
Related
When deploying our API (which doesn't use assets at all), it hangs for about 5 minutes on this line:
DEBUG [985661f8] cannot access /var/www/api.staging/releases/20160208111413/public/assets/.sprockets-manifest*
DEBUG [985661f8] : No such file or directory
We have already disabled assets in config/application.rb:
config.assets.enabled = false
What else needs to be done? We're using these versions:
capistrano (3.4.0)
capistrano-bundler (1.1.4)
capistrano-rails (1.1.3)
capistrano-rails-collection (0.0.3)
Capistrano log:
INFO [42c93c96] Running /usr/local/rvm/bin/rvm 2.1.0#appyapi.staging do bundle exec rake assets:precompile as deploy#139.162.4.97
DEBUG [42c93c96] Command: cd /var/www/appyapi.staging/releases/20160223041856 && ( RAILS_ENV=staging /usr/local/rvm/bin/rvm 2.1.0#appyapi.staging do bundle exec rake assets:precompile )
INFO [42c93c96] Finished in 279.004 seconds with exit status 0 (successful).
DEBUG [f2410fde] Running /usr/bin/env if test ! -d /var/www/appyapi.staging/releases/20160223041856; then echo "Directory does not exist '/var/www/appyapi.staging/releases/20160223041856'" 1>&2; false; fi as deploy#139.162.4.97
DEBUG [f2410fde] Command: if test ! -d /var/www/appyapi.staging/releases/20160223041856; then echo "Directory does not exist '/var/www/appyapi.staging/releases/20160223041856'" 1>&2; false; fi
DEBUG [f2410fde] Finished in 0.081 seconds with exit status 0 (successful).
INFO [fd9b639a] Running /usr/bin/env mkdir -p /var/www/appyapi.staging/releases/20160223041856/assets_manifest_backup as deploy#139.162.4.97
DEBUG [fd9b639a] Command: cd /var/www/appyapi.staging/releases/20160223041856 && /usr/bin/env mkdir -p /var/www/appyapi.staging/releases/20160223041856/assets_manifest_backup
INFO [fd9b639a] Finished in 0.078 seconds with exit status 0 (successful).
DEBUG [462a5734] Running /usr/bin/env ls /var/www/appyapi.staging/releases/20160223041856/public/assets/.sprockets-manifest* as deploy#139.162.4.97
DEBUG [462a5734] Command: cd /var/www/appyapi.staging/releases/20160223041856 && /usr/bin/env ls /var/www/appyapi.staging/releases/20160223041856/public/assets/.sprockets-manifest*
DEBUG [462a5734] ls: cannot access /var/www/appyapi.staging/releases/20160223041856/public/assets/.sprockets-manifest*
DEBUG [462a5734] : No such file or directory
DEBUG [462a5734] Finished in 0.079 seconds with exit status 2 (failed).
OK, first it is important to know that the "No such file or directory" error is benign. Capistrano executes certain commands as tests and takes different code paths based on the results, and it is completely normal that some of those tests result in failures. Unless Capistrano raises an exception, you can safely ignore these "errors".
Second, it seems that rake assets:precompile is being run even though you are not using the asset pipeline, and therefore have no use for it. I'm surprised this step could take so long if you don't have any assets, but let's leave that for another discussion.
The quick solution is to not include the asset pipeline steps of the capistrano-rails plugin. As explained in the README, you can do this by including only the steps you need.
So:
# Put these in your Capfile
require "capistrano/bundler"
require "capistrano/rails/migrations"
# REMOVE these lines so that asset pipeline steps are excluded
# require "capistrano/rails"
# require "capistrano/rails/assets"
My rails application uses capistrano 3.4.0 for the deploy tasks.
In my Capfile I have the line require 'capistrano/rails/migrations' in order to have the configured task that can run the DB migrations.
When I cap production deploy, I can see always the following output:
INFO [deploy:migrate] Run `rake db:migrate`
DEBUG [6214167f] Running /usr/bin/env if test ! -d XXXX/releases/20160117093811; then echo "Directory does not exist 'XXXX/releases/20160117093811'" 1>&2; false; fi as deploy#candiru-web
DEBUG [6214167f] Command: if test ! -d XXXX/releases/20160117093811; then echo "Directory does not exist 'XXXX/releases/20160117093811'" 1>&2; false; fi
DEBUG [6214167f] Finished in 0.005 seconds with exit status 0 (successful).
INFO [1ebeb8c8] Running ~/.rvm/bin/rvm default do bundle exec rake db:migrate as deploy#candiru-web
DEBUG [1ebeb8c8] Command: cd XXXX/releases/20160117093811 && ( RAILS_ENV=production ~/.rvm/bin/rvm default do bundle exec rake db:migrate )
even if I don't add something like after :deploy, "deploy:migrate".
If I comment out the line require 'capistrano/rails/migrations', the migration won't be executed.
Why? shouldn't it run only if I add the task to my deploy script in config/deploy.rb?
According to documentation of the capistrano/rails gem, you have to set :conditionally_migrate option in order to check if you need to run migrations.
I guess that's the option you need and you should add it in your deploy.rb, this way:
set :conditionally_migrate, true
And to answer your question, in migrations.rake file the task deploy:migrate is already set to run after deploy:updated.
Also, if you want to completely remove this task from your deploy process, and always run migrations manually, by invoking deploy:migrate, you can do like this:
Rake::Task["deploy:migrate"].clear_actions
I'm using capistrano 3.2.1 with capistrano-resque gem to restart rasque workers on deployment. Always getting this error.
If I start workers manually under current directory on production server it starts fine.
cd /home/azureuser/apps/app_production/current && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 /usr/bin/env nohup RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.1 ~/.rbenv/bin/rbenv exec bundle exec rake RACK_ENV=production RAILS_ENV=production QUEUE="mailer" PIDFILE=/home/azureuser/apps/app_production/shared/tmp/pids/resque_work_1.pid BACKGROUND=yes VERBOSE=1 INTERVAL=5 environment resque:work >> log/resque.log 2>> log/resque.log )
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as azureuser#thesend.cloudapp.net: nohup exit status: 127
nohup stdout: Nothing written
nohup stderr: Nothing written
/Library/Ruby/Gems/2.0.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/Library/Ruby/Gems/2.0.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
SSHKit::Command::Failed: nohup exit status: 127
After I worked out that capistrano-rbenv was the problem, I removed that gem from my gemfile and also my capfile.
I then just added the following to my deploy.rb file:
set :default_env, {
PATH: "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH",
RBENV_ROOT: '~/.rbenv',
RBENV_VERSION: '2.2.2'
}
Now capistrano-resque works correctly as does unicorn etc..
I fix this based on the #archfish recommendation on capistrano-resque incompatibility between capistrano-resque and capistrano-rbenv issue. Then you should add or modify the :rbenv_prefix on deploy.rb, like:
set :rbenv_prefix, "env RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
Note: the :rbenv_prefix usually is used like:
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
I am getting the following error while deploying using capistrano 3
INFO [5d0ddb5f] Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on 162.243.253.220
DEBUG [5d0ddb5f] Command: cd /home/deployer/apps/nabthat/releases/20131227083740 && ( RAILS_ENV=staging ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [5d0ddb5f] /home/deployer/.rvm/rubies/ruby-2.0.0-p353/bin/ruby /home/deployer/apps/nabthat/shared/bundle/ruby/2.0.0/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets
DEBUG [5d0ddb5f]
DEBUG [5d0ddb5f] rake aborted!
DEBUG [5d0ddb5f]
DEBUG [5d0ddb5f] database configuration does not specify adapter
DEBUG [5d0ddb5f]
DEBUG [5d0ddb5f] /home/deployer/apps/nabthat/shared/bundle/ruby/2.0.0/gems/activerecord- 3.2.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection
I deploy using the command
bundle exec staging deploy
but error shows RAILS_ENV=staging, how to change it to production
i tried
bundle exec staging deploy RAILS_ENV="production"
still same error
I've been trying to configure my deployment with capistrano for a few weeks now, and it still is not working properly. Every time I deploy to my server I get an error saying a gem is missing, like:
DEBUG [a0e618f0] /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize'
DEBUG [a0e618f0] :
DEBUG [a0e618f0] Could not find ansi-1.4.3 in any of the sources
DEBUG [a0e618f0] (
DEBUG [a0e618f0] Bundler::GemNotFound
DEBUG [a0e618f0] )
I know how to fix this, simply install the "ansi" gem, but there is a much bigger problem here: why didn't bundler work properly with capistrano??
When I look higher in the output I see:
INFO [1ee9a88e] Running ~/.rvm/bin/rvm ruby-2.0.0-p247 do bundle --gemfile /var/www/html/SparkMyInterest/releases/20131122204608/Gemfile --path /var/www/html/SparkMyInterest/shared/bundle --deployment --quiet --binstubs /var/www/html/SparkMyInterest/shared/bin --without development test on 54.200.196.1
DEBUG [1ee9a88e] Command: cd /var/www/html/SparkMyInterest/releases/20131122204608 && ( RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.0.0-p247 do bundle --gemfile /var/www/html/SparkMyInterest/releases/20131122204608/Gemfile --path /var/www/html/SparkMyInterest/shared/bundle --deployment --quiet --binstubs /var/www/html/SparkMyInterest/shared/bin --without development test )
INFO [1ee9a88e] Finished in 20.132 seconds with exit status 0 (successful).
DEBUG [7d1a9e40] Running if test ! -d /var/www/html/SparkMyInterest/releases/20131122204608; then echo "Directory does not exist '/var/www/html/SparkMyInterest/releases/20131122204608'" 1>&2; false; fi on 54.200.196.1
DEBUG [7d1a9e40] Command: if test ! -d /var/www/html/SparkMyInterest/releases/20131122204608; then echo "Directory does not exist '/var/www/html/SparkMyInterest/releases/20131122204608'" 1>&2; false; fi
DEBUG [7d1a9e40] Finished in 1.291 seconds with exit status 0 (successful).
INFO [a0e618f0] Running ~/.rvm/bin/rvm ruby-2.0.0-p247 do rake assets:precompile on 54.200.196.1
DEBUG [a0e618f0] Command: cd /var/www/html/SparkMyInterest/releases/20131122204608 && ( RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.0.0-p247 do rake assets:precompile )
DEBUG [a0e618f0] /home/ec2-user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize'
DEBUG [a0e618f0] :
DEBUG [a0e618f0] Could not find ansi-1.4.3 in any of the sources
DEBUG [a0e618f0] (
DEBUG [a0e618f0] Bundler::GemNotFound
DEBUG [a0e618f0] )
Clearly it looks like bundler was run (and successful!). What gives?
Here's my cap file:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
And in my production.rb (I'm deploying with production) at the top I have:
set :stage, :production
set :rails_env, "production"
Any ideas why bundler isn't working? And/ or why it never seems to install all the required gems?
Thank you a million
I've worked through similar issues with rvm involved (required rvm/capistrano) by providing some additional info to capitrano
set :bundle_cmd, '/path/to/project/rvm/bundle'
set :default_shell, :bash
set :rvm_type, :system
set :rvm_ruby_string, release_path
This code was in my stage-specific deploy (e.g., deploy/production.rb). The issue that I had to work around was that the bundle was installed but to the wrong place; could be what you're facing here as well.
FWIW, rvm/capsitrano also let me specify a shell to use when running certain commands within the deploy script. For example, I was using the whenever gem to update my crontab and needed the "rvm_shell" (my specific ruby with gemset) to make this happen from capistrano. The line looks like this:
run "cd #{release_path} && bundle exec whenever -w -s environment=production", shell: fetch(:rvm_shell)