简体   繁体   English

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

[英]How to get bundle_path from rbenv setting in Capistrano deploy.rb?

Since I have require capistrano-bundler and capistrano-rbenv gems, and have set as follow in deploy.rb file:由于我需要capistrano-bundlercapistrano-rbenv gems,并且在 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

Clearly bundle_path is not in shared subpath, it should be /home/deploy/.rbenv/shims/bundle .显然 bundle_path 不在shared子路径中,它应该是/home/deploy/.rbenv/shims/bundle So how can I get that path after I have set rbenv's settings.那么在我设置了 rbenv 的设置后,我如何才能获得该路径。 I struggle for a long time but found nothing both on github or google.com .我挣扎了很长时间,但在githubgoogle.com上一无所获

Thx.谢谢。

To get rbenv's gem path you can do rbenv exec gem environment gemdir .要获得 rbenv 的 gem 路径,您可以执行rbenv exec gem environment gemdir

However, I think the problem comes from the combination of the :bundle_path , :bundle_flags settings, and how bundler interacts with rbenv.但是,我认为问题来自:bundle_path:bundle_flags设置的组合,以及 bundler 如何与 rbenv 交互。

Because of the --deployment option (set in :bundle_flags ), the installed gems won't install their binaries in rbenv's system gemdir, but on app/shared/bundle , so you won't get them in your $PATH .由于的--deployment选项(在设置:bundle_flags ),安装的宝石不会rbenv的系统gemdir安装它们的可执行文件,但在app/shared/bundle ,这样你就不会在你得到他们$PATH

To fix this, you need to add your command to both :rbenv_map_bins and :bundle_bins so that it is properly prefixed.要解决此问题,您需要将命令添加到:rbenv_map_bins:bundle_bins以便正确添加前缀。

For example, for jekyll, you need to set:比如对于jekyll,需要设置:

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

This makes the command executed by capistrano to be something like这使得由 capistrano 执行的命令类似于

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

which will work because bundle is in :rbenv_map_bins and bundle install --deployment creates a .bundler/config file that sets the path to app/share/bundle这将起作用,因为bundle:rbenv_map_bins并且bundle install --deployment .bundler/config创建了一个.bundler/config文件,该文件设置了app/share/bundle的路径

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

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