使用Capistrano部署Rails 5.1 / Webpacker应用 [英] Deploy Rails 5.1 / Webpacker app with Capistrano

查看:53
本文介绍了使用Capistrano部署Rails 5.1 / Webpacker应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台Ubuntu服务器来部署我的Rails项目。在我的Ubuntu服务器中,我有RVM。



现在,我想使用Rails 5.1和webpacker部署新项目。为了部署这个项目,我已经在Ubuntu服务器中安装了NVM,npm和yarn。



在Rails 5.1 / Webpacker项目中,我有以下用于capistrano部署的工具: / p>

Gemfile

  group:开发吗
宝石'capistrano-rails'
宝石'capistrano-rvm'
宝石'capistrano-passenger'
宝石'capistrano-nvm',要求:假
gem' capistrano-yarn'
end

在deploy.rb中,我为capistrano添加了一些配置nvm和capistrano纱线。



deploy.rb

  set:nvm_type,:user#或:system取决于您的nvm设置
set:nvm_node,'v7.10.0'
set:nvm_map_bins,%w {node npm yarn}

set:yarn_target_path,-> {release_path.join('client')}#
设置:yarn_flags,'--production --silent --no-progress'#默认
设置:yarn_roles,:all#默认
设置:yarn_env_variables,{}

我也已在linked_dirs中添加了node_modules。



deploy.rb

  set:linked_dirs,%w {日志tmp / pids tmp / cache tmp / socket供应商/捆绑包public / system node_modules client / node_modules} 

当我在资产:预编译步骤中执行cap部署时,问题就来了。接下来,您将看到错误日志。



终端日志

  00:10 deploy:assets:precompile 
01 / usr / local / rvm / bin / rvm 2.4.1@project捆绑exec rake资产:precompile
01未检测到纱线可执行文件在系统中。
01在https://yarnpkg.com/en/docs/install上下载纱线
01 /home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake :没有这样的文件或目录-节点
01未安装Node.js。请下载并安装Node.js https://nodejs.org/en/download/
(回溯仅限于导入的任务)
上限已中止!
SSHKit :: Runner :: ExecuteError:在主机xxx.xxx.xxx.xxx上执行时发生异常:耙退出状态:1
耙标准输出:在系统中未检测到纱线可执行文件。
在https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake下载纱线此类文件或目录-未安装节点
Node.js。请下载并安装Node.js
https://nodejs.org/en/download/
rake stderr:未写任何内容

SSHKit :: Command :: Failed:rake exit状态:1
佣金标准输出:在系统中未检测到纱线可执行文件。
在https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake下载纱线此类文件或目录-未安装节点
Node.js。请下载并安装Node.js
https://nodejs.org/en/download/
rake stderr:什么都没写

任务:TOP => deploy:assets:precompile
(通过使用--trace运行任务来查看完整跟踪)
部署失败,并显示错误:在主机xxx.xxx.xxx.xxx上执行时发生异常:耙退出状态: 1
rake stdout:在系统中未检测到纱线可执行文件。
在https://yarnpkg.com/en/docs/install
/home/deploy/rails/241/project/shared/bundle/ruby/2.4.0/bin/rake下载纱线此类文件或目录-未安装节点
Node.js。请下载并安装Node.js
https://nodejs.org/en/download/
rake stderr:未写任何内容



**部署失败
**有关详细信息,请参阅log / capistrano.log。这是最后20行:


DEBUG [016276ab] *春天(2.0.1)

DEBUG [016276ab] * spring-watcher-listen(2.0 .1)

调试[016276ab] *网络控制台(3.5.0)

调试[016276ab]使用`bundle install`
$ b安装丢失的gems $ b DEBUG [016276ab]在0.677秒内完成,退出状态为1(失败)。

信息[86e74b01]运行/ usr / local / rvm / bin / rvm 2.4.1@project进行捆绑安装--path / home / deploy / rails / 241 / project / shared / bundle-未经开发测试--deployment --quiet on xxx.xxx.xxx.xxx

DEBUG [86e74b01]命令:cd / home / deploy / rails / 241 / project / releases / 20170511083021& (export NODE_VERSION = v7.10.0; / usr / local / rvm / bin / rvm 2.4.1@project捆绑安装--path / home / deploy / rails / 241 / project / shared / bundle-无开发测试--deployment --quiet)

调试[86e74b01]警告,rvm的新版本可用 1.29.1,您使用的是旧版本 1.26.11。

您可以使用以下命令禁用此警告:echo rvm_autoupdate_flag = 0>> 〜/ .rvmrc

您可以使用以下命令启用自动更新:echo rvm_autoupdate_flag = 2>> 〜/ .rvmrc

信息[86e74b01]在3.209秒内完成,退出状态0(成功)。

调试[4a428031]如果测试运行! -d / home / deploy / rails / 241 / project / releases / 20170511083021;然后回显目录不存在‘/ home / deploy / rails / 241 / project / releases / 20170511083021’ 1>& 2;假; fi on xxx.xxx.xxx.xxx

DEBUG [4a428031]命令:如果测试! -d / home / deploy / rails / 241 / project / releases / 20170511083021;然后回显目录不存在‘/ home / deploy / rails / 241 / project / releases / 20170511083021’ 1>& 2;假; fi

调试[4a428031]在0.066秒内完成,退出状态0(成功)。

信息[d225a8b5]运行/ usr / local / rvm / bin / rvm 2.4.1@project捆绑执行rake资产:在xxx.xxx.xxx.xxx上预编译

调试[d225a8b5]命令: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捆绑执行rake资产:预编译)

调试[d225a8b5]在系统中未检测到纱线可执行文件。

在https://yarnpkg.com/en/docs/install上下载纱线

调试[d225a8b5] / home / deploy / rails / 241 / project / shared / bundle /ruby/2.4.0/bin/rake:没有这样的文件或目录-节点

调试[d225a8b5]未安装Node.js。请下载并安装Node.js https://nodejs.org/en/download/

感谢

解决方案

该错误几乎告诉您什么地方出错了。在服务器上找不到Yarn或Node。您的安装可能不正确。



按照说明在此处安装它们:



https://nodejs.org/en/download/package-manager/ #debian-and-ubuntu-based-linux-distributions



在这里:



< a href = https://yarnpkg.com/lang/zh-CN/docs/install/#linux-tab rel = nofollow noreferrer> https://yarnpkg.com/lang/zh-CN/docs/install/#linux -tab



然后请确保您可以致电:

 在服务器上的
节点

如果没有,您可能需要将可执行文件的路径添加到PATH变量中


I have an Ubuntu server to deploy my Rails projects. In my Ubuntu server I had RVM.

Now I want to deploy new projects with Rails 5.1 and webpacker. To deploy this projects, I've installed NVM, npm and yarn in my Ubuntu server.

In my Rails 5.1 / Webpacker project I have following gems for capistrano deployment:

Gemfile

group :development do
  gem 'capistrano-rails'
  gem 'capistrano-rvm'
  gem 'capistrano-passenger'
  gem 'capistrano-nvm', require: false
  gem 'capistrano-yarn'
end

In deploy.rb I've added some configurations for capistrano nvm and capistrano yarn.

deploy.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, {}

Also I've added node_modules in linked_dirs.

deploy.rb

set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system node_modules client/node_modules}

The problem comes when I execute cap deploy in assets:precompile step. Next you have the error log.

terminal log

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/

Thanks in advance!

解决方案

The error tells you pretty much what's wrong. Neither Yarn or Node can be found on the server. Your installation might be incorrect.

Follow instructions to install both here:

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

and here:

https://yarnpkg.com/lang/en/docs/install/#linux-tab

Then make sure you can call:

yarn
node

On the server. If not, you might need to add paths to executables into your PATH variable

这篇关于使用Capistrano部署Rails 5.1 / Webpacker应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆