Skip to content

Commit

Permalink
Merge pull request capistrano#85 from will-in-wi/bundler_clean_task
Browse files Browse the repository at this point in the history
Bundler clean task
  • Loading branch information
mattbrictson authored Sep 26, 2016
2 parents d4964e6 + c2a92cb commit d21138e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(master)

* Added a `bundle clean` task. There are no default hooks for it.
* Use `bundle check` to check if we can skip `bundle install`
* Run `bundle:install` on rollback (`deploy:reverted`)

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ set :bundle_path, -> { shared_path.join('bundle') } # this is defaul
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
set :bundle_clean_options, "" # this is default. Use "--dry-run" if you just want to know what gems would be deleted, without actually deleting them
```

You can parallelize the installation of gems with bundler's jobs feature.
Expand Down Expand Up @@ -86,6 +87,13 @@ $ bundle install \

If any option is set to `nil` it will be excluded from the final bundle command.

If you want to clean up gems after a successful deploy, add `after 'deploy:published', 'bundler:clean'` to config/deploy.rb.

Downsides to cleaning:

* If a rollback requires rebuilding a Gem with a large compiled binary component, such as Nokogiri, the rollback will take a while.
* In rare cases, if a gem that was used in the previously deployed version was yanked, rollback would entirely fail.

### Environment Variables

The `bundle_env_variables` option can be used to specify any environment variables you want present when running the `bundle` command:
Expand Down
12 changes: 12 additions & 0 deletions lib/capistrano/tasks/bundler.cap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace :bundler do
set :bundle_flags, '--deployment --quiet'
set :bundle_jobs, nil
set :bundle_env_variables, {}
set :bundle_clean_options, ""
DESC
task :install do
on fetch(:bundle_servers) do
Expand Down Expand Up @@ -50,6 +51,17 @@ namespace :bundler do
SSHKit.config.command_map.prefix[command.to_sym].push("bundle exec")
end
end

desc "Remove unused gems intalled by bundler"
task :clean do
on fetch(:bundle_servers) do
within release_path do
with fetch(:bundle_env_variables, {}) do
execute :bundle, :clean, fetch(:bundle_clean_options, "")
end
end
end
end
end

Capistrano::DSL.stages.each do |stage|
Expand Down

0 comments on commit d21138e

Please sign in to comment.