【问题标题】:Rails 6 Capistrano Deployment Failure - Webpacker assets:precompileRails 6 Capistrano 部署失败 - Webpacker assets:precompile
【发布时间】:2019-10-10 10:28:47
【问题描述】:

目前我正在尝试在 Ubuntu 服务器上将我的 Rails 6 应用程序投入生产,为此,我正在使用 Capistrano。我花了一天时间准备这个项目,它运行得很好,但我无法绕过一个错误。 我按照 webpacker 上的说明链接linked_dirs 中的依赖项并在资产之前运行 yarn install:预编译,这就是我收到此错误的时候:

00:47 deploy:assets:precompile
      01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
      01 [Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
      01 I, [2019-10-10T11:01:27.724567 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/pdf-9124940acc21064e2797d4fc331490b7dd2616867e513e126f2a163025a71bc7.css
      01 I, [2019-10-10T11:01:27.725085 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/pdf-9124940acc21064e2797d4fc331490b7dd2616867e513e126f2a163025a71bc7.css.gz
      01 I, [2019-10-10T11:01:27.728319 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/MultiFactor-ec7b30855ff129ef43275ce9047d6b28196613335a7fde0aa2b9b937c7e7b0e6.png
      01 I, [2019-10-10T11:01:27.733297 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/logo-d3cf944e7b444e9265ffc5708b91386900a04c498681b2ee8b4537e92ce93757.jpg
      01 I, [2019-10-10T11:01:27.737513 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/top-1b883a805cfc1445462e1accd2d4f9db4062476e1d0ca24842f2691e8ca72231.png        
      01 I, [2019-10-10T11:01:28.315834 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/express/lib/application-9232ebdb20ad39572e70fb9e29810e63dbb63b58f5f18617c7c2bc8…
      01 I, [2019-10-10T11:01:28.316656 #10699]  INFO -- : Writing /home/deploy/webmenue/releases/20191010110029/public/assets/express/lib/application-9232ebdb20ad39572e70fb9e29810e63dbb63b58f5f18617c7c2bc8…
      01 Compiling…
      01 Compilation failed:
      01
#<Thread:0x00000000031d6db8@C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@142.93.104.71: rake exit status: 1 (SSHKit::Runner::ExecuteError)

在 StackOverflow 线程中,有人说可以,因为我使用的是 5 美元的 DigitalOcean 服务器,只有 1GB 内存?这可能是问题吗?因为 webpacker 似乎可以工作!

有什么建议吗?

谢谢!

【问题讨论】:

  • 错误本身说:尝试运行“rails generate simple_form:install”。你在本地签到生产环境了吗?

标签: ruby-on-rails ruby capistrano


【解决方案1】:

好的,在查看了 webpacker 的文档之后,我能够解决这个问题。对于以后可能遇到该问题的每个人,我将尝试解释问题所在:

我在 DigitalOcean 上运行一个只有 1GB 内存的服务器(最便宜的 5 美元),而 webpacker 的编译对于服务器来说实在是太多了。所以我决定在通过我发现的这个任务将东西上传到服务器之前进行编译:

# lib/capistrano/precompile.rake (create this file)

namespace :assets do
    desc 'Precompile assets locally and then rsync to web servers'
    task :precompile do
      run_locally do
        with rails_env: stage_of_env do
          execute :bundle, 'exec rake assets:precompile'
        end
      end

      on roles(:web), in: :parallel do |server|
        run_locally do
          execute :rsync,
            "-a --delete ./public/packs/ #{fetch(:user)}@#{server.hostname}:#{shared_path}/public/packs/"
          execute :rsync,
            "-a --delete ./public/assets/ #{fetch(:user)}@#{server.hostname}:#{shared_path}/public/assets/"
        end
      end

      run_locally do
        execute :rm, '-rf public/assets'
        execute :rm, '-rf public/packs'
      end
    end
  end

这解决了我的问题!我希望它对将来的人有所帮助!

【讨论】:

  • 这是一个 Rails 问题,它提供了更多背景信息,说明如果您不想使用具有更多资源的服务器,为什么这是一种正确的方法:github.com/rails/webpacker/issues/955
  • rsync failed with error too many auth 失败。
猜你喜欢
  • 2022-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-29
相关资源
最近更新 更多