为什么Capistrano部署在Assets:precompile上失败而没有错误?

我已经尽力想尽一切办法,但是我无法进行部署。

该应用需要使用Capistrano进行部署,以部署到Alwaysdata托管并运行ruby 2.6.2的VPS。 这是一个Rails 6.0.2.2应用程序,对JS使用webpack,对旧脚本,所有图像和CSS使用链轮。

# On local machine (MacOS)

$ bundle exec cap production deploy
00:00 git:wrapper
00:01 git:check
00:03 deploy:check:directories
00:03 deploy:check:linked_dirs
00:03 deploy:check:make_linked_dirs
00:05 git:clone
00:06 git:update
00:08 git:create_release
00:10 deploy:set_current_revision
00:10 deploy:symlink:linked_files
00:12 deploy:symlink:linked_dirs
00:18 deploy:config:bundler
00:20 bundler:install
00:20 deploy:assets:precompile
#<Thread:0x00007fb35ba959f0@/Users/Goulven/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
/Users/Goulven/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/sshkit-1.21.0/lib/sshkit/command.rb:97:in `exit_status=': rake exit status: 1 (SSHKit::Command::Failed)
rake stdout: Nothing written
rake stderr: Nothing written

  INFO [3def24f1] Running bundle exec rake assets:precompile as vtcontrol@ssh-vtcontrol.alwaysdata.net

 DEBUG [3def24f1] Command: cd /home/www/app/releases/20200409174918 && ( export NODE_ENVironMENT="production" RAILS_ENV="production" RAILS_GROUPS="" ; bundle exec rake assets:precompile )

在本地或服务器上运行最后一个命令不会产生任何错误,只会发出警告:

# On production server:

$ cd /home/www/app/releases/20200409174918 && ( export NODE_ENVironMENT="production" RAILS_ENV="production" RAILS_GROUPS="" ; bundle exec rake assets:precompile )
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.12: The platform "linux" is incompatible with this module.
info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > webpack-dev-server@3.10.3" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
success Already up-to-date.
Done in 0.62s.

我想到的假设:

  1. RAM用完。主要发生在Digital Ocean上,提供程序排除了这种可能性,并且在将其切入服务器时仍无法编译。
  2. nodenodejs的问题。这曾经让我很讨厌,但它不再发生了,起初是因为我只使用了链轮,并添加了mini_racer gem,它为ExecJS打包了节点,然后因为我包括了使用webpacker而不是Sprockets的Bootstrap,从而消除了对autoprefixer-rails,其中errors out when an old version of nodejs is present alongside node
  3. Capistrano错误地解释了纱/卷装机故障的警告。我将Bootstrap提取到其自己的app / javascripts / bootstrap.js中,因为webpacker抱怨生成的JS太大,因此可以排除它。 Yarn抱怨未满足的对等依赖关系,但是这些是开发依赖关系,我认为这并不重要。 这可能是问题所在,但是我该如何测试?
  4. 还有什么我应该尝试的?例如,使用webpack和链轮会导致生产冲突吗?它在开发中运行良好,并且生成的资产不应相互覆盖。

以下是我的Gemfile的相关部分:

# Gemfile

# Use SCSS for stylesheets
gem 'sass-rails','>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker','~> 4.0'

group :production do
  # Used to load env vars from an .env file during deploy
  gem 'dotenv-rails'
end

group :development do
  gem 'capistrano','~> 3.13.0',require: false
  gem 'capistrano-rails','~> 1.4',require: false
  gem 'capistrano-bundler','~> 1.6',require: false
  gem 'capistrano-rails-console',require: false
end

最后是我的Capfiledeploy.rb的相关部分:

# Capfile

require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/rails/console'
require 'dotenv'
Dotenv.load
# config/deploy.rb

# Setup bundler
# Unset capistrano/bundler default flags because Bundler has deprecated them
set :bundle_flags,'--quiet'
set :bundle_path,nil
set :bundle_without,nil
before 'bundler:install','deploy:config:bundler'

# Remove gems no longer used to reduce disk space used
# This command requires loading capistrano/bundler in Capfile
after 'deploy:published','bundler:clean'

# Skip migration if files in db/migrate were not modified
# This command requires loading capistrano/rails in Capfile
set :conditionally_migrate,true

# Rails app server manages the database
set :migration_role,:app

# Defaults to nil (no asset cleanup is performed)
# If you use Rails 4+ and you'd like to clean up old assets after each deploy,# set this to the number of versions to keep
set :keep_assets,2

感谢您的帮助!

b50409346 回答:为什么Capistrano部署在Assets:precompile上失败而没有错误?

好吧,经过几天的尝试之后,我想我尝试了一些我已经测试过的东西,但是这次我想使用正确的语法,因为它现在可以工作了。

这是我需要添加到Capistrano的配置文件中的内容,以确保在部署时可以使用Yarn:

# In deploy.rb
# Add or adjust default_env to append .npm-packages to $PATH:
set :default_env,{
   PATH: '$HOME/.npm-packages/bin/:$PATH',NODE_ENVIRONMENT: 'production'
}

说明:允许VPS用户“全局”(使用npm install --global yarn安装二进制文件(如Yarn)。在后台将二进制文件安装在$HOME/.npm-packages/bin中,并将此文件夹添加到$PATH中以进行交互式/登录Shell会话。由于Capistrano竭尽全力不去处理此问题,因此我们必须在$PATH中强制输入更新后的deploy.rb

,

感谢您指出正确的方向。我有同样的错误,原来是内存问题。对于存在相同问题的任何人,请检查在编译过程中是否用free -m用完了内存。如果您用完了,会看到类似-bash: fork: Cannot allocate memory的内容。

我正在使用Digitalocean,我的解决方案是添加交换空间:https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-18-04

本文链接:https://www.f2er.com/2474608.html

大家都在问