我已经尽力想尽一切办法,但是我无法进行部署。
该应用需要使用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.
我想到的假设:
- RAM用完。主要发生在Digital Ocean上,提供程序排除了这种可能性,并且在将其切入服务器时仍无法编译。
-
node
与nodejs
的问题。这曾经让我很讨厌,但它不再发生了,起初是因为我只使用了链轮,并添加了mini_racer
gem,它为ExecJS打包了节点,然后因为我包括了使用webpacker而不是Sprockets的Bootstrap,从而消除了对autoprefixer-rails
,其中errors out when an old version of nodejs is present alongside node。 - Capistrano错误地解释了纱/卷装机故障的警告。我将Bootstrap提取到其自己的app / javascripts / bootstrap.js中,因为webpacker抱怨生成的JS太大,因此可以排除它。 Yarn抱怨未满足的对等依赖关系,但是这些是开发依赖关系,我认为这并不重要。 这可能是问题所在,但是我该如何测试?
- 还有什么我应该尝试的?例如,使用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
最后是我的Capfile
和deploy.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
感谢您的帮助!