Skip to content

Commit add1371

Browse files
committed
merge a grumpy stash
1 parent 7294626 commit add1371

2 files changed

Lines changed: 58 additions & 16 deletions

File tree

chef/lib/chef/provider/deploy.rb

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@ def run(command, &block)
6060
end
6161

6262
def action_deploy
63+
if all_releases.include?(release_path)
64+
Chef::Log.info("Already deployed app at #{release_path}, skipping. Use action :force_deploy to force.")
65+
else
66+
deploy
67+
end
68+
end
69+
70+
def action_force_deploy
71+
if all_releases.include?(release_path)
72+
Chef::Log.info("Already deployed app at #{release_path}, forcing.")
73+
FileUtils.rm_rf(release_path)
74+
end
75+
deploy
76+
end
77+
78+
def action_rollback
79+
@release_path = all_releases[-2]
80+
raise RuntimeError, "There is no release to rollback to!" unless @release_path
81+
release_to_nuke = all_releases.last
82+
Chef::Log.info "rolling back to previous release: #{release_path}"
83+
symlink
84+
Chef::Log.info "removing last release: #{release_to_nuke}"
85+
FileUtils.rm_rf release_to_nuke
86+
Chef::Log.info "restarting with previous release"
87+
restart
88+
end
89+
90+
def deploy
6391
Chef::Log.info "deploying branch: #{@new_resource.branch}"
6492
enforce_ownership
6593
update_cached_repo
@@ -76,18 +104,6 @@ def action_deploy
76104
cleanup!
77105
end
78106

79-
def action_rollback
80-
@release_path = all_releases[-2]
81-
raise RuntimeError, "There is no release to rollback to!" unless @release_path
82-
release_to_nuke = all_releases.last
83-
Chef::Log.info "rolling back to previous release: #{release_path}"
84-
symlink
85-
Chef::Log.info "removing last release: #{release_to_nuke}"
86-
FileUtils.rm_rf release_to_nuke
87-
Chef::Log.info "restarting with previous release"
88-
restart
89-
end
90-
91107
def callback(what, callback_code=nil)
92108
@collection = Chef::ResourceCollection.new
93109
case callback_code
@@ -162,8 +178,8 @@ def update_cached_repo
162178
def copy_cached_repo
163179
Chef::Log.info "copying the cached checkout to #{release_path}"
164180
FileUtils.mkdir_p(@new_resource.deploy_to + "/releases")
165-
FileUtils.cp_r(@new_resource.destination, release_path, :preserve => true)
166-
release_created
181+
FileUtils.cp_r("#{@new_resource.destination}.", release_path, :preserve => true)
182+
release_created(release_path)
167183
end
168184

169185
def enforce_ownership
@@ -213,7 +229,7 @@ def purge_tempfiles_from_current_release
213229

214230
# Internal callback, called after copy_cached_repo.
215231
# Override if you need to keep state externally.
216-
def release_created
232+
def release_created(release_path)
217233
end
218234

219235
# Internal callback, called during cleanup! for each old release removed.

chef/spec/unit/provider/deploy_spec.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,35 @@
5151
@provider.should_receive(:restart)
5252
@provider.should_receive(:callback).with(:after_restart, nil)
5353
@provider.should_receive(:cleanup!)
54+
@provider.deploy
55+
end
56+
57+
it "does not deploy when using the :deploy action if there is already a deploy at release_path" do
58+
@provider.stub!(:all_releases).and_return([@expected_release_dir])
59+
@provider.should_not_receive(:enforce_ownership)
60+
@provider.should_not_receive(:update_cached_repo)
61+
@provider.action_deploy
62+
end
63+
64+
it "calls deploy when deploying a new release" do
65+
@provider.stub!(:all_releases).and_return([])
66+
@provider.should_receive(:deploy)
5467
@provider.action_deploy
5568
end
5669

70+
it "Removes the old release before deploying when force deploying over it" do
71+
@provider.stub!(:all_releases).and_return([@expected_release_dir])
72+
FileUtils.should_receive(:rm_rf).with(@expected_release_dir)
73+
@provider.should_receive(:deploy)
74+
@provider.action_force_deploy
75+
end
76+
77+
it "deploys as normal when force deploying and there's no prior release at the same path" do
78+
@provider.stub!(:all_releases).and_return([])
79+
@provider.should_receive(:deploy)
80+
@provider.action_force_deploy
81+
end
82+
5783
it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do
5884
@provider.unstub!(:release_path)
5985
all_releases = ["/my/deploy/dir/releases/20040815162342", "/my/deploy/dir/releases/20040700000000",
@@ -118,7 +144,7 @@
118144

119145
it "makes a copy of the cached repo in releases dir" do
120146
FileUtils.should_receive(:mkdir_p).with("/my/deploy/dir/releases")
121-
FileUtils.should_receive(:cp_r).with( "/my/deploy/dir/shared/cached-copy/",
147+
FileUtils.should_receive(:cp_r).with( "/my/deploy/dir/shared/cached-copy/.",
122148
@expected_release_dir,
123149
:preserve => true)
124150
@provider.copy_cached_repo

0 commit comments

Comments
 (0)