使用 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 应用程序 的相关文章

  • 错误“未初始化常量 AWS (NameError)”

    它说 AWS 未初始化 我正在使用 aws sdk core gem 我尝试使用 aws sdk gem 代替 问题仍然存在 这是initializers aws rb 文件 AWS config access key id gt ENV
  • Memcachier 达到缓存限制时 Heroku 请求超时

    我使用 Memcachier Dalli 作为客户端 将 Rails 应用程序部署到 Heroku 我正在使用免费插件 提供 25 MB 缓存 我们开始收到来自heroku的请求超时 经过调试 我们发现手动刷新Memcachier解决了问题
  • Rails 3 - “无法解析 Yaml”

    我不知道我做错了什么 我尝试运行 rails c 但它只是给了我一个错误 10 分钟前它还在工作 C Ruby192 lib ruby 1 9 1 psych rb 148 in parse couldn t parse YAML at l
  • 使用 VirtualDocumentRoot 的 SSL 虚拟主机

    我在 ubuntu 16 04 VM 上进行开发工作 当我处理多个项目时 为了让我的生活更轻松 我使用 VirtualDocumentRoot 和主机文件使用 dev 域从我的主文件夹中服务器站点 在 000 default conf 我有
  • 自定义变形在rails3上不起作用?

    我正在使用 Rails 3 0 1 并在initializers inflections rb 中有以下代码 ActiveSupport Inflector inflections do inflect inflect irregular
  • HABTM 关系和accepts_nested_attributes_for

    我有一个可以让我创建的表单新博客文章我希望能够创造新类别来自同一个表格 我在帖子和类别之间有一个习惯关系 这就是我遇到麻烦的原因 我有以下2个型号 class Post lt ActiveRecord Base has and belong
  • 在 Rails 中禁用连接池以使用 PgBouncer

    我们有一个 Ruby on Rails 4 2 8 项目 可以访问大型 PostgreSQL 数据库 我们将使用 PgBouncer 添加一个新的连接池服务器 由于 PgBouncer 将处理数据库连接池 我们是否需要关闭 Rails 自动
  • gitlab 上的权限被拒绝(公钥)

    我的问题是我无法从 GitLab 推送或获取 不过 我可以克隆 通过 HTTP 或通过 SSH 当我尝试推送时出现此错误 权限被拒绝 公钥 致命 无法从远程存储库读取 从我看过的所有线程中 这是我所做的 在我的计算机上设置 SSH 密钥并将
  • kaminari ajax 分页不更新分页

    我正在使用 kaminari gem 在 Rails3 中实现分页 我一直在关注github上的这段代码https github com amatsuda kaminari example commits ajax https github
  • 使用复选框过滤列表

    我有一个电影列表及其评级 在我的页面顶部 我有一个表单 其中提供了一个复选框列表 其中显示了每个可用的评级 G PG 13 等 一旦用户单击复选框并点击提交 我只想显示所选的电影 在我的索引方法中 我有一个名为的实例变量 filtered
  • RSpec 请求规范发布一个空数组

    我目前正在 Rails 中开发 API 端点 如果我需要的数据无效 我想确保端点响应具有正确的错误状态 我需要一个 id 数组 无效值之一是空数组 Valid vendor district ids 2 4 5 6 Invalid vend
  • Lodash 不是使用 Webpack 和 Webpack 4 进行 TreeShaking 吗?

    我想要摇树lodash以及我未使用的multiply生成的包中的函数webpack 我有2个主要文件app js math js 它包含以下代码 app js import map from lodash map import sum fr
  • Angular 2 - ng 构建与 webpack 构建

    我想了解构建和部署 Angular 2 Web 应用程序的最佳方法是什么 我最终需要将其作为 Web 捆绑资源提供给我的 dropwizard 应用程序 我试图了解是否应该保留 ng build 并使用它来生成我的 dist 文件夹 或者我
  • 为什么||和 或 在 Rails 中的行为有所不同? [复制]

    这个问题在这里已经有答案了 可能的重复 i true 和 false 在 Ruby 中是真的吗 https stackoverflow com questions 2802494 i true and false in ruby is tr
  • Eslint errorring 导入没有扩展名的 jsx

    我正在尝试在 es6 中导入 jsx 文件而不需要 jsx 扩展名 import LoginErrorDialog from LoginErrorDialogView Not import LoginErrorDialog from Log
  • 我必须使用什么加密程序来通过 HTTP 协议发送加密的“电子邮件”和“密码”值?

    我正在使用 Ruby on Rails 3 我想通过 HTTP 协议发送 电子邮件 和 密码 值 我知道 我不应该 但我需要 我需要从发送用户凭据我的客户申请到一个我的服务应用 我可以使用公共和私人RSA密钥来实现这一点 但如果是这样 我不
  • Webpack - 导出常量

    我第一次尝试从 systemjs 迁移到 webpack 在我的应用程序中 我有这样的东西 import appSettings from AppSettings 其中 AppSettings 只是一个带有 const 的文件 实际上并不是
  • 为 Angular2 中的组件加载多个样式表

    我正在构建一个 angular2 应用程序 当我尝试为同一组件加载多个样式表时 我面临多个问题 这是我正在做的代码 import Component from angular core Component selector my tag t
  • Apache 2 中的“捕获 SIGWINCH”错误是什么?

    我的服务器 ubuntu 8 04 LAMP运行drupal 6 当流量较高时 它会停止提供页面 重新启动apache2将不起作用 所以我必须重新启动该服务 我在 apache2 error log 中找到了这条消息 通知 捕获SIGWIN
  • 将 Rack::Deflater 插入机架中的哪个位置?

    我目前有以下内容 use Rack Rewrite use Rack Cache verbose gt true metastore gt memcached localhost 11211 rack cache meta entityst

随机推荐

  • 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