Skip to content

Commit

Permalink
Batch rm -rf calls in deploy:cleanup. (#2027)
Browse files Browse the repository at this point in the history
  • Loading branch information
azin634 authored and mattbrictson committed Aug 29, 2019
1 parent 5567908 commit 96fdb4c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gem "capistrano", github: "capistrano/capistrano", require: false
[master]: https://github.com/capistrano/capistrano/compare/v3.11.0...HEAD

* Your contribution here!
* [#2027](https://github.com/capistrano/capistrano/pull/2027): Batch rm -rf calls in deploy:cleanup. [@azin634](https://github.com/azin634)

## [`3.11.0`] (2018-06-02)

Expand Down
6 changes: 6 additions & 0 deletions features/deploy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ Feature: Deploy
Then 3 valid releases are kept
And the current directory will be a symlink to the release

Scenario: Cleanup when there are more releases than arguments can handle
Given config stage file has line "set :keep_releases, 3"
And 5000 valid existing releases
When I run cap "deploy:cleanup"
Then 3 valid releases are kept

Scenario: Rolling Back
Given I make 2 deployments
When I run cap "deploy:rollback"
Expand Down
10 changes: 6 additions & 4 deletions features/step_definitions/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@

Given(/^(\d+) valid existing releases$/) do |num|
a_day = 86_400 # in seconds
offset = -(a_day * num.to_i)
num.to_i.times do
run_vagrant_command("mkdir -p #{TestApp.release_path(TestApp.timestamp(offset))}")
offset += a_day
(1...num).each_slice(100) do |num_batch|
dirs = num_batch.map do |i|
offset = -(a_day * i)
TestApp.release_path(TestApp.timestamp(offset))
end
run_vagrant_command("mkdir -p #{dirs.join(' ')}")
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/capistrano/tasks/deploy.rake
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ namespace :deploy do
debug t(:no_current_release, host: host.to_s)
end
if directories.any?
execute :rm, "-rf", *directories
directories.each_slice(100) do |directories_batch|
execute :rm, "-rf", *directories_batch
end
else
info t(:no_old_releases, host: host.to_s, keep_releases: fetch(:keep_releases))
end
Expand Down

0 comments on commit 96fdb4c

Please sign in to comment.