使用 Capistrano 部署 Rails 5.1 / Webpacker 应用程序

2024-04-01

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

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

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

Gemfile

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}

当我在资产中执行 cap 部署时出现问题:预编译步骤。接下来你有错误日志。

终端日志

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/

提前致谢!


我更喜欢在本地编译资产,然后使用 rsync 复制到生产服务器:

# lib/capistrano/tasks/precompile.rake
namespace :assets do
  desc 'Precompile assets locally and then rsync to web servers'
  task :precompile do
    run_locally do
      with rails_env: stage_of_env do
        execute :bundle, 'exec rake assets:precompile'
      end
    end

    on roles(:web), in: :parallel do |server|
      run_locally do
        execute :rsync,
          "-a --delete ./public/packs/ #{fetch(:user)}@#{server.hostname}:#{shared_path}/public/packs/"
        execute :rsync,
          "-a --delete ./public/assets/ #{fetch(:user)}@#{server.hostname}:#{shared_path}/public/assets/"
      end
    end

    run_locally do
      execute :rm, '-rf public/assets'
      execute :rm, '-rf public/packs'
    end
  end
end

# config/deploy.rb
after 'deploy:updated', 'assets:precompile'

在您的 Capfile 中,您需要包含所有 capistrano 任务:

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/**/*.rake').each { |r| import r }

这消除了在生产服务器上安装节点和纱线的需要。

当然你需要本地安装node和yarn

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Capistrano 部署 Rails 5.1 / Webpacker 应用程序 的相关文章

  • Rails 中的 PDF 导出

    我需要将包含一些图表的 HTML 页面导出为 PDF 有哪些好的 gem 可以做到这一点 PDFKit http railscasts com episodes 220 pdfkit http railscasts com episodes
  • 如何在 Rails 3.2.1 版本中注释 Rails 模型

    我正在尝试遵循一些在线教程来在 Rails 中注释我的模型 然而 似乎所有教程都在谈论过时的注释版本或不正确的安装 这真是一团糟 到目前为止我已经尝试过以下方法 1 在 Gemfile 中添加此内容 gem annotate 2 4 0 2
  • 忽略 git 中的本地配置文件

    Rails 应用程序中有一些本地文件 属于我们存储库的一部分 我希望 git 忽略它们 基本上 我希望 git 忽略我对 config environments 目录和 config application rb 文件中的任何内容所做的所有
  • NMCLI 设备不可用

    我正在尝试在 ubuntu core 16 04 上配置带有蜂窝接口的新设备 我有 NMCLI 包在上面运行 在添加连接之前 我检查了接口 nmcli dev DEVICE TYPE STATE CONNECTION eth1 ethern
  • 预期的 ProductField,出现数组问题

    我有一个 Rails 4 应用程序 它有一个如下所示的 params 块 def store params params require store permit name description user id products attr
  • Rails Active Admin css 与 Twitter Bootstrap css 冲突

    我对 Rails 资产管道有点陌生 所以我可能做错了什么 我正在尝试为我的后端使用 Active Admin 为我的前端应用程序使用 twitter bootstrap css 我将 bootstrap css 添加到 应用程序 资产 样式
  • Ubuntu 12.04 上的 DeepDive 安装指南

    在拥有以后很多问题 https stackoverflow com questions 22469188 deepdive installation postgresql error安装深潜项目 http deepdive stanford
  • 如何更改 Ubuntu 14.04 上的 php-cli 版本?

    我是 Linux 新手 在篡改时破坏了一些 php 设置 如果我执行一个包含以下内容的 php 脚本 phpinfo 它显示 php 版本为 5 6 但通过命令行 如果我运行php v它返回 7 0 版本 我想让两个版本匹配 我怎样才能修复
  • Rubymine 6 更新/刷新 Rails 项目中可用的方法和路径?

    这是一个例子 假设我更新路线resources foo这给我带来了一些新的道路 例如 new foo session当我开始在 ERB 视图中输入路径时 我希望它向我显示 建议自动完成与路径匹配的名称 当我输入 new foo 我会得到所有
  • 如何从引擎覆盖 Rails 应用程序路由?

    我有一个 Rails 应用程序 我正在尝试将 Rails 引擎集成到其中 主机应用程序有一些捕获所有路由 magic urls match gt admin rendering show match path edit gt admin r
  • Rails 5.1 CORS - 如何为不同环境设置不同来源

    我正在使用带有 Rail 5 1 API 的rack cors gem 根据文档 我有以下初始化程序 配置 初始化器 cors rb module Api Rails application config middleware insert
  • Ruby on Rails:如何使用 TCP 套接字连接 GPS 设备

    ruby 2 3 0p0 2015 12 25 修订版 53290 x86 64 linux 轨道 4 2 4 我正在使用 cloud9 IDE 和 webrick 服务器 我的项目是实时跟踪GPS 我想使用TCP连接与GPS跟踪设备进行通
  • 如何使用 Rspec 测试具有嵌套路由的控制器?

    我有 2 个使用轨道脚手架生成器创建的控制器 我希望它们嵌套在一个名为 demo 的文件夹中 所以运行 rails g scaffold demo flows rails g scaffold demo nodes 然后我决定将节点嵌套在流
  • 如何在不反编译的情况下更改已编译的.class文件?

    我想更改 class 文件方法 我安装 JD Eclipse Decompiler 并打开 class 文件 我添加了一些代码并保存 class 文件 但是 class 文件没有改变 我不知道如何使用反编译器 如果可能的话 如何在不使用反编
  • Rails - 渲染:目标锚标记的操作?

    我希望像这样使用渲染 render action gt page form 我也尝试过这个 render template gt site page form 那也没用 这个特定页面上的表单位于最底部 如果提交时发生任何错误 我不希望用户被
  • SSH 无法对 [email protected] 进行身份验证

    最近 我在 Github com 上注册了一个免费计划 我按照他们的说明生成 ssh 密钥以添加到我的帐户 然而 当我尝试ssh v email protected cdn cgi l email protection 我收到此错误 deb
  • css-loader 不导入 .css 文件返回空对象

    从 css 文件导入样式 返回空对象 看来 css loader 无法正常工作 谁可以帮我这个事 请找到下面的参考文件 index js import React from react import style from header cs
  • 如何加载页面特定的rails 4 js文件?

    我正在阅读资产管道的 Rails 指南文档 它指出 CoffeeScript 页面特定生成的文件 如果清单上有 require tree 指令 则默认情况下可供用户使用 这对我不起作用我必须包括这个 在特定控制器上 我缺少什么 资产管道会将
  • RoR - Rails 中的大文件上传

    我有一个 Rails Web 应用程序 允许用户上传视频 视频存储在 NFS 安装的目录中 当前的设置适用于较小的文件 但我也需要支持大文件上传 最多 4GB 当我尝试上传 4GB 文件时 它最终会发生 但从用户体验的角度来看很糟糕 上传开
  • 将rails_admin 与rails_api 结合使用

    我最初将此发布为Rails api GitHub 上的问题 https github com sferik rails admin issues 2617 但由于不活跃 我现在将其发布在这里 我正在尝试使用rails admin使用 Rai

随机推荐

  • Tensorflow 相当于 numpy.diff

    是否存在相当于的张量流numpy diff https docs scipy org doc numpy reference generated numpy diff html 计算沿给定轴的第 n 个离散差值 对于我的项目 我只需要 n
  • ARM 9处理器的opencv交叉编译

    我需要为 ARM 9 处理器交叉编译 opencv 我有处理器的工具链 但不知道如何交叉编译 请告诉我为arm板交叉编译的过程 谢谢大家 看这个参考 http www airs com ian configure configure 5 h
  • 在 Android 中使用签名 URL 从 Amazon S3 + CloudFront 播放 m3u8

    我能够使用签名 URL 访问播放列表文件 m3u8 但问题是 要访问播放列表中的流文件 ts 每个文件的 URL 也需要签名 例如 我可以使用签名 URL 访问 playlist m3u8 EXTM3U EXT X TARGETDURATI
  • 在模态 JDialog 之外时光标不正确?

    使用方法时setCursor 要更改组件使用的光标 所有组件都可以正常工作 包括JFrame and JDialog 这里的问题在于modal JDialog 当鼠标处于inside对话框中 光标显示在右侧 但是 当鼠标移动时outside
  • 使用 AngularJS 和 ngResource 调用外部 api

    我们目前正在开发一个小型 AngularJS 项目 并从前端开始 所以纯 HTML 和 JavaScript 然而 我们需要使用 ngResource 进行一些 API 调用 目前我们正在使用canned http github com s
  • 将 Google Apps API 密钥与距离矩阵结合使用

    我正在使用谷歌距离矩阵 API https developers google com maps documentation distancematrix 并且文档告诉我我需要一个 API 密钥 但我可以在没有 API 密钥的情况下使用它
  • 当 AngularJS 中的响应为 304(未修改)时,$http 返回错误

    我正在使用 angularjs http 向 asp net web api 发出请求 服务器上的 Web API 通过 ETag 管理缓存 如果我的响应状态代码是 304 那么它会进入错误函数 而不是成功函数 我不明白 AngularJS
  • 在 DataGrid 工具栏的弹出组件 Material-UI 中添加自定义样式

    我正在创建一个自定义Data Grid Toolbar通过修改现有组件Grid Toolbar组件来自材质 UI https v4 mui com Here https v4 mui com components data grid fil
  • WWW::Mechanize::Timed https 超时不起作用

    所以我在互联网上研究了这个问题 至少我是这么认为的 我正在尝试设置一个alarm超时 60 秒get 但它不会被捕获 并且会运行超过 60 秒 而且每当 www mechanized timed 构造函数达到默认超时 180 秒 时 我都会
  • Discord.py 机器人没有响应

    我对discord py相对较新 我正在制作一个机器人 但是使用某些命令或我放置的东西 机器人停止响应命令 当它以前工作时 我不知道如何修复它 机器人开启 但不响应任何命令 这是新的区域 import os import discord f
  • C#列表覆盖问题[重复]

    这个问题在这里已经有答案了 我有一些代码如下所示 用于写入 a 的值gridview到如图所示的列表 该代码确实获得了正确的值 但是当网格的第二行添加到列表中时 它会覆盖列表的第一行 有人知道为什么会发生这种情况吗 C Code List
  • 如何在 SQL 中识别连续日期组?

    我正在尝试编写一个函数来识别日期组并测量该组的大小 到目前为止 我一直在 Python 中按程序执行此操作 但我想将其移至 SQL 中 例如 列表 Bill 01 01 2011 Bill 02 01 2011 Bill 03 01 201
  • 角度标记错误

    我突然得到这个 它不允许我正确使用我的传单地图 每次我单击地图时 都会将一个标记添加到相同的坐标 当我尝试使用函数删除标记时 它会清空标记数组 但标记在地图上仍然可见 这是怎么回事 Error parse syntax Syntax Err
  • Django 预关闭钩子关闭挂起的 pymongo 连接

    我在 Django 项目中使用 pymongo 最近我开始遇到一个问题 在退出主 Django 进程 即使通过管理命令 时 pymongo 连接将挂起 并且该进程永远不会退出 显然 堆栈中的某个地方出了问题 但目前最好的解决方案似乎是在 D
  • @UsePipes(ValidationPipe) 不适用于泛型(抽象控制器)

    我正在使用构建 APINest js和MySQL 由于敏捷性和 DRY 原则 我正在创建一个 OOP 结构 它为给定实体 来自 TypeORM 设置所有基本 CRUD 端点 主要目标是避免为不同的实体编写相同的通用方法 为了实现这一目标 我
  • 有没有办法在 VAR 模型中挑选滞后变量?

    我对每日数据的两个时间序列进行建模 一是注册 二是订阅的终止 我想使用 VAR 模型的两个变量中包含的信息来预测后者varsR 中的包 由于我正在对订阅进行建模 因此我知道终止与前几个月的注册倍数相关 也就是说 5 月 10 日的注册人数激
  • document.execCommand() FontSize(以像素为单位)?

    如何使用以下命令将字体大小更改为 30px 例如 document execCommand This document execCommand fontSize false 30px 不起作用 因为在函数 execCommand 的第三个参
  • 在 Java 中执行身份验证加密的正确方法是什么?

    验证加密要求我们使用一些公认的标准来加密和验证消息 因此 我们对消息进行加密并计算消息的 MAC 以验证它没有被篡改 这个问题 https stackoverflow com questions 992019 java 256 bit ae
  • 如何使用 Xcode 6.3 Beta2 覆盖 Swift 中超类的 setter?

    我的 SuerClass 是UICollectionViewCell它有一个属性 var selected Bool 我的班级是 MyClass UICollectionViewCell func setSelected selected
  • 使用 Capistrano 部署 Rails 5.1 / Webpacker 应用程序

    我有一个 Ubuntu 服务器来部署我的 Rails 项目 在我的 Ubuntu 服务器中 我有 RVM 现在我想使用 Rails 5 1 和 webpacker 部署新项目 为了部署这个项目 我在我的 Ubuntu 服务器中安装了 NVM