【问题标题】:Capistrano complains about missing 'eventmachine' on asset precompileCapistrano 抱怨资产预编译中缺少“eventmachine”
【发布时间】:2012-06-14 06:36:05
【问题描述】:

我正在尝试按照 Ryan Bates 截屏视频部署到 VPS。

我使用 Thin 作为网络服务器,而不是独角兽,这让我很头疼...... 当它试图在服务器上编译资产时,它给了我这个:

triggering after callbacks for `deploy:update_code'
* executing `deploy:assets:precompile'
* executing "cd /home/deployer/apps/my-app/releases/20120614062157 && b
undle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
servers: ["**.**.**.**"]
[xx.xx.xx.xx] executing command
** [out :: **.**.**.**] rake aborted!
** [out :: **.**.**.**] cannot load such file -- eventmachine
** [out :: **.**.**.**]
** [out :: **.**.**.**] (See full trace by running task with --trace)
command finished in 3891ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/deployer/apps/my-app/releases/20120614062157;
true"
servers: ["**.**.**.**"]
[**.**.**.**] executing command

我无法检查是否在捆绑包中安装了 eventmachine,因为 capistrano 总是回滚所有内容,所以我实际上并没有在脚本之后安装应用程序。这使得几乎不可能进一步追溯...

所以我完全迷路了。谷歌搜索“rake assets:precompile eventmachine”不会返回任何相关内容..

感谢您的帮助。

亲切的问候 斯特凡诺

我的宝石文件:

source 'http://rubygems.org'

gem 'rails', '3.2.2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

# gem 'sqlite3'
gem 'pg'
gem 'bootstrap-sass-rails'

group :development do 
    # To generate the class diagrams.
    gem 'annotate', :git => 'git://github.com/jeremyolliver/annotate_models.git', :branch => 'rake_compatibility'
end

group :test do
    gem 'rspec-rails'
    gem 'capybara'
    gem 'spork', '0.9.0'
    gem 'factory_girl_rails'
    gem 'guard-spork', '0.3.2'
end 

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

#To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'

# Form helpers
gem 'simple_form'
gem 'country_select'

# RMagick
gem 'mini_magick'

# Active merchant
gem 'activemerchant', :require => 'active_merchant'

# To validate IBAN numbers
gem 'iban-tools'

# For the google maps stuff
gem 'gmaps4rails'

# To generate PDFs
gem 'prawn', '1.0.0.rc1'

# HAML test
gem 'haml'
gem 'haml-rails'

# For HTML emails
gem 'roadie'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# gem "thin", "1.3.1"
# gem "unicorn"

# Deploy with Capistrano
gem 'capistrano'

platform :ruby do
    gem "unicorn"
end

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

如您所见,我将瘦身换成了独角兽...我想我也将其范围缩小到 capistrano 从未真正调用捆绑安装?因为现在它抱怨没有找到 nokogiri。

我设法在共享/缓存复制目录下找到 capistrano 存储在服务器上的实际版本,并在那里进行捆绑安装工作正常!

是的,“使用 rails 部署很容易!”很容易在它上面浪费一整个星期..

如果我执行 bundle exec cap deploy,Bundle install 可以工作:

    triggering after callbacks for `deploy:finalize_update'
  * executing `bundle:install'
  * executing "ls -x /home/deployer/apps/hemd-mit-stil/releases"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 1453ms
  * executing "cd /home/deployer/apps/hemd-mit-stil/releases/20120615043946 && b
undle install --gemfile /home/deployer/apps/hemd-mit-stil/releases/2012061504394
6/Gemfile --path /home/deployer/apps/hemd-mit-stil/shared/bundle --deployment --
quiet --without development test"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 29813ms
  * executing `deploy:symlink_config'
  * executing "ln -nfs /home/deployer/apps/hemd-mit-stil/shared/config/database.
yml /home/deployer/apps/hemd-mit-stil/releases/20120615043946/config/database.ym
l"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 1484ms
    triggering after callbacks for `deploy:update_code'
  * executing `deploy:assets:precompile'
  * executing "cd /home/deployer/apps/hemd-mit-stil/releases/20120615043946 && b
undle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
 ** [out :: xx.xx.xx.xx] rake aborted!
 ** [out :: xx.xx.xx.xx] cannot load such file -- nokogiri
 ** [out :: xx.xx.xx.xx]
 ** [out :: xx.xx.xx.xx] (See full trace by running task with --trace)
    command finished in 3563ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/deployer/apps/hemd-mit-stil/releases/20120615043946;
 true"
    servers: ["xx.xx.xx.xx"]
    [xx.xx.xx.xx] executing command
    command finished in 1453ms
failed: "sh -c 'cd /home/deployer/apps/hemd-mit-stil/releases/20120615043946 &&
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on
 xx.xx.xx.xx

我的 deploy.rb 文件(基本上是从 railscasts 直接复制)

require "bundler/capistrano"

server "xx.xx.xx.xx", :web, :app, :db, primary: true

set :application, "hemd-mit-stil"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@github.com:Stefano1990/#{application}.git"
set :branch, "master"

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

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

namespace :deploy do
  %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"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

【问题讨论】:

  • 你能在本地运行 rake RAILS_ENV=production RAILS_GROUPS=assets 吗?
  • 是的,它在本地工作得很好。与此同时,我尝试在服务器上手动克隆 git 存储库,然后编译资产,效果也很好。
  • 这听起来像是 Thin 的某种问题(因为 Thin 在幕后使用 EM)。我之前没有遇到过这个问题,所以我没有答案,抱歉。
  • 我很好奇你的 Gemfile 是什么样子的
  • 您是否在进行冷部署以启动?

标签: ruby-on-rails rake capistrano asset-pipeline


【解决方案1】:

我居然发现了问题……

如果您将 Gemfile.lock 保存在您的存储库中(这是推荐的)并且您在 Windows 机器上生成 Gemfile.lock,那么您基本上就完蛋了。

来自 Windows 机器的 Gemfile.lock 将执行此操作:

bcrypt-ruby (3.0.1-x86-mingw32)

在您的生产环境 (linux) 中,这将静默失败。

“解决方案”: 不要将 Gemfile.lock 检入您的版本控制中。这可能会导致以后出现问题,但当您重新部署并且您的应用决定更新其 gems 时,因为它自己构建了 Gemfile.lock。

真正的解决方案”: 不要在 Windows 上工作。

要从存储库中删除 Gemfile.lock,请执行以下操作:

git rm Gemfile.lock

【讨论】:

  • @KimJongII,我非常爱你。至此,现在结束了在 iterwebs 上为解决此问题而进行的 5 小时搜寻。您仍然可以将 Gemfile.lock 文件检查到您的存储库中,但我在提交之前做了以下操作......在 Gemfile.lock 中替换:bcrypt-ruby (3.0.1-x86-mingw32) 与:bcrypt-ruby (3.0.1 )这非常hackish,每次运行bundle update时我都需要这样做,但我现在不在乎,我是一个快乐的人。你不喜欢近 2 年后这仍然是一个问题吗?
  • 我不会评论 bundler 的工作方式。我向打包人员提出了这个问题,但他们认为这不是问题......
【解决方案2】:

您不需要cap deploy:cold,但您需要确保您的capistrano 脚本知道bundle install。您需要做的就是require 'bundler/capistrano'。这应该会有所帮助:http://gembundler.com/deploying.html

【讨论】:

  • 恐怕还是不行..我完全重新安装了VPS,但它又卡在了同一步骤上。输出附加到我的问题。
  • 你能发布你的 deploy.rb 文件吗?我认为问题出在那儿
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-17
相关资源
最近更新 更多