From 50d4905d85316dd17490bc480e7f867b4774ebf9 Mon Sep 17 00:00:00 2001 From: rspeicher Date: Mon, 20 Sep 2010 20:43:25 -0400 Subject: [PATCH 01/10] Add basic support for specifying local/remote branches When not specified, local defaults to the current branch and remote to "master" --- lib/gitploy.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/gitploy.rb b/lib/gitploy.rb index e9dfe5e..08161a3 100644 --- a/lib/gitploy.rb +++ b/lib/gitploy.rb @@ -5,6 +5,7 @@ module Gitploy class Config REQUIRED_OPTIONS = [:repo, :path, :user, :host] attr_accessor *REQUIRED_OPTIONS + attr_accessor :local_branch, :remote_branch def check! unless missing_options.empty? @@ -20,6 +21,10 @@ def missing_options def configure config = Config.new yield config; config.check! + + config.local_branch ||= current_branch + config.remote_branch ||= 'master' + self.config = config end @@ -66,7 +71,7 @@ def rake(task) end def push! - local { run "git push #{config.user}@#{config.host}:#{config.path}/.git master" } + local { run "git push #{config.user}@#{config.host}:#{config.path}/.git #{config.local_branch}:#{config.remote_branch}" } end private @@ -100,4 +105,12 @@ def flush_run_queue @run_queue = [] cmd end -end \ No newline at end of file + + def current_branch + if branch = `git symbolic-ref HEAD` + branch.chomp.gsub('refs/heads/', '') + else + 'master' + end + end +end From 167186bea3cf5b4483026c9b886d9b269bba2c46 Mon Sep 17 00:00:00 2001 From: rspeicher Date: Thu, 23 Sep 2010 17:09:55 -0400 Subject: [PATCH 02/10] Add basic Cucumber feature --- features/gitploy.feature | 20 ++++++++++++++++++++ features/support/env.rb | 15 +++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 features/gitploy.feature create mode 100644 features/support/env.rb diff --git a/features/gitploy.feature b/features/gitploy.feature new file mode 100644 index 0000000..d8cff48 --- /dev/null +++ b/features/gitploy.feature @@ -0,0 +1,20 @@ +Feature: gitploy + + Scenario Outline: Missing options + Given a file named "config/deploy.rb" with: + """ + require 'gitploy/script' + configure do |c| + stage :staging do + end + end + """ + When I run "gitploy " + Then the output should contain: + """ + The following configuration options are missing for the 'staging' stage: repo, path, user, host + """ + Examples: + | arguments | + | staging setup | + | staging | diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..3073131 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,15 @@ +require 'rubygems' +require 'aruba' +require 'fileutils' + +Before do + FileUtils.rm_rf("tmp") + FileUtils.mkdir("tmp") +end + +PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze +BIN_PATH = File.join(PROJECT_ROOT, 'bin').freeze +LIB_PATH = File.join(PROJECT_ROOT, 'lib').freeze + +ENV['PATH'] = [BIN_PATH, ENV['PATH']].join(':') +ENV['RUBYLIB'] = LIB_PATH From 34c17da0338739ef19084edff5194f69311e6438 Mon Sep 17 00:00:00 2001 From: rspeicher Date: Thu, 23 Sep 2010 17:39:26 -0400 Subject: [PATCH 03/10] Add --pretend option Lets us test remote command execution without actually establishing a remote connection. Also it's just a useful option to have. --- lib/gitploy.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/gitploy.rb b/lib/gitploy.rb index 08161a3..de3f2ea 100644 --- a/lib/gitploy.rb +++ b/lib/gitploy.rb @@ -41,7 +41,7 @@ def stage(name) end def deploy - yield if action.nil? || action == 'deploy' + yield unless action == 'setup' end def setup @@ -81,12 +81,13 @@ def pretty_run(title, cmd) print_bar(100, title) puts "> #{cmd}" puts - Kernel.system(cmd) + Kernel.system(cmd) unless pretend? print_bar(100) end def print_bar(width, title=nil) if title + title += " (pretend)" if pretend? half_width = (width / 2) - (title.length / 2) - 2 left_bar = '=' * half_width right_bar = '=' * (title.length % 2 == 0 ? half_width : half_width - 1) # TODO: lame. @@ -113,4 +114,9 @@ def current_branch 'master' end end + + def pretend? + pretend = %w(-p --pretend) + ARGV.any? { |v| pretend.include? v } + end end From 26ba849602d69ad0b66d1fc34385af94837c8a2f Mon Sep 17 00:00:00 2001 From: rspeicher Date: Thu, 23 Sep 2010 18:31:06 -0400 Subject: [PATCH 04/10] Add Cucumber features. Tests! --- README.markdown | 3 +- config/deploy.rb | 42 +++++++++++++++ features/gitploy.feature | 57 ++++++++++++++++++--- features/step_definitions/gitploy_steps.rb | 59 ++++++++++++++++++++++ 4 files changed, 151 insertions(+), 10 deletions(-) create mode 100644 config/deploy.rb create mode 100644 features/step_definitions/gitploy_steps.rb diff --git a/README.markdown b/README.markdown index 6a27900..1aa464c 100644 --- a/README.markdown +++ b/README.markdown @@ -65,6 +65,5 @@ Gitploy is super alpha - don't use it yet, unless you're just that baller. Are y ### Known issues -* No tests :( * Not enough documentation -* DSL implementation is pretty dumb and needs refactoring \ No newline at end of file +* DSL implementation is pretty dumb and needs refactoring diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..7acccfa --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,42 @@ +$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))) +require 'gitploy/script' + +configure do |c| + c.repo = 'git@github.com:tsigo/gitploy.git' + c.path = '/var/www/fooapp' + + stage :staging do + c.host = 'staging.gitploy.foo' + c.user = 'staging' + end + + stage :production do + c.host = 'gitploy.foo' + c.user = 'production' + end +end + +setup do + local do + run "echo 'Setup local'" + end + remote do + run "mkdir -p #{config.path}" + run "cd #{config.path} && git init" + run "git config --bool receive.denyNonFastForwards false" + run "git config receive.denyCurrentBranch ignore" + end +end + +deploy do + push! + local do + run "echo 'Deploy local'" + end + remote do + run "cd #{config.path}" + run "git reset --hard" + run "bundle install --deployment" + run "touch tmp/restart.txt" + end +end diff --git a/features/gitploy.feature b/features/gitploy.feature index d8cff48..4e782bd 100644 --- a/features/gitploy.feature +++ b/features/gitploy.feature @@ -1,14 +1,7 @@ Feature: gitploy Scenario Outline: Missing options - Given a file named "config/deploy.rb" with: - """ - require 'gitploy/script' - configure do |c| - stage :staging do - end - end - """ + Given an invalid configuration file When I run "gitploy " Then the output should contain: """ @@ -18,3 +11,51 @@ Feature: gitploy | arguments | | staging setup | | staging | + + Scenario Outline: Pretend execution + Given a valid configuration file + When I run "gitploy " + Then the output should contain "(pretend)" + Examples: + | arguments | + | staging setup --pretend | + | staging setup -p | + | staging --pretend | + | staging -p | + + Scenario: Setup on staging + Given a valid configuration file + When I run "gitploy staging setup --pretend" + Then the output should contain "Setup local" + And the output should contain "ssh staging@staging.gitploy.foo" + And the output should contain "mkdir -p /var/www/fooapp" + And the output should contain "cd /var/www/fooapp && git init" + But the output should not contain "Deploy local" + And the output should not contain "ssh production@gitploy.foo" + And the output should not contain "bundle install" + + Scenario: Deploy on staging + Given a valid configuration file + When I run "gitploy staging --pretend" + Then the output should contain "git push" + And the output should contain "Deploy local" + And the output should contain "cd /var/www/fooapp" + And the output should contain "git reset --hard" + But the output should not contain "Setup local" + And the output should not contain "ssh production@gitploy.foo" + + Scenario: Setup on production + Given a valid configuration file + When I run "gitploy production setup --pretend" + Then the output should contain "Setup local" + And the output should contain "production@gitploy.foo" + But the output should not contain "Deploy local" + And the output should not contain "staging@staging.gitploy.foo" + + Scenario: Deploy on production + Given a valid configuration file + When I run "gitploy production --pretend" + Then the output should contain "Deploy local" + And the output should contain "production@gitploy.foo" + But the output should not contain "Setup local" + And the output should not contain "staging@staging.gitploy.foo" diff --git a/features/step_definitions/gitploy_steps.rb b/features/step_definitions/gitploy_steps.rb new file mode 100644 index 0000000..6b1f6ae --- /dev/null +++ b/features/step_definitions/gitploy_steps.rb @@ -0,0 +1,59 @@ +Given /^an invalid configuration file$/ do + Given %{a file named "config/deploy.rb" with:}, + """ + require 'gitploy/script' + configure do |c| + stage :staging do + end + end + """ +end + +Given /^a valid configuration file$/ do + Given %{a file named "config/deploy.rb" with:}, + <<-CODE + require 'gitploy/script' + + configure do |c| + c.repo = 'git@github.com:brentd/gitploy.git' + c.path = '/var/www/fooapp' + c.local_branch = 'master' + c.remote_branch = 'master' + + stage :staging do + c.host = 'staging.gitploy.foo' + c.user = 'staging' + end + + stage :production do + c.host = 'gitploy.foo' + c.user = 'production' + end + end + + setup do + local do + run "echo 'Setup local'" + end + remote do + run "mkdir -p /var/www/fooapp" + run "cd /var/www/fooapp && git init" + run "git config --bool receive.denyNonFastForwards false" + run "git config receive.denyCurrentBranch ignore" + end + end + + deploy do + push! + local do + run "echo 'Deploy local'" + end + remote do + run "cd /var/www/fooapp" + run "git reset --hard" + run "bundle install --deployment" + run "touch tmp/restart.txt" + end + end + CODE +end From 7228bcce3e1783a4b4b3654f5b60cc9f9ffce4a2 Mon Sep 17 00:00:00 2001 From: rspeicher Date: Thu, 23 Sep 2010 18:35:20 -0400 Subject: [PATCH 05/10] Did not mean to commit my test config --- config/deploy.rb | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 config/deploy.rb diff --git a/config/deploy.rb b/config/deploy.rb deleted file mode 100644 index 7acccfa..0000000 --- a/config/deploy.rb +++ /dev/null @@ -1,42 +0,0 @@ -$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))) -require 'gitploy/script' - -configure do |c| - c.repo = 'git@github.com:tsigo/gitploy.git' - c.path = '/var/www/fooapp' - - stage :staging do - c.host = 'staging.gitploy.foo' - c.user = 'staging' - end - - stage :production do - c.host = 'gitploy.foo' - c.user = 'production' - end -end - -setup do - local do - run "echo 'Setup local'" - end - remote do - run "mkdir -p #{config.path}" - run "cd #{config.path} && git init" - run "git config --bool receive.denyNonFastForwards false" - run "git config receive.denyCurrentBranch ignore" - end -end - -deploy do - push! - local do - run "echo 'Deploy local'" - end - remote do - run "cd #{config.path}" - run "git reset --hard" - run "bundle install --deployment" - run "touch tmp/restart.txt" - end -end From 3861434aada37fc2b66b45505ed1f675b82c96a1 Mon Sep 17 00:00:00 2001 From: Brent Dillingham Date: Thu, 30 Sep 2010 03:56:23 +0800 Subject: [PATCH 06/10] Don't need the repo option for config --- README.markdown | 1 - lib/gitploy.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 1aa464c..f785bdd 100644 --- a/README.markdown +++ b/README.markdown @@ -19,7 +19,6 @@ strategy. No hooks, very little behind-the-scenes magic - it just does what you require 'gitploy/script' configure do |c| - c.repo = 'git@github.com:myuser/fooapp.git' c.path = '/var/www/fooapp' stage :staging do diff --git a/lib/gitploy.rb b/lib/gitploy.rb index de3f2ea..455ee6b 100644 --- a/lib/gitploy.rb +++ b/lib/gitploy.rb @@ -3,7 +3,7 @@ module Gitploy attr_accessor :config class Config - REQUIRED_OPTIONS = [:repo, :path, :user, :host] + REQUIRED_OPTIONS = [:path, :user, :host] attr_accessor *REQUIRED_OPTIONS attr_accessor :local_branch, :remote_branch From 42ed9e3c2e4314a6b38b408cf9964cdfa98ec20c Mon Sep 17 00:00:00 2001 From: Brent Dillingham Date: Thu, 30 Sep 2010 03:56:57 +0800 Subject: [PATCH 07/10] Version bump to 0.2.1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0ea3a94..0c62199 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.2.1 From c7b4dde669bd3950b0750b1fa68fa16cd20b1b5e Mon Sep 17 00:00:00 2001 From: Brent Dillingham Date: Thu, 30 Sep 2010 03:57:29 +0800 Subject: [PATCH 08/10] Regenerated gemspec for version 0.2.1 --- gitploy.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitploy.gemspec b/gitploy.gemspec index 6079ac8..0a7028b 100644 --- a/gitploy.gemspec +++ b/gitploy.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{gitploy} - s.version = "0.2.0" + s.version = "0.2.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Brent Dillingham"] - s.date = %q{2010-09-14} + s.date = %q{2010-09-29} s.default_executable = %q{gitploy} s.description = %q{Dead-simple deployments. No, for real this time.} s.email = %q{brentdillingham@gmail.com} From ad2b8f8304602bc9bdf0a87bbef14fc9d149aaaa Mon Sep 17 00:00:00 2001 From: rspeicher Date: Wed, 29 Sep 2010 16:10:44 -0400 Subject: [PATCH 09/10] Remove 'repo' option with regard to tests --- features/gitploy.feature | 2 +- features/step_definitions/gitploy_steps.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/features/gitploy.feature b/features/gitploy.feature index 4e782bd..dd8e16f 100644 --- a/features/gitploy.feature +++ b/features/gitploy.feature @@ -5,7 +5,7 @@ Feature: gitploy When I run "gitploy " Then the output should contain: """ - The following configuration options are missing for the 'staging' stage: repo, path, user, host + The following configuration options are missing for the 'staging' stage: path, user, host """ Examples: | arguments | diff --git a/features/step_definitions/gitploy_steps.rb b/features/step_definitions/gitploy_steps.rb index 6b1f6ae..e9b65fb 100644 --- a/features/step_definitions/gitploy_steps.rb +++ b/features/step_definitions/gitploy_steps.rb @@ -15,7 +15,6 @@ require 'gitploy/script' configure do |c| - c.repo = 'git@github.com:brentd/gitploy.git' c.path = '/var/www/fooapp' c.local_branch = 'master' c.remote_branch = 'master' From beb69c1a8789347a70de0ec0d80d686c48614907 Mon Sep 17 00:00:00 2001 From: rspeicher Date: Wed, 29 Sep 2010 16:11:02 -0400 Subject: [PATCH 10/10] Make sure 'push!' works --- features/gitploy.feature | 2 ++ 1 file changed, 2 insertions(+) diff --git a/features/gitploy.feature b/features/gitploy.feature index dd8e16f..abb00b5 100644 --- a/features/gitploy.feature +++ b/features/gitploy.feature @@ -51,11 +51,13 @@ Feature: gitploy And the output should contain "production@gitploy.foo" But the output should not contain "Deploy local" And the output should not contain "staging@staging.gitploy.foo" + And the output should not contain "git push" Scenario: Deploy on production Given a valid configuration file When I run "gitploy production --pretend" Then the output should contain "Deploy local" And the output should contain "production@gitploy.foo" + And the output should contain "git push" But the output should not contain "Setup local" And the output should not contain "staging@staging.gitploy.foo"