Skip to content

Commit

Permalink
Add the ability to do no-op test deploys in Moonshine.
Browse files Browse the repository at this point in the history
  • Loading branch information
wfarr committed Feb 1, 2011
1 parent 2819351 commit f66bb7f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/moonshine/capistrano_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def self.load_defaults_info(capistrano_config)
ssh_options[:paranoid] = false
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :noop, false

# fix common svn error
set :scm, :subversion if !! repository =~ /^svn/
Expand Down Expand Up @@ -56,7 +57,9 @@ def self.load_defaults_info(capistrano_config)
def self.load_callbacks_into(capistrano_config)
capistrano_config.load do
on :start, 'moonshine:configure'
after 'deploy:restart', 'deploy:cleanup'
unless fetch(:noop)
after 'deploy:restart', 'deploy:cleanup'
end
after 'multistage:ensure', 'moonshine:configure_stage'
end
end
Expand Down Expand Up @@ -120,6 +123,11 @@ def self.load_into(capistrano_config)
sudo "RAILS_ROOT=#{latest_release} DEPLOY_STAGE=#{ENV['DEPLOY_STAGE'] || fetch(:stage)} RAILS_ENV=#{fetch(:rails_env)} shadow_puppet #{latest_release}/app/manifests/#{fetch(:moonshine_manifest)}.rb"
end

desc 'No-op apply the Moonshine manifest for this application'
task :noop_apply, :except => { :no_release => true } do
sudo "RAILS_ROOT=#{latest_release} DEPLOY_STAGE=#{ENV['DEPLOY_STAGE'] || fetch(:stage)} RAILS_ENV=#{fetch(:rails_env)} shadow_puppet --noop #{latest_release}/app/manifests/#{fetch(:moonshine_manifest)}.rb"
end

desc 'Update code and then run a console. Useful for debugging deployment.'
task :update_and_console do
set :moonshine_apply, false
Expand All @@ -142,7 +150,15 @@ def self.load_into(capistrano_config)
end

before 'deploy:symlink' do
apply if fetch(:moonshine_apply, true) == true
if fetch(:noop)
noop_apply
else
apply if fetch(:moonshine_apply, true) == true
end
end

after 'deploy' do
deploy.rollback.default if fetch(:noop)
end

end
Expand Down Expand Up @@ -290,7 +306,9 @@ def self.load_into(capistrano_config)
namespace :deploy do
desc 'Restart the Passenger processes on the app server by touching tmp/restart.txt.'
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
unless fetch(:noop)
run "touch #{current_path}/tmp/restart.txt"
end
end

[:start, :stop].each do |t|
Expand All @@ -315,6 +333,11 @@ def self.load_into(capistrano_config)
end
end

desc "does a no-op deploy. great for testing a potential deploy before running it!"
task :noop do
set :noop, true
end

namespace :ruby do

desc 'Forces a reinstall of Ruby and restarts Apache/Passenger'
Expand Down
48 changes: 48 additions & 0 deletions spec/moonshine/capistrano_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,54 @@
callback.call
end

it "performs moonshine:noop_apply before deploy:symlink" do
@configuration.set :noop, true
@configuration.set :shared_path, '/srv/app/shared'
@configuration.set :latest_release, '/srv/app/releases/20100601'
callbacks = find_callback(@configuration, :before, 'deploy:symlink')
callbacks.should_not be_nil

callback = callbacks.first
callback.should_not be_nil

@configuration.namespace :moonshine do
should_receive(:noop_apply)
end

callback.call
end

context "noop deploy" do
before do
@configuration.set :noop, true
@configuration.set :shared_path, '/srv/app/shared'
@configuration.set :latest_release, '/srv/app/releases/20100601'
@configuration.set :rails_env, :staging
@configuration.set :stage, :staging
@configuration.set :moonshine_manifest, 'application_manifest'
end

it "should execute noop_apply" do
pending "Needs some tweaks to cap integration handling"
apply_cmd = "sudo sh -c 'RAILS_ROOT=#{latest_release} DEPLOY_STAGE=#{ENV['DEPLOY_STAGE'] || fetch(:stage)} RAILS_ENV=#{fetch(:rails_env)} shadow_puppet #{'--noop' if noop} #{latest_release}/app/manifests/#{fetch(:moonshine_manifest)}.rb'"
# should run noop
noop = true
@configuration.should have_run(apply_cmd)
# should not run go-op
noop = false
@configuration.should_not have_run(apply_cmd)
end

it "should rollback the release" do
pending "Needs some tweaks to cap integration handling"
end

it "rolling back the noop release should not restart passenger" do
pending "Needs some tweaks to cap integration handling"
@configuration.should_not have_run("touch tmp/restart.txt")
end
end

context "on default stage" do
it "sets rails_env to production" do
@configuration.rails_env.should == 'production'
Expand Down

0 comments on commit f66bb7f

Please sign in to comment.