如何从Capistrano deploy.rb中的rbenv设置获取bundle_path?

时间:2015-10-26 11:17:45

标签: ruby-on-rails capistrano bundler rbenv

由于我需要capistrano-bundlercapistrano-rbenv个宝石,并在deploy.rb文件中设置如下:

    # rbenv
    set :rbenv_type, :user
    set :rbenv_ruby, '2.0.0-p645'
    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}

    # bundler
    set :bundle_roles, :all                                         # this is default
    set :bundle_servers, -> { release_roles(fetch(:bundle_roles)) } # this is default
    set :bundle_binstubs, -> { shared_path.join('bin') }            # default: nil
    set :bundle_gemfile, -> { release_path.join('Gemfile') }        # default: nil
    set :bundle_path, -> { shared_path.join('bundle') }             # this is default
    set :bundle_without, %w{development test}.join(' ')             # this is default
    set :bundle_flags, '--deployment --quiet'                       # this is default
    set :bundle_env_variables, {}                                   # this is default

很明显,bundle_path不在shared子路径中,它应该是/home/deploy/.rbenv/shims/bundle那么在设置rbenv设置后如何才能获得该路径。我挣扎了很长时间但在githubgoogle.com 上都没有找到任何内容。

THX。

1 个答案:

答案 0 :(得分:1)

要获得rbenv的宝石路径,您可以rbenv exec gem environment gemdir

但是,我认为问题来自于:bundle_path:bundle_flags设置的组合,以及bundler与rbenv的交互方式。

由于--deployment选项(在:bundle_flags中设置),已安装的宝石不会在rbenv的系统 gemdir中安装其二进制文件,但是在app/shared/bundle,所以你不能在$PATH中获取它们。

要解决此问题,您需要将命令添加到:rbenv_map_bins:bundle_bins,以便正确添加前缀。

例如,对于jekyll,您需要设置:

set :rbenv_map_bins, fetch(:rbenv_map_bins, []).push('jekyll')
set :bundle_bins, fetch(:bundle_bins, []).push('jekyll')

这使得capistrano执行的命令类似于

RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec bundle exec jekyll

可行,因为bundle位于:rbenv_map_binsbundle install --deployment会创建一个.bundler/config文件,用于设置app/share/bundle的路径