我正在使用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} # ...
其他一切都使用默认设置.
由于./bin
目录是在Rails 4中受版本控制,我们需要阻止Capistrano通过删除bin
来在部署中链接它set :linked_dirs
.现在,为了防止bundler覆盖版本控制的binstub,我们可以添加在运行bundle install时set :bundle_binstubs, nil
阻止capistrano-bundler
设置--binstubs
选项的行.
希望有所帮助!