【问题标题】:Rails Capistrano fails on assets:precompile SSHKITRails Capistrano 在资产上失败:预编译 SSHKIT
【发布时间】:2019-11-21 02:20:46
【问题描述】:

当我将应用程序部署到 Digital Ocean (Ubuntu 18.04) 时。部署过程失败 deploy:assets:precompile。它不提供特定的错误。我浏览了很多类似的案例,但都没有解决问题。

我检查了我的 ssh 设置,它们似乎是正确的。 ssh_config 中的#AllowAgentForwarding 设置设置为yes(本地和远程)。 ssh-add -l alsi 返回正确的 ssh 代理

有什么想法吗?感谢您的帮助!

以下是我的错误输出:


00:09 deploy:assets:precompile
      01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
      01 I, [2019-07-11T10:37:53.282876 #17762]  INFO -- sentry: ** [Raven] Raven 2.9.0 ready to catch errors
      01 yarn install v1.16.0
      01 [1/4] Resolving packages...
      01 [2/4] Fetching packages...
      01 info fsevents@1.2.9: The platform "linux" is incompatible with this module.
      01 info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
      01 info fsevents@2.0.7: The platform "linux" is incompatible with this module.
      01 info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation.
      01 [3/4] Linking dependencies...
      01 [4/4] Building fresh packages...
      01 Done in 22.00s.
      01 Compiling…
      01 Compilation failed:
      01
      01
#<Thread:0x00007fbb8d3ba470@/Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    13: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
    12: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:31:in `run'
    11: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
    10: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-rails-1.4.0/lib/capistrano/tasks/assets.rake:67:in `block (4 levels) in <top (required)>'
     9: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:92:in `within'
     8: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-rails-1.4.0/lib/capistrano/tasks/assets.rake:68:in `block (5 levels) in <top (required)>'
     7: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:100:in `with'
     6: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/capistrano-rails-1.4.0/lib/capistrano/tasks/assets.rake:69:in `block (6 levels) in <top (required)>'
     5: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:80:in `execute'
     4: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
     3: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:148:in `tap'
     2: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
     1: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/backends/netssh.rb:169:in `execute_command'
/Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/command.rb:97:in `exit_status=': rake exit status: 1 (SSHKit::Command::Failed)
rake stdout: I, [2019-07-11T10:37:53.282876 #17762]  INFO -- sentry: ** [Raven] Raven 2.9.0 ready to catch errors
yarn install v1.16.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.0.7: The platform "linux" is incompatible with this module.
info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 22.00s.
Compiling…
Compilation failed:
rake stderr: Nothing written
    1: from /Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/sebastiaan/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.19.1/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@134.209.201.210: rake exit status: 1 (SSHKit::Runner::ExecuteError)
rake stdout: I, [2019-07-11T11:12:13.618508 #20267]  INFO -- sentry: ** [Raven] Raven 2.9.0 ready to catch errors
yarn install v1.16.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.0.7: The platform "linux" is incompatible with this module.
info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 22.95s.
Compiling…
Compilation failed:
rake stderr: Nothing written

Capfile:

require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
require "capistrano/rbenv"
require "capistrano/rails"
require "capistrano/passenger"
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
set :rbenv_type, :user
set :rbenv_ruby, '2.6.3'


部署.rb

lock "~> 3.11.0"
set :application, "youba"
set :repo_url, "git@bitbucket.org:pspoppen/youba.git"
set :deploy_to, "/home/deploy/#{fetch :application}"
append :linked_files, 'config/database.yml'
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'
set :keep_releases, 10
set :ssh_options, { forward_agent: true }

Gemfile(相关宝石)

gem 'capistrano', '~> 3.11'
gem 'capistrano-rails', '~> 1.4'
gem 'capistrano-passenger', '~> 0.2.0'
gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'
gem 'webpacker', '~> 4.x'

【问题讨论】:

    标签: ruby-on-rails ruby webpack ssh capistrano


    【解决方案1】:

    尝试向您的虚拟机添加一些交换,您应该会没事的。在资产编译期间,它看起来像是用完了 RAM 并失败了。如果您有一个具有 1GB RAM 的小型 VM,就会发生这种情况。要验证.. 在您的 VM 上安装 htop (apt-get install htop) 实用程序并在部署期间打开。然后你应该看到统计数据。我曾经也有过一样的问题。我的解决方案是在本地电脑上编译并复制它们(你可以在 Capistrano 中为它做一个任务)

    【讨论】:

      【解决方案2】:

      @Nordic Panda 和@Claasz,感谢您的帮助!内存不足确实是问题所在,导致编译失败。我调整了我的 Digital Ocean 帐户的大小,现在部署工作正常了!

      在我这样做之前(仍然使用较轻的服务器)。我在本地编译资产并按照您的建议单独部署它们。这也很好用!

      【讨论】:

        【解决方案3】:

        SSH 不是你的问题。从您提供的日志来看,资产编译过程中发生了错误。

        我建议登录服务器,将项目克隆到临时目录,然后手动运行rails assets:precompile。这可能会失败,您必须找出原因。

        【讨论】:

        • 您好,感谢您的回答。我尝试在克隆的临时文件夹中进行预编译,它编译所有资产而不会失败。还有其他建议吗?
        • 您必须找出 Capistrano 环境和临时测试环境之间的区别。不同的Linux用户?不同的 PATH 或其他 ENV 变量?不同的 Rails 环境(development/production) 不同的目录结构?诸如此类。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多