繁体   English   中英

有和没有rbenv的Rails Capistrano部署

[英]Rails Capistrano deploy with and without 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

部署/ 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}

部署/ 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

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

如果尚未将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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM