Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundler clean task #85

Merged
merged 4 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -51,6 +52,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