Capistrano 3部署Rails 4 binstubs冲突?

 个信2502894627 发布于 2022-12-18 18:02

我正在使用Capistrano 3和新生成的Rails 4应用程序.我的部署正在运行,但是当我bundle exec rails console在生产服务器上运行时,我收到来自Rails的警告:

看起来你的应用程序的./bin/rails是由Bundler生成的存根.

在Rails 4中,您的应用程序的bin /目录包含与任何其他源代码一样版本化的可执行文件,而不是按需生成的存根.

实际上,部署期间生成的binstub会覆盖存储库中的binstub:

原来的binstub:

$ cat bin/rails

#!/usr/bin/env ruby
begin
  load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application',  __FILE__)
require_relative '../config/boot'
require 'rails/commands'

生产中的binstub:

$ cat bin/rails

#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rails' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../releases/20140930173754/Gemfile",
  Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('railties', 'rails')

为了使Capistrano配置与Rails 4兼容,需要改变什么?

# Gemfile
group :development do
  gem 'capistrano', '~> 3.1'
  gem 'capistrano-rbenv', '~> 2.0'
  gem 'capistrano-bundler', '~> 1.1.2'
  gem 'capistrano-rails', '~> 1.1'
end

# config/deploy.rb
lock '3.2.1'
# ...
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
# ...

其他一切都使用默认设置.

1 个回答
  • 由于./bin目录是在Rails 4中受版本控制,我们需要阻止Capistrano通过删除bin来在部署中链接它set :linked_dirs.现在,为了防止bundler覆盖版本控制的binstub,我们可以添加在运行bundle install时set :bundle_binstubs, nil阻止capistrano-bundler设置--binstubs选项的行.

    希望有所帮助!

    2022-12-18 18:05 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有