为什么capistrano资产预编译投掷ci / reporter / rake / rspec错误?

时间:2016-08-06 07:49:29

标签: ruby-on-rails ruby ruby-on-rails-3 deployment capistrano3

Capistrano部署在资产预编译步骤中抛出以下错误。

rake aborted!
LoadError: cannot load such file -- ci/reporter/rake/rspec
/home/ubuntu/github/my_app/releases/20160806071639/Rakefile:4:in `require'
/home/ubuntu/github/my_app/releases/20160806071639/Rakefile:4:in `<top (required)>'
/home/ubuntu/github/my_app/shared/bundle/ruby/2.0.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/bin/bundle:23:in `load'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/bin/bundle:23:in `<main>'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `eval'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)

我运行了以下命令,

  

cap staging deploy

所以,我尝试在发布文件夹中运行~/.rvm/bin/rvm default do bundle exec rake assets:precompile来检查我是否遗漏了部署文件中的内容。但它也失败了。

但是当我从我的部署目录(我正在运行~/.rvm/bin/rvm default do bundle exec rake assets:precompile命令的地方)运行相同的命令cap deploy时,它运行成功。

以下是环境设置

Ruby version = 2.0.0
Rails version = 3.2.21
Capistrano version = 3.4.0

我的deploy.rb文件(我已经更改了github网址),

# config valid only for current version of Capistrano
lock '3.4.0'

set :application, 'my_app'
set :repo_url, 'git@github.com:xyz/my_app.git'

set :branch, ENV["REVISION"] || ENV["BRANCH_NAME"] || "master"
set :deploy_root, "/home/ubuntu/github/"
set :deploy_to, "#{fetch(:deploy_root)}my_app"

set :bundle_flags, "--local --no-cache" 

set :scm_passphrase, ""
set :use_sudo, false
set :ssh_options, {:forward_agent => true}
set :copy_exclude, [ '.git' ]
set :rails_env, "staging"
set :keep_releases, 1
set :run_bundle_install, true
set :run_precompile, true
set :run_db_migrate, false
set :run_rspec, false

set :stage, :production

server "127.0.0.1", user: "ubuntu", roles: %w{web app}

set :linked_files, %w{config/database.yml config/database.yml}

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'

# Default value for :scm is :git
# set :scm, :git

# Default value for :format is :pretty
# set :format, :pretty

# Default value for :log_level is :debug
# set :log_level, :debug

# Default value for :pty is false
set :pty, true

# Default value for :linked_files is []
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')

# Default value for linked_dirs is []
# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
# set :keep_releases, 5

namespace :deploy do

  desc "Restart sidekiq"
  task :restart_sidekiq do
    run <<-CMD
      cd fetch(current_path) && script/sidekiq restart -e #{rails_env}
    CMD
  end

  desc "Restart application"
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join("tmp/restart.txt")
    end
  end

  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

  #after :finishing, "deploy:restart"
  after :finishing, "deploy:restart_sidekiq"
  after :finishing, "deploy:cleanup"

end

我的Capfile,

# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'

# Include 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
#   https://github.com/capistrano/passenger
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# require 'capistrano/passenger'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

Gemfile快照,

gem 'capistrano', '3.4.0'
gem 'sshkit', '1.11.2'
gem 'net-scp', '1.2.1'
gem 'capistrano-rails', '1.1.7'
gem 'capistrano-bundler', '1.1.4'
gem 'capistrano-rvm', '0.1.2'

如果您需要更多信息,请告诉我。

1 个答案:

答案 0 :(得分:1)

我自己也没有遇到过这种情况,所以很难给出直接答案。我会试着指出你正确的方向。

这个错误听起来像来自这个宝石:https://github.com/ci-reporter/ci_reporter

堆栈转储中的关键行是:

LoadError: cannot load such file -- ci/reporter/rake/rspec
/home/ubuntu/github/my_app/releases/20160806071639/Rakefile:4:in `require'
/home/ubuntu/github/my_app/releases/20160806071639/Rakefile:4:in `<top (required)>'

如果查看Rakefile的第4行,您可能会看到require 'ci/reporter/rake/rspec'。出于某种原因,此Gem在部署时不可用。我的猜测是gem 'ci_reporter_rspec'不在你的Gemfile中(或者在:development不可用的组中)。通过添加(或移动)Gem,它可能会起作用。

祝你好运!