有和没有rbenv的Rails Capistrano部署

时间:2019-07-16 06:31:19

标签: ruby-on-rails ruby capistrano rbenv

生产中的旧Rails项目没有rbenv,使用手动安装的ruby。我已经使用rbenv为它设置了一个暂存器,添加了capistrano-rbenv gem和capistrano暂存器部署配置参数。现在,即使在部署到生产环境中时,它仍然会搜索rbenv文件夹,但是它当然会失败。

有没有一种方法可以配置capistrano在部署到生产环境时不使用rbenv?

这是我当前的配置文件:

deploy.rb

# config valid only for Capistrano 3.1
lock '3.4.1'

# Git repo URL
set :repo_url, '...'

# Default value for :pty is false
set :pty, true

# Don't use sudo
set :use_sudo, false

# Default value for :linked_files is []
set :linked_files, %w{config/database.yml config/secrets.yml}

# Default value for linked_dirs is []
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

namespace :deploy do
 ...
end

deploy / staging.rb

# Application name
set :application, '...'

# Use a specific tmp dir
set :tmp_dir, "/home/user_name/apps/#{fetch(:application)}/tmp"

# Deploy to this location
set :deploy_to, "/home/user_name/apps/#{fetch(:application)}"

# Branch to deploy from
set :branch, 'staging'

# rbenv stuff
set :rbenv_type, :user
set :rbenv_ruby, '2.2.5'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value

# General
server '...', user: 'user_name', roles: %w{app web db}

deploy / production.rb

# Application name
set :application, 'production'

# Use a specific tmp dir
set :tmp_dir, "/home/user_name/apps/#{fetch(:application)}/tmp"

# Deploy to this location
set :deploy_to, "/home/user_name/apps/#{fetch(:application)}"

# Branch to deploy from
set :branch, 'master'

# General
server '...', user: 'user_name', roles: %w{app web db}

生产红宝石

production@server_name:~$ ruby -v
ruby 2.2.10p489 (2018-03-28 revision 63023) [x86_64-linux]

production@server_name:~$ which ruby
/usr/bin/ruby

1 个答案:

答案 0 :(得分:1)

为避免将宝石装载到production环境中,

尝试将Gemfile中的capistrano-rbenv组移到staging组(如果您尚未在该组中)。

此外,您必须在Capfile中有一个条目

require 'capistrano/rbenv'

您需要将其设置为有条件,以免最终在生产环境中不需要它

有一个老问题解决了类似的问题,请看看

https://github.com/capistrano/rbenv/issues/31

将其添加到Capfile

if Rake.application.top_level_tasks.first == "staging"
  require 'capistrano/rbenv'
end