我有一个 Ubuntu 服务器来部署我的 Rails 项目。在我的 Ubuntu 服务器中,我有 RVM。
现在我想用 Rails 5.1 和 webpacker 部署新项目。为了部署这个项目,我在我的 Ubuntu 服务器中安装了 NVM、npm 和 yarn。
在我的 Rails 5.1 / Webpacker 项目中,我有以下用于 capistrano 部署的 gem:
宝石文件
group :development do
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano-passenger'
gem 'capistrano-nvm', require: false
gem 'capistrano-yarn'
end
在 deploy.rb 中,我为 capistrano nvm 和 capistrano yarn 添加了一些配置。
部署.rb
set :nvm_type, :user # or :system, depends on your nvm setup
set :nvm_node, 'v7.10.0'
set :nvm_map_bins, %w{node npm yarn}
set :yarn_target_path, -> { release_path.join('client') } #
set :yarn_flags, '--production --silent --no-progress' # default
set :yarn_roles, :all # default
set :yarn_env_variables, {}
我还在linked_dirs 中添加了node_modules。
部署.rb
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system node_modules client/node_modules}
当我在 assets:precompile 步骤中执行 cap deploy 时,问题就来了。接下来你有错误日志。
终端日志
00:10 deploy:assets:precompile
01 /usr/local/rvm/bin/rvm 2.4.1@project do bundle exec rake assets:precompile
01 Yarn executable was not detected in the system.
01 Download Yarn at https://yarnpkg.com/en/docs/install
01 /home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
01 Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
Node.js not installed. Please download and install Node.js
https://nodejs.org/en/download/
rake stderr: Nothing written
SSHKit::Command::Failed: rake exit status: 1
rake stdout: Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
Node.js not installed. Please download and install Node.js
https://nodejs.org/en/download/
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
Node.js not installed. Please download and install Node.js
https://nodejs.org/en/download/
rake stderr: Nothing written
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [016276ab] * spring (2.0.1)
DEBUG [016276ab] * spring-watcher-listen (2.0.1)
DEBUG [016276ab] * web-console (3.5.0)
DEBUG [016276ab] Install missing gems with `bundle install`
DEBUG [016276ab] Finished in 0.677 seconds with exit status 1 (failed).
INFO [86e74b01] Running /usr/local/rvm/bin/rvm 2.4.1@project do bundle install --path /home/deploy/rails/241/project/shared/bundle --without development test --deployment --quiet on xxx.xxx.xxx.xxx
DEBUG [86e74b01] Command: cd /home/deploy/rails/241/project/releases/20170511083021 && ( export NODE_VERSION="v7.10.0" ; /usr/local/rvm/bin/rvm 2.4.1@project do bundle install --path /home/deploy/rails/241/project/shared/bundle --without development test --deployment --quiet )
DEBUG [86e74b01] Warning, new version of rvm available '1.29.1', you are using older version '1.26.11'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
INFO [86e74b01] Finished in 3.209 seconds with exit status 0 (successful).
DEBUG [4a428031] Running if test ! -d /home/deploy/rails/241/project/releases/20170511083021; then echo "Directory does not exist '/home/deploy/rails/241/project/releases/20170511083021'" 1>&2; false; fi on xxx.xxx.xxx.xxx
DEBUG [4a428031] Command: if test ! -d /home/deploy/rails/241/project/releases/20170511083021; then echo "Directory does not exist '/home/deploy/rails/241/project/releases/20170511083021'" 1>&2; false; fi
DEBUG [4a428031] Finished in 0.066 seconds with exit status 0 (successful).
INFO [d225a8b5] Running /usr/local/rvm/bin/rvm 2.4.1@project do bundle exec rake assets:precompile on xxx.xxx.xxx.xxx
DEBUG [d225a8b5] Command: cd /home/deploy/rails/241/project/releases/20170511083021 && ( export NODE_VERSION="v7.10.0" RAILS_ENV="production" ; /usr/local/rvm/bin/rvm 2.4.1@project do bundle exec rake assets:precompile )
DEBUG [d225a8b5] Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
DEBUG [d225a8b5] /home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake: No such file or directory - node
DEBUG [d225a8b5] Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/
提前致谢!