Skip to content

Commit

Permalink
Added a bundler:clean task
Browse files Browse the repository at this point in the history
  • Loading branch information
betesh committed Jul 5, 2015
1 parent 1e097d4 commit 7c4ed40
Show file tree
Hide file tree
Showing 3 changed files with 20 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
1 change: 1 addition & 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
18 changes: 18 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,23 @@ 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
deleted_gems = capture(:bundle, :clean, fetch(:bundle_clean_options, ""))
if "" == deleted_gems
info "All installed gems are in Gemfile.lock"
else
deleted_gems = deleted_gems.split("\n").collect(&:strip).collect{ |line| line.gsub(/^Removing /, "") }.sort.join(", ")
info "Deleting bundled gems: #{deleted_gems}"
end
end
end
end
end
end

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

0 comments on commit 7c4ed40

Please sign in to comment.