【问题标题】:Rails, Capistrano - Compilation failed without serving any debug logRails,Capistrano - 编译失败,没有提供任何调试日志
【发布时间】:2018-10-16 22:02:45
【问题描述】:

我正在尝试使用 Capistrano3 将我的 Rails5 应用程序部署到 AWS EC2 实例。 但是,当涉及资产编译时,它会在没有记录任何原因的情况下失败。 在这种情况下我应该从哪里开始? 虽然我将log_level: :debug 设置为config/deploy/staging.rb,但没有更多信息。 log/capistrano.log也一样。

我尝试在本地运行bundle exec rake assets:precompile RAILS_ENV=staging并成功。

"log/capistrano.log" 50149L, 2790165C


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:


 DEBUG [39e6a15a]



 DEBUG [39e6a15a]

 DEBUG [39e6a15a]   warning " > webpack-cli@2.1.3" has incorrect peer dependency "webpack@^4.0.0".

 DEBUG [39e6a15a]

[4/4] Building fresh packages...

success Saved lockfile.



 DEBUG [39e6a15a]

 DEBUG [39e6a15a]   Done in 38.64s.

 DEBUG [39e6a15a]

 DEBUG [39e6a15a]   Webpacker is installed ???? ????

 DEBUG [39e6a15a]

 DEBUG [39e6a15a]   Using /home/deploy/apps/neuroweb/releases/20180507061527/config/webpacker.yml file for setting up webpack paths

 DEBUG [39e6a15a]

 DEBUG [39e6a15a]   Compiling…

 DEBUG [39e6a15a]

 DEBUG [39e6a15a]   Compilation failed:

我用来部署的宝石:

  gem 'capistrano'
  gem 'capistrano-rails'
  gem 'capistrano-bundler'
  gem 'capistrano-rbenv'
  gem 'capistrano3-unicorn'

config/deploy/staging.rb

lock "3.10.2"

set :log_level, :debug
set :repo_url,        'xxxxxxxx'
set :application,     'neuroweb'
set :branch, 'staging'
set :keep_releases, 1
set :rbenv_ruby, '2.4.3'

# Don't change these unless you know what you're doing
set :use_sudo,        false
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/deploy/apps/#{fetch(:application)}"


#set :linked_dirs, %w{vendor/bundle}
#set :linked_files, %w{ config/secrets.yml}
append :linked_files, ".env"
set :rbenv_type, :user


set :ssh_options, {
  port: 22,
  forward_agent: true,
  keys: ['~/.ssh/staging.pem'],
}
set :pty, true
server 'xxxx', roles: [:web, :app, :db], primary: true, user: 'ubuntu'
set :keep_releases, 1

set :stage, :staging
set :rails_env, 'staging'
set :unicorn_exec, -> { "unicorn_rails" }
set :unicorn_config_path, -> { File.join(current_path, "config", "unicorn",  "staging.rb") }
set :unicorn_rack_env, 'staging'
set :user,            'ubuntu' #deploy
set :unicorn_pid, "/home/deploy/apps/neuroweb/shared/tmp/pids/unicorn.pid"




namespace :deploy do
  desc "Upload secrets.yml to the shared/config directory."
  task :secrets_yml do
    unless File.exist?('tmp/secrets.yml')
      secrets = { fetch(:stage).to_s =>
        { 'secret_key_base' => SecureRandom.hex(64) } }
      File.open('tmp/secrets.yml', 'w') do |f|
        f.write secrets.to_yaml
      end
    end

    on roles(:app) do
      unless test "[ -f #{shared_path}/config/secrets.yml ]"
        unless test "[ -d #{shared_path}/config ]"
          execute "/bin/mkdir -p #{shared_path}/config/"
        end
        upload! "tmp/secrets.yml", "#{shared_path}/config/secrets.yml"
      end
    end

  end # secrets_yml





  #
  # delayed_job
  #
  task :restart do
    invoke 'unicorn:restart'
    invoke 'delayed_job:restart'
  end
end #deploy


namespace :delayed_job do

  def args
    fetch(:delayed_job_args, "")
  end

  def delayed_job_roles
    fetch(:delayed_job_server_role, :app)
  end

  desc 'Stop the delayed_job process'
  task :stop do
    on roles(delayed_job_roles) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :bundle, :exec, :'bin/delayed_job', :stop
        end
      end
    end
  end

  desc 'Start the delayed_job process'
  task :start do
    on roles(delayed_job_roles) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :bundle, :exec, :'bin/delayed_job', args, :start
        end
      end
    end
  end

  desc 'Restart the delayed_job process'
  task :restart do
    on roles(delayed_job_roles) do
      within release_path do
        with rails_env: fetch(:rails_env) do
          execute :bundle, :exec, :'bin/delayed_job', args, :restart
        end
      end
    end
  end

end


after 'deploy:publishing', 'deploy:restart'

webpacker.yml

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  extensions:
    - .jsx
    - .vue
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: /node_modules/


test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default
  compile: false
  cache_manifest: true

staging:
  <<: *default
  compile: false
  cache_manifest: true

【问题讨论】:

  • 您的服务器有多少内存?可能是您在资产编译期间内存不足。
  • @NARKOZ 谢谢,我正在使用 t2.medium 实例,所以 4GiB 内存和运行编译时 free -m 的结果是 ~$ free -m total 1998 used 1658 free 74 buff 121 swap 0

标签: ruby-on-rails webpack capistrano asset-pipeline assets


【解决方案1】:

尝试在服务器上直接运行 ./bin/webpack。

我遇到了同样的问题,这向我显示了一条错误消息。

【讨论】:

  • 或者更好的./bin/webpack --progress关注编译进度
【解决方案2】:

这可能是由于内存不足造成的。

在您的系统日志中查找类似内容以确认:

Out of memory: Kill process 2736 (node) score 222 or sacrifice child

解决方案是升级到内存更大的机器(或虚拟机)。

【讨论】:

  • 谢谢@Robin,这很有帮助
猜你喜欢
  • 2019-11-21
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
  • 2011-05-17
  • 2014-12-08
  • 1970-01-01
相关资源
最近更新 更多