Capistrano rails部署失败

时间:2013-07-31 09:41:23

标签: ruby-on-rails capistrano rvm-capistrano

当我尝试使用capistrano进行部署时,我收到错误

/home/username/.rvm/gems/ruby-2.0.0-p0@dvr/gems/capistrano-2.15.5/lib/capistrano/recipes/deploy/assets.rb:28:in `parse_manifest': undefined method `to_a' for #<String:0x9fa62d0> (NoMethodError)

此外,在输出中我有多个这样的实例:

** [out :: *IP_HERE*] SHELL=/bin/bash
** [out :: *IP_HERE*] SSH_CLIENT=*IP_HERE* 53366 22
** [out :: *IP_HERE*] USER=root
** [out :: *IP_HERE*] MAIL=/var/mail/root
** [out :: *IP_HERE*] PATH=/usr/local/rvm/gems/ruby-2.0.0-p247/bin:/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p247/bin:/home/rails/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
** [out :: *IP_HERE*] PWD=/root
** [out :: *IP_HERE*] LANG=en_US.UTF-8
** [out :: *IP_HERE*] SHLVL=1
** [out :: *IP_HERE*] HOME=/root
** [out :: *IP_HERE*] LANGUAGE=en_US:en
** [out :: *IP_HERE*] LOGNAME=root
** [out :: *IP_HERE*] SSH_CONNECTION=*IP_HERE* 53366 *IP_HERE* 22
** [out :: *IP_HERE*] _=/usr/bin/env
** [out :: *IP_HERE*] RUBY_VERSION=ruby-2.0.0-p247
** [out :: *IP_HERE*] GEM_HOME=/usr/local/rvm/gems/ruby-2.0.0-p247:/usr/local/rvm/gems/ruby-2.0.0-p247@global
** [out :: *IP_HERE*] BUNDLE_PATH=/usr/local/rvm/gems/ruby-2.0.0-p247

我发现这个输出来自capture函数,在gem(path_to_cap_gem/configuration/actions/inspect.rb)中定义:

def capture(command, options={})
        output = ""
        invoke_command(command, options.merge(:once => true, :eof => !command.include?(sudo))) do |ch, stream, data|
          case stream
            when :out then output << data
            when :err then warn "[err :: #{ch[:server]}] #{data}"
            end
          end
        output
end

因此函数parse_manifest尝试解析capture方法的输出而不是它想要的方法。

最后有PATH字符串/usr/games,真是奇怪。

部分Gemfile:

gem 'capistrano'
gem 'rvm-capistrano'

Capfile:

load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks

deploy.rb:

require 'bundler/capistrano'
require 'rvm/capistrano'
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
set :application, 'dvr_rails'


set :rvm_ruby, "ruby-2.0.0-p247"
set :rvm_ruby_string, 'ruby-2.0.0-p247@dvr'
set :rvm_gem_home, "/usr/local/rvm/gems/#{fetch(:rvm_ruby)}"
set :rvm_ruby_path, "/usr/local/rvm/rubies/#{fetch(:rvm_ruby)}"
set :default_environment, {
        'RUBY_VERSION' => fetch(:rvm_ruby),
        'GEM_HOME' => "#{fetch(:rvm_gem_home)}:#{fetch(:rvm_gem_home)}@global",
        'BUNDLE_PATH' => fetch(:rvm_gem_home),
        'PATH' => "#{fetch(:rvm_gem_home)}/bin:#{fetch(:rvm_gem_home)}@global/bin:#{fetch(:rvm_ruby_path)}/bin:/home/rails/.rvm/bin:$PATH;",
}

set :rvm_type, :system  # Copy the exact line. I really mean :system here*

set :scm, :none
set :repository, '.'
set :deploy_via, :copy



server 'IP_HERE', :app, :web, :db, :primary => true

#If you are using Passenger mod_rails uncomment this:
namespace :deploy do
    task :start do ; end
   task :stop do ; end
   task :restart, :roles => :app, :except => { :no_release => true } do
       run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
   end
end

set :deploy_to, '/var/sites/dvr_rails'

set :user, 'root'
set :use_sudo, 'true'
set :password, 'password'

有什么想法吗?

Ruby 2.0.0,Rails 4,Capistrano 2.15.5。服务器 - ubuntu 12.04,JS可执行文件 - nodejs。

1 个答案:

答案 0 :(得分:0)

解决了它。仍然不知道在capture函数深处真正发生了什么,但编辑deploy.rb有帮助。 这是我的工作配置:

require 'bundler/capistrano'
require 'rvm/capistrano'
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
set :application, 'dvr_rails'

set :rvm_ruby, "ruby-2.0.0-p247"
set :rvm_ruby_string, "ruby-2.0.0-p247@dvr"
set :rvm_gem_home, "/usr/local/rvm/gems/#{fetch(:rvm_ruby_string)}"

=begin
# These sets somehow messed up everything. 
set :rvm_ruby_path, "/usr/local/rvm/rubies/#{fetch(:rvm_ruby)}"
set :default_environment, {
        'RUBY_VERSION' => fetch(:rvm_ruby),
        'GEM_HOME' => "#{fetch(:rvm_gem_home)}:#{fetch(:rvm_gem_home)}@global",
        'BUNDLE_PATH' => fetch(:rvm_gem_home),
        'PATH' => "#{fetch(:rvm_gem_home)}/bin:#{fetch(:rvm_gem_home)}@global/bin:#{fetch(:rvm_ruby_path)}/bin:/home/rails/.rvm/bin;",
}
=end


#set :rvm_bin_path, "/usr/local/rvm/bin"
set :rvm_type, :system  # Copy the exact line. I really mean :system here*

set :scm, :none
set :repository, '.'
set :deploy_via, :copy

set :rails_env, 'production'


server 'IP_HERE', :app, :web, :db, :primary => true


#If you are using Passenger mod_rails uncomment this:
namespace :deploy do
    task :start do ; end
   task :stop do ; end
   task :restart, :roles => :app, :except => { :no_release => true } do
       run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
   end
end

set :deploy_to, '/var/sites/dvr_rails'

set :user, 'root'
#set :use_sudo, 'true' #loggin as root, so no sudo required
set :password, 'password'