capistrano / bundler

Bundler support for Capistrano 3.x
MIT License
219 stars 83 forks source link

Add explicit bundler:config step to support 2.1+ #122

Closed mattbrictson closed 4 years ago

mattbrictson commented 4 years ago

Starting with Bundler 2.1, the --path, --without, and --deployment options are deprecated. In other words you are no longer supposed to specify these when running bundle install.

Instead, Bundler wants you to set these options externally from the install command. That way all subsequent invocations of bundler can use the same external configuration without you having to remember which flags to use each time.

There are two ways to specify this external configuration: providing environment variables, or running bundle config. This commit implements the latter.

To summarize, prior to running bundle check, bundle install, or bundle clean, Capistrano will now run a new bundler:config task. This task executes the following command as many times as needed:

bundle config --local KEY VALUE

Each execution sets the external Bundler configuration KEY to VALUE.

The following Capistrano variables are automatically consulted to get these KEYs and VALUEs:

This commit also introduces a new variable:

It is a Hash that can contain any arbitrary KEY and VALUE pairs to send to bundle config. By default it has a single entry:

set :bundle_config, { deployment: true }

Finally, this commit removes --deployment option from the default value of :bundle_flags, since that flag is deprecated. It has been replaced by the default :bundle_config as mentioned above.

Fixes #115

capistrano-bot commented 4 years ago

Thanks for the PR! This project lacks automated tests, which makes reviewing and approving PRs somewhat difficult. Please make sure that your contribution has not broken backwards compatibility or introduced any risky changes.

Generated by :no_entry_sign: Danger

mattbrictson commented 4 years ago

I want to give a shout out to @spajic who proposed similar changes a few years ago in #97 and #101. Sorry it took so long. 😅

mattbrictson commented 4 years ago

@will-in-wi @ansonhoyt @jamesw @tsechingho @patsch any thoughts on this PR? It would be great if you could test out this branch to see if it works prior to me merging this. Thanks!

You can test by modifying your Gemfile as follows:


gem "capistrano-bundler", git: "https://github.com/capistrano/bundler.git", branch: "features/bundler-2.1-support"
tsechingho commented 4 years ago

I had test this PR in my current projects, it works as old days. thanks @mattbrictson 😄

ccasabona commented 4 years ago

The 'features/bundler-2.1-support' branch works perfectly when deploying to staging and production environments. The necessary bundle config commands run as such:

00:10 bundler:config
      01 /var/www/html/example.com/public/rvm1scripts/rvm-auto.sh . bundle config --local deployment true
    ✔ 01 user@192.168.1.107 2.421s
      02 /var/www/html/example.com/public/rvm1scripts/rvm-auto.sh . bundle config --local path /var/www/html/example.com/public/shared/bundle
    ✔ 02 user@192.168.1.107 2.341s
      03 /var/www/html/example.com/public/rvm1scripts/rvm-auto.sh . bundle config --local without development\ test
    ✔ 03 user@192.168.1.107 2.380s
00:18 bundler:install
      01 /var/www/html/example.com/public/rvm1scripts/rvm-auto.sh . bundle install --jobs 4 --quiet

Thank you for making this change!

mattbrictson commented 4 years ago

Alright I'm going to merge this and release a 2.0 version of this gem within the next few days. Thanks everyone!

Fjan commented 4 years ago

There is a small issue with this patch: bundler install wants a space separated list of groups, but bundler config wants a ":" separated list of groups (see https://bundler.io/v2.0/man/bundle-config.1.html).

We now emit the options designed for install to config, so as a space separated list, which will show a warning in bundler, but otherwise seems to work. It would be better to replace the space with a ":" in bundler-capistrano. As a quick fix to get rid of the warning you can simply do set :bundle_without, %w{development test}.join(':')

mattbrictson commented 4 years ago

@Fjan thanks for the heads up and the link to the docs. Somehow I missed this warning in my testing. Could you open a new issue with some more details, including the text of the warning so that others can search for it and find it? I can implement the fix that you mentioned.

ansonhoyt commented 4 years ago

👍 Just deployed with capistrano-bunder 2.0.1. No bundler warnings. Many thanks! ❤️

Sorry I wasn't available to test this before release, but glad several others were able to test it out.

thbar commented 3 years ago

Thanks for the work on this! FWIW, I'm asking Bundler if we could have a single call to set 3 options here https://github.com/rubygems/rubygems/issues/4392, in order to accelerate deployment further (since the 3 steps can take near 10 seconds in cases, which could be divided by three).