开发者

How to raise error if cap deploy was not invoked using bundle exec

I just encountered a subtle issue with capistrano deployment gem dependencies and I would like to en开发者_高级运维force how capistrano is invoked.

How can I detect that capistrano was invoked using 'bundle exec' like this:

bundle exec cap app deploy

And not like this:

cap app deploy

I would like to raise an error in the latter case by detecting the method of invocation at the top of my deploy.rb file.


It appears that Bundler sets the $BUNDLE_BIN_PATH and $BUNDLE_GEMFILE environment variables when running executables. For example, do this:

env >/tmp/1
bundler exec env >/tmp/2
diff -u /tmp/[12]

You'll see the differences in the environment.

So then in your deployment script, you can do something like this:

abort "You must run this using 'bundle exec ...'" unless ENV['BUNDLE_BIN_PATH'] || ENV['BUNDLE_GEMFILE']

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜