From 4f9a5590d0dd6f0444dce685c17fe3c06534b13a Mon Sep 17 00:00:00 2001 From: Jesus Lopes Date: Mon, 23 Aug 2010 22:33:44 -0300 Subject: [PATCH 1/7] Added option app_folder. --- deploy.rb.sample | 1 + lib/inploy/deploy.rb | 9 +++++++-- spec/deploy_spec.rb | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/deploy.rb.sample b/deploy.rb.sample index 7f5465d..1a037e1 100644 --- a/deploy.rb.sample +++ b/deploy.rb.sample @@ -11,3 +11,4 @@ hosts = ['hooters', 'geni'] #sudo = false #cache_dirs = %w(public/cache) #skip_steps = nil +#app_folder = nil diff --git a/lib/inploy/deploy.rb b/lib/inploy/deploy.rb index 59804af..0994c75 100644 --- a/lib/inploy/deploy.rb +++ b/lib/inploy/deploy.rb @@ -3,7 +3,7 @@ class Deploy include Helper include DSL - attr_accessor :repository, :user, :application, :hosts, :path, :ssh_opts, :branch, :environment, + attr_accessor :repository, :user, :application, :hosts, :path, :app_folder, :ssh_opts, :branch, :environment, :port, :skip_steps, :cache_dirs, :sudo define_callbacks :after_setup, :before_restarting_server @@ -15,6 +15,7 @@ def initialize @environment = 'production' @user = "deploy" @path = "/var/local/apps" + @app_folder = nil configure end @@ -40,7 +41,7 @@ def remote_install(opts) end def remote_setup - remote_run "cd #{path} && #{@sudo}git clone --depth 1 #{repository} #{application} && cd #{application} #{checkout}#{bundle} && #{@sudo}rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}" + remote_run "cd #{path} && #{@sudo}git clone --depth 1 #{repository} #{application} && cd #{directory} #{checkout}#{bundle} && #{@sudo}rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}" end def local_setup @@ -71,6 +72,10 @@ def update_code private + def directory + app_folder.nil? ? application : "#{application}/#{app_folder}" + end + def checkout branch.eql?("master") ? "" : "&& $(git branch | grep -vq #{branch}) && git checkout -f -b #{branch} origin/#{branch}" end diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index eee5d7f..5f7a0ac 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -4,7 +4,7 @@ subject { Inploy::Deploy.new } - def expect_setup_with(branch, environment = 'production', skip_steps = nil, bundler = false) + def expect_setup_with(branch, environment = 'production', skip_steps = nil, bundler = false, app_folder = nil) if branch.eql? 'master' checkout = "" else @@ -12,7 +12,8 @@ def expect_setup_with(branch, environment = 'production', skip_steps = nil, bund end skip_steps_cmd = " skip_steps=#{skip_steps.join(',')}" unless skip_steps.nil? bundler_cmd = " && bundle install ~/.bundle --without development test" if bundler - expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path} && git clone --depth 1 #{@repository} #{@application} && cd #{@application} #{checkout}#{bundler_cmd} && rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}'" + directory = app_folder.nil? ? @application : "#{@application}/#{app_folder}" + expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path} && git clone --depth 1 #{@repository} #{@application} && cd #{directory} #{checkout}#{bundler_cmd} && rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}'" end def setup(subject) @@ -76,6 +77,10 @@ def setup(subject) subject.path.should eql("/var/local/apps") end + it "should use nil as the default app_path" do + subject.app_folder.should be_nil + end + context "configured" do before :each do setup subject @@ -100,6 +105,12 @@ def setup(subject) expect_setup_with @branch, @environment, subject.skip_steps subject.remote_setup end + + it "should pass app_folder params to local setup" do + subject.app_folder = "project" + expect_setup_with @branch, @environment, nil, false, subject.app_folder + subject.remote_setup + end it "should execute bundle install before local setup if Gemfile exists" do file_exists "Gemfile" From 4735961378c661bfee92bae0b90de0b01004c020 Mon Sep 17 00:00:00 2001 From: Jesus Lopes Date: Mon, 23 Aug 2010 22:51:12 -0300 Subject: [PATCH 2/7] Fixed typo in test. --- spec/deploy_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index 5f7a0ac..37fc4ae 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -77,7 +77,7 @@ def setup(subject) subject.path.should eql("/var/local/apps") end - it "should use nil as the default app_path" do + it "should use nil as the default app_folder" do subject.app_folder.should be_nil end From 45f320c333c325af11e714c38164a9a73e117994 Mon Sep 17 00:00:00 2001 From: Jesus Lopes Date: Mon, 23 Aug 2010 23:19:33 -0300 Subject: [PATCH 3/7] Added option app_folder for update commands. --- lib/inploy/deploy.rb | 6 +----- lib/inploy/helper.rb | 6 +++++- spec/deploy_spec.rb | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/inploy/deploy.rb b/lib/inploy/deploy.rb index 0994c75..f3c725a 100644 --- a/lib/inploy/deploy.rb +++ b/lib/inploy/deploy.rb @@ -41,7 +41,7 @@ def remote_install(opts) end def remote_setup - remote_run "cd #{path} && #{@sudo}git clone --depth 1 #{repository} #{application} && cd #{directory} #{checkout}#{bundle} && #{@sudo}rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}" + remote_run "cd #{path} && #{@sudo}git clone --depth 1 #{repository} #{application} && cd #{application_folder} #{checkout}#{bundle} && #{@sudo}rake inploy:local:setup environment=#{environment}#{skip_steps_cmd}" end def local_setup @@ -72,10 +72,6 @@ def update_code private - def directory - app_folder.nil? ? application : "#{application}/#{app_folder}" - end - def checkout branch.eql?("master") ? "" : "&& $(git branch | grep -vq #{branch}) && git checkout -f -b #{branch} origin/#{branch}" end diff --git a/lib/inploy/helper.rb b/lib/inploy/helper.rb index 91c043d..e578ef6 100644 --- a/lib/inploy/helper.rb +++ b/lib/inploy/helper.rb @@ -33,7 +33,11 @@ def camelize(string) end def application_path - "#{path}/#{application}" + app_folder.nil? ? "#{path}/#{application}" : "#{path}/#{application}/#{app_folder}" + end + + def application_folder + app_folder.nil? ? application : "#{application}/#{app_folder}" end def copy_sample_files diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index 37fc4ae..d351e9e 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -141,6 +141,12 @@ def setup(subject) subject.remote_update end + it "should exec the commands in the app_folder" do + subject.app_folder = 'project' + expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path}/#{@application}/#{subject.app_folder} && rake inploy:local:update environment=#{@environment}'" + subject.remote_update + end + end context "on local update" do @@ -166,6 +172,12 @@ def setup(subject) expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path}/#{@application} && rake #{task} RAILS_ENV=#{@environment}'" subject.remote_rake task end + it "should execute the rake task in app_folder" do + subject.app_folder = 'project' + task = 'build' + expect_command "ssh #{@ssh_opts} #{@user}@#{@host} 'cd #{@path}/#{@application}/#{subject.app_folder} && rake #{task} RAILS_ENV=#{@environment}'" + subject.remote_rake task + end end end From fbe2f1a7ca63eca73550f38ed68fdd4ab15dcedb Mon Sep 17 00:00:00 2001 From: Jesus Lopes Date: Tue, 24 Aug 2010 09:25:23 -0300 Subject: [PATCH 4/7] Fixed after_update_code for run git submodule from toplevel of the working tree. --- lib/inploy/deploy.rb | 2 +- spec/deploy_spec.rb | 4 ++++ spec/shared_examples.rb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/inploy/deploy.rb b/lib/inploy/deploy.rb index f3c725a..fc44045 100644 --- a/lib/inploy/deploy.rb +++ b/lib/inploy/deploy.rb @@ -81,7 +81,7 @@ def bundle end def after_update_code - run "git submodule update --init" + run "cd #{path}/#{application} && git submodule update --init" copy_sample_files return unless install_gems migrate_database diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index d351e9e..558006d 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -154,6 +154,10 @@ def setup(subject) expect_command "git pull origin #{@branch}" subject.local_update end + it "should run git submodule command from the toplevel of the working tree" do + expect_command "cd #{@path}/#{@application} && git submodule update --init" + subject.local_update + end it_should_behave_like "local update" end diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index 8866b45..0c4c5da 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -169,7 +169,7 @@ end it "should init submodules" do - expect_command "git submodule update --init" + expect_command "cd #{subject.path}/#{subject.application} && git submodule update --init" subject.local_update end From 6d55050d63f19357c002a9e3753fdc0aff7ae704 Mon Sep 17 00:00:00 2001 From: Jesus Lopes Date: Tue, 24 Aug 2010 13:03:26 -0300 Subject: [PATCH 5/7] Return to app_folder after run git submodule. --- lib/inploy/deploy.rb | 2 +- spec/deploy_spec.rb | 2 +- spec/shared_examples.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/inploy/deploy.rb b/lib/inploy/deploy.rb index fc44045..5ad3af8 100644 --- a/lib/inploy/deploy.rb +++ b/lib/inploy/deploy.rb @@ -81,7 +81,7 @@ def bundle end def after_update_code - run "cd #{path}/#{application} && git submodule update --init" + run "cd #{path}/#{application} && git submodule update --init && cd #{path}/#{application}/#{app_folder}" copy_sample_files return unless install_gems migrate_database diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index 558006d..c0f44f6 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -155,7 +155,7 @@ def setup(subject) subject.local_update end it "should run git submodule command from the toplevel of the working tree" do - expect_command "cd #{@path}/#{@application} && git submodule update --init" + expect_command "cd #{@path}/#{@application} && git submodule update --init && cd #{@path}/#{@application}/#{@app_folder}" subject.local_update end diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index 0c4c5da..7803c2c 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -169,7 +169,7 @@ end it "should init submodules" do - expect_command "cd #{subject.path}/#{subject.application} && git submodule update --init" + expect_command "cd #{subject.path}/#{subject.application} && git submodule update --init && cd #{subject.path}/#{subject.application}/#{subject.app_folder}" subject.local_update end From 8941d1ac781f7613262e18eaae2ba7453d9624e6 Mon Sep 17 00:00:00 2001 From: Jesus Lopes Date: Tue, 24 Aug 2010 17:04:09 -0300 Subject: [PATCH 6/7] Update Readme. --- README.textile | 1 + 1 file changed, 1 insertion(+) diff --git a/README.textile b/README.textile index 49129bd..80dd353 100644 --- a/README.textile +++ b/README.textile @@ -116,6 +116,7 @@ branch = 'production' # default master sudo = true # default false cache_dirs = ['public/cache', 'tmp/cache'] # default ['public/cache'] skip_steps = ['install_gems', 'clear_cache'] # default [] +app_folder = 'project_folder' # default empty h2. SKIP STEPS From 7d0920f0deee43698b8e0d04393ef36599c10bd9 Mon Sep 17 00:00:00 2001 From: Jesus Lopes Date: Tue, 14 Dec 2010 18:24:53 -0200 Subject: [PATCH 7/7] Fix errors in 1.8.6 --- lib/inploy/dsl.rb | 8 +++++--- spec/deploy_spec.rb | 2 +- spec/rails3_push_spec.rb | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/inploy/dsl.rb b/lib/inploy/dsl.rb index bcf4209..96759b9 100644 --- a/lib/inploy/dsl.rb +++ b/lib/inploy/dsl.rb @@ -3,9 +3,11 @@ module DSL module ClassMethods def define_callbacks(*callbacks) callbacks.each do |callback| - define_method callback do |&block| - instance_variable_set "@#{callback}", block - end + class_eval <<-METHOD + def #{callback} &block + instance_variable_set("@#{callback}", block) + end + METHOD end end end diff --git a/spec/deploy_spec.rb b/spec/deploy_spec.rb index 0afee35..ace1c1b 100644 --- a/spec/deploy_spec.rb +++ b/spec/deploy_spec.rb @@ -135,7 +135,7 @@ def setup(subject) it "should exec the commands in all hosts" do subject.hosts = ['host0', 'host1', 'host2'] - 3.times.each do |i| + 3.times do |i| expect_command "ssh #{@ssh_opts} #{@user}@host#{i} 'cd #{@path}/#{@application} && rake inploy:local:update RAILS_ENV=#{@environment} environment=#{@environment}'" end subject.remote_update diff --git a/spec/rails3_push_spec.rb b/spec/rails3_push_spec.rb index b82d6cb..e48dbb9 100644 --- a/spec/rails3_push_spec.rb +++ b/spec/rails3_push_spec.rb @@ -32,7 +32,7 @@ it "should push git repository and runs the local update on all hosts" do subject.hosts = ['host0', 'host1', 'host2'] - 3.times.each do |i| + 3.times do |i| expect_command "git push -f batman@host#{i}:/fakie/path/robin live" expect_command "ssh #{@ssh_opts} batman@host#{i} 'cd /fakie/path/robin && git reset --hard && git clean -f -d -e public/system && git submodule update --init && bundle install --deployment'" expect_command "ssh #{@ssh_opts} batman@host#{i} 'cd /fakie/path/robin && rake inploy:local:update RAILS_ENV=production environment=production'"