“使用Capistrano在EC2上部署Rails 3应用程序时,请在Capistrano配方中请求此文件”错误

时间:2015-03-17 14:15:19

标签: ruby-on-rails ruby-on-rails-3 amazon-ec2 capistrano

在部署Rails 3应用程序时,我们遇到以下错误。请帮助解决此问题。

$ cap deploy
    triggering load callbacks
  * 2015-03-17 19:25:22 executing `deploy'
  * 2015-03-17 19:25:22 executing `deploy:update'
 ** transaction: start
  * 2015-03-17 19:25:22 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@github.com:BoTreeConsultingTeam/IntegrityMatters.git master"
    command finished in 3579ms
  * executing "if [ -d /home/ubuntu/integrity_matters/shared/cached-copy ]; then cd /home/ubuntu/integrity_matters/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard eb49600f7de21f4b2b1de8884f70dd5a88837f41 && git clean -q -d -x -f; else git clone -q -b master git@github.com:BoTreeConsultingTeam/IntegrityMatters.git /home/ubuntu/integrity_matters/shared/cached-copy && cd /home/ubuntu/integrity_matters/shared/cached-copy && git checkout -q -b deploy eb49600f7de21f4b2b1de8884f70dd5a88837f41; fi"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 4644ms
    copying the cached version to /home/ubuntu/integrity_matters/releases/20150317135535
  * executing "cp -RPp /home/ubuntu/integrity_matters/shared/cached-copy /home/ubuntu/integrity_matters/releases/20150317135535 && (echo eb49600f7de21f4b2b1de8884f70dd5a88837f41 > /home/ubuntu/integrity_matters/releases/20150317135535/REVISION)"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 1212ms
  * 2015-03-17 19:25:36 executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * 2015-03-17 19:25:36 executing `deploy:assets:symlink'
  * executing "rm -rf /home/ubuntu/integrity_matters/releases/20150317135535/public/assets && mkdir -p /home/ubuntu/integrity_matters/releases/20150317135535/public && mkdir -p /home/ubuntu/integrity_matters/shared/assets && ln -s /home/ubuntu/integrity_matters/shared/assets /home/ubuntu/integrity_matters/releases/20150317135535/public/assets"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 986ms
  * 2015-03-17 19:25:37 executing `bundle:install'
  * executing "cd /home/ubuntu/integrity_matters/releases/20150317135535 && bundle install --gemfile /home/ubuntu/integrity_matters/releases/20150317135535/Gemfile --path /home/ubuntu/integrity_matters/shared/bundle --deployment --quiet --without development test"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 1302ms
  * executing "chmod -R -- g+w /home/ubuntu/integrity_matters/releases/20150317135535 && rm -rf -- /home/ubuntu/integrity_matters/releases/20150317135535/public/system && mkdir -p -- /home/ubuntu/integrity_matters/releases/20150317135535/public/ && ln -s -- /home/ubuntu/integrity_matters/shared/system /home/ubuntu/integrity_matters/releases/20150317135535/public/system && rm -rf -- /home/ubuntu/integrity_matters/releases/20150317135535/log && ln -s -- /home/ubuntu/integrity_matters/shared/log /home/ubuntu/integrity_matters/releases/20150317135535/log && rm -rf -- /home/ubuntu/integrity_matters/releases/20150317135535/tmp/pids && mkdir -p -- /home/ubuntu/integrity_matters/releases/20150317135535/tmp/ && ln -s -- /home/ubuntu/integrity_matters/shared/pids /home/ubuntu/integrity_matters/releases/20150317135535/tmp/pids"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 982ms
    triggering after callbacks for `deploy:finalize_update'
  * 2015-03-17 19:25:39 executing `deploy:symlink_config'
  * executing "ln -nfs /home/ubuntu/integrity_matters/shared/config/database.yml /home/ubuntu/integrity_matters/releases/20150317135535/config/database.yml"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 976ms
    triggering after callbacks for `deploy:update_code'
  * 2015-03-17 19:25:40 executing `deploy:assets:precompile'
    triggering before callbacks for `deploy:assets:precompile'
  * 2015-03-17 19:25:40 executing `deploy:assets:update_asset_mtimes'
  * executing "[ -e /home/ubuntu/integrity_matters/shared/assets/manifest* ] && cat /home/ubuntu/integrity_matters/shared/assets/manifest* || echo"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 991ms
  * executing "cd -- /home/ubuntu/integrity_matters/releases/20150317135535 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] rake aborted!
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] Please require this file from within a Capistrano recipe
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/capistrano-2.15.5/lib/capistrano/configuration/loading.rb:18:in `instance'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/rvm-capistrano-1.5.1/lib/rvm/capistrano/helpers/base.rb:16:in `rvm_with_capistrano'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/rvm-capistrano-1.5.1/lib/rvm/capistrano/helpers/_cset.rb:3:in `<top (required)>'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `block in require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/rvm-capistrano-1.5.1/lib/rvm/capistrano/base.rb:1:in `<top (required)>'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `block in require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/rvm-capistrano-1.5.1/lib/rvm/capistrano/selector.rb:1:in `<top (required)>'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.r
 ** [out :: 52.10.245.227] b:251:in `block in require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/shared/bundle/ruby/2.2.0/gems/rvm-capistrano-1.5.1/lib/rvm/capistrano.rb:3:in `<top (required)>'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/.rvm/gems/ruby-2.2.0/gems/bundler-1.8.5/lib/bundler/runtime.rb:85:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/.rvm/gems/ruby-2.2.0/gems/bundler-1.8.5/lib/bundler/runtime.rb:85:in `rescue in block in require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/.rvm/gems/ruby-2.2.0/gems/bundler-1.8.5/lib/bundler/runtime.rb:68:in `block in require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/.rvm/gems/ruby-2.2.0/gems/bundler-1.8.5/lib/bundler/runtime.rb:61:in `each'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/.rvm/gems/ruby-2.2.0/gems/bundler-1.8.5/lib/bundler/runtime.rb:61:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/.rvm/gems/ruby-2.2.0/gems/bundler-1.8.5/lib/bundler.rb:134:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/releases/20150317135535/config/application.rb:7:in `<top (required)>'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/releases/20150317135535/Rakefile:5:in `require'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] /home/ubuntu/integrity_matters/releases/20150317135535/Rakefile:5:in `<top (required)>'
 ** [out :: 52.10.245.227] 
 ** [out :: 52.10.245.227] (See full trace by running task with --trace)
 ** [out :: 52.10.245.227] 
    command finished in 2630ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/ubuntu/integrity_matters/releases/20150317135535; true"
    servers: ["52.10.245.227"]
    [52.10.245.227] executing command
    command finished in 1025ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'default' -c 'cd -- /home/ubuntu/integrity_matters/releases/20150317135535 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile'" on 52.10.245.227

的Gemfile

gem 'capistrano'
gem 'capistrano-ext'
gem 'rvm-capistrano', require: false

deploy.rb

require "bundler/capistrano"
require "rvm/capistrano"

server "IP_ADDRESS", :web, :app, :db, primary: true

set :application, "integrity_matters"
set :user, "ubuntu"
ssh_options[:keys] = ["~/.ssh/im_ec2_free.pem"]
set :deploy_to, "/home/#{user}/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@github.com:BoTreeConsultingTeam/IntegrityMatters.git"
set :branch, "master"


default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases
after "deploy", "deploy:migrate"

namespace :deploy do
  # Reference: https://www.ruby-forum.com/topic/85305
  task :symlink_assets, :roles => [:app, :db, :web] do
    run "ln -nfs #{shared_path}/assets #{deploy_to}/assets"
  end
  after "deploy", "deploy:symlink_assets"

  # Reference: http://stackoverflow.com/a/11462003/936494
  task :cold do
    transaction do
      update
      setup_db  #replacing migrate in original
      start
    end
  end

  task :setup_db, :roles => :app do
    raise RuntimeError.new('db:setup aborted!') unless Capistrano::CLI.ui.ask("About to `rake db:setup`. Are you sure to wipe the entire database (anything other than 'yes' aborts):") == 'yes'
    run "cd #{current_path}; bundle exec rake db:setup RAILS_ENV=#{rails_env}"
  end

  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"
  after "deploy", "deploy:assets:precompile"
end

Capfile

load 'deploy' if respond_to?(:namespace) # cap2 differentiator

# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'

Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }

load 'config/deploy' # remove this line to skip loading any of the default tasks

$ gem list | grep bundler
bundler (1.8.5, 1.3.5)
bundler-unload (1.0.1)
rubygems-bundler (1.2.2)

application.rb中

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module IntegrityMatters
  class Application < Rails::Application
    config.time_zone = 'Mumbai'

    config.encoding = "utf-8"

    config.filter_parameters += [:password]

    config.active_support.escape_html_entities_in_json = true

    config.active_record.whitelist_attributes = true

    config.assets.enabled = true

    config.assets.version = '1.0'

    config.i18n.enforce_available_locales = false

    config.assets.initialize_on_precompile = false
  end
end

2 个答案:

答案 0 :(得分:6)

这是一个非常愚蠢的错误。将require:false添加到gem rvm-capistrano

后,我忘了推送Gemfile

答案 1 :(得分:4)

我有相同的错误消息,但有不同的问题。

如果您遇到像我这样的问题,请按以下步骤修复:

gem 'capistrano'
gem 'capistrano-ext'
gem 'rvm-capistrano'

rvm-capistrano之前移动capistrano ,如下所示:

gem 'rvm-capistrano'
gem 'capistrano'
gem 'capistrano-ext'