capistrano error: …/current: No such file or direc

2019-04-16 07:15发布

问题:

I'm trying to deploy using capistrano but when I do cap deploy:update it's not creating a /current folder, here's the error, any ideas?

executing "cd /home/adamtodd/apps/homebase/current && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile --trace"
servers: ["xx.xxx.xx.xxx"]
[xx.xxx.xx.xxx] executing command
 ** [out :: xx.xxx.xx.xxx] bash: line 0: cd: /home/adamtodd/apps/homebase/current: No such file or directory

回答1:

I had the same problem when I used Ben Curtis solution for assets precompilation (assets:precompile task redifinition) on first-time deploy (deploy:cold didn't help me)

Simple workaround here

namespace :deploy do
  namespace :assets do
    task :precompile, :roles => :web, :except => { :no_release => true } do
      begin
        from = source.next_revision(current_revision) # <-- Fail here at first-time deploy because of current/REVISION absence
      rescue
        err_no = true
      end
      if err_no || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
        run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
      else
        logger.info "Skipping asset pre-compilation because there were no asset changes"
      end
   end
  end
end


回答2:

cap deploy:update will generally only work for applications that have already been deployed once which I'm assuming hasn't happened in your case since you don't have a current directory.

Try doing a cap deploy:cold instead.



回答3:

It looks like you've redefined the deploy:assets:precompile task, because in the Capistrano source code you can see it tries to cd into releases/12345, not current:

https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy/assets.rb#L31-43

So I would check your deploy.rb and remove the redefined task.

(I had redefined the task in the same way, even adding a --trace like you, but whatever problem I was trying to solve isn't a problem any more, and the out-of-the-box task works fine for me. If I had to guess, I'd say that our custom task was a hack to get RAILS_GROUPS=assets into the command string, but Capistrano handles that automatically now, as you can see if you check the linked source code.)