【问题标题】:Capistrano 3.0 assets:precompile failed on railsCapistrano 3.0 资产:预编译在轨道上失败
【发布时间】:2014-01-01 19:31:53
【问题描述】:

我尝试了几种使用 Capistrano v3 部署到我的服务器的方法,但它失败并出现以下错误; 我曾尝试在本地预编译,但失败了。

DEBUG [4ec78ee3] Command: cd /var/www/html/webapp/releases/20140101221937 && bundle exec rake assets:precompile RAILS_ENV=production
DEBUG [4ec78ee3]    /usr/local/bin/ruby /var/www/html/webapp/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
DEBUG [4ec78ee3]    rake aborted!
DEBUG [4ec78ee3]    undefined method `fetch' for false:FalseClass

我的部署文件如下所示;

SSHKit.config.command_map[:rake] = "bundle exec rake"

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
       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:cleanup'

end

这里有详细的踪迹;

INFO [4ec78ee3] Running bundle exec rake assets:precompile RAILS_ENV=production on 208.68.39.56
DEBUG [4ec78ee3] Command: cd /var/www/html/webapp/releases/20140101221937 && bundle exec rake assets:precompile RAILS_ENV=production
DEBUG [4ec78ee3]    /usr/local/bin/ruby /var/www/html/webapp/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
DEBUG [4ec78ee3]    rake aborted!
DEBUG [4ec78ee3]    undefined method `fetch' for false:FalseClass
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:35:in `resolve_string_connection'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:25:in `each'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
DEBUG [4ec78ee3]    /var/www/html/webapp/releases/20140101221937/config/environment.rb:5:in `<top (required)>'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
DEBUG [4ec78ee3]    Tasks: TOP => environment
DEBUG [4ec78ee3]    (See full trace by running task with --trace)
DEBUG [4ec78ee3]    rake aborted!
DEBUG [4ec78ee3]    Command failed with status (1): [/usr/local/bin/ruby /var/www/html/webapp/s...]
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:12:in `ruby_rake_task'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
DEBUG [4ec78ee3]    /var/www/html/webapp/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
DEBUG [4ec78ee3]    Tasks: TOP => assets:precompile
DEBUG [4ec78ee3]    (See full trace by running task with --trace)

我已经运行cap production deploy:compile_assets

得到了这个; 上限中止!

if test ! -d /var/www/html/webapp/current; then echo "Directory does not exist '/var/www/html/webapp/current'" 1>&2; false; fi stdout: Nothing written
if test ! -d /var/www/html/webapp/current; then echo "Directory does not exist '/var/www/html/webapp/current'" 1>&2; false; fi stderr: Nothing written

记住,它仍然是一个空文件。

【问题讨论】:

  • 你能得到更好的堆栈跟踪吗?错误undefined method 'fetch' for false:FalseClass 出现在哪个文件中?顺便说一句,当预期的 Capistrano 变量未定义时,Capistrano 3 往往会给出神秘的错误消息,而 fetch 是获取 Capistrano 变量的一种方法。
  • @DavidGrayson,我添加了详细的跟踪..

标签: ruby-on-rails capistrano capistrano3


【解决方案1】:

这不是一个完整的答案,而是故障排除的第一步。

首先,转到服务器并运行 Capistrano 正在运行的完全相同的命令,以确保您可以重现完全相同的错误。这将 Capistrano 排除在外,现在该错误仅与 Rails 及其配置有关。

这是引发错误的行:

https://github.com/rails/rails/blob/v3.2.13/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb#L35

错误消息告诉我们configurations 是假的,但代码期望它是响应fetch 的某个对象(可能是哈希)。问题是这个ActiveRecord::Base::ConnectionSpecification::Resolver 中的@configurations 实例变量被错误地设置为false。你知道为什么会这样吗?我会检查所有与数据库连接有关的配置文件,并确保它们看起来正常。

如果这没有帮助,下一步是找出为什么该变量被设置为false。好吧,如果我们在堆栈跟踪中向下看两行,我们可以看到这个 Resolver 对象是如何创建和使用的:

https://github.com/rails/rails/blob/v3.2.13/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb#L129-130

该方法只是调用 ActiveRecord::Base.configurations 并将其传递给 Resolver 对象。那么现在问题变成了ActiveRecord::Base.configurations 是如何设置为 false 的?

编辑 1:

这是ActiveRecord::Base.configurations的文档和代码:

https://github.com/rails/rails/blob/v3.2.13/activerecord/lib/active_record/base.rb#L341-369

听起来ActiveRecord::Base.configurations 应该来自您的 database.yml 文件。您应该去您的服务器并仔细查看您的 database.yml 文件,看看它是否可能以某种方式被读取为错误。您应该在此处发布该文件。

【讨论】:

  • 谢谢...现在我又遇到了一个奇怪的错误,不知道你能不能帮忙。在deploy:assets:backup_manifest cd /var/www/html/webapp/releases/20140102101731 &amp;&amp; /usr/bin/env cp /var/www/html/webapp/releases/20140102101731/public/assets/manifest*.json /var/www/html/webapp/releases/20140102101731/assets_manifest_backup.json 处部署失败
  • 这可以使用与我上面解释的类似的故障排除策略进行调试。
  • 我尝试过类似的方法...最困扰的是在 rails 3.2 manifest.yml 中不存在 manifest.*json
  • 我认为 manifest.yml 是 Rails 资产管道的一部分,您看到的 JSON 文件是 Capistrano 资产跟踪的一部分。 Capistrano 知道如何部署、回滚和清理 Rails 资产有点棘手,而这些文件对于存储有关资产的元数据是必需的。
猜你喜欢
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
  • 2019-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-25
  • 1970-01-01
相关资源
最近更新 更多