Skip to content
Permalink
Browse files
ॐ श्री गणेशाय नमः
  • Loading branch information
parolkar committed Jul 1, 2012
0 parents commit 3d2cbf24d96fb702486a9644f1a8f8be986b17c4
Show file tree
Hide file tree
Showing 13 changed files with 643 additions and 0 deletions.
16 Gemfile
@@ -0,0 +1,16 @@
source :rubygems
gem "thor","0.14.6"
gem "pg"
gem "active_support"
gem "i18n"
gem "chronic"
gem "rdiscount"
gem "rugged","0.16.0"
gem "progressbar","0.11.0"
gem "hpricot"

#testing related
gem "rspec"
gem "rr","1.0.4"


@@ -0,0 +1,40 @@
GEM
remote: http://rubygems.org/
specs:
active_support (3.0.0)
activesupport (= 3.0.0)
activesupport (3.0.0)
chronic (0.6.7)
diff-lcs (1.1.3)
hpricot (0.8.6)
i18n (0.6.0)
pg (0.13.2)
progressbar (0.11.0)
rdiscount (1.6.8)
rr (1.0.4)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
rugged (0.16.0)
thor (0.14.6)

PLATFORMS
ruby

DEPENDENCIES
active_support
chronic
hpricot
i18n
pg
progressbar (= 0.11.0)
rdiscount
rr (= 1.0.4)
rspec
rugged (= 0.16.0)
thor (= 0.14.6)
@@ -0,0 +1,90 @@

Deployment Pipeline (Let's make Continuous Deployment painless)
-------------------

In the life of Deployment Manager of an agile aggressive team<sup>1</sup>, there comes a day when he/she needs to manage releases and communicate with
stake holders about features being released and also control what goes live on production. Why control? because in any practical scenario, feature which is ready
and accepted by product managers doesn't guarantee its readiness for the business and marketing and quite often non-technical teams need a buffer time before
a feature is released. Deployment Pipeline is here to help you manage these releases and keep non-technical teams and users better informed about whats going on.


### Ideal Scenario:

1. Your Product Managers write feature/bug stories and prioritize them anytime during the day.
2. Your engineering team believes in Continuous Integration and all engineers commit to Master branch (or Trunk) several times a day.
3. If the build (CI) is green, that tag from Master Branch might get pushed to QA environment for stories to be delivered.
4. Once all stories are accepted, (QA) Staging Tag is deployed to production, Happy Ending of the day!

### Practical Scenario:
1. You have 5 Product Managers who requests feature/bug stories and prioritize them anytime during the day.
2. You have 10 engineers working on 5 stories and commits to Master branch (or Trunk) several times a day.
3. Build is green only 60% of time during the day.
4. By the time build is green there are commits to 4 finished & intermediate commits to an 1 un-finished story.
5. QA delivers the stories(4) which has been finished and 3 are accepted and 1 is rejected.
6. Among 3 accepted stories Marketing Team takes a call to hold 1 story even though its ready.
7. Now we have 2 production ready, 1 held by marketing, 1 rejected, 1 un-finished.
8. Commits related to 2 prod ready are shuffled between commits related to all non-ready stories.
9. Among 2 ready-to-deploy , 1 is marked urgent but it's commits are part of the day when CI build was RED (not necessarily due to this commit).
10. What and how would you deploy today? (cherry-pick commits for a feature with no green build? FAIL) You post-pone release!
- ==Day Rolls Over==
11. 3 new stories requested by Product Managers.
12. An engineer finishes 2 of new stories quickly whose commits goes to master. 3rd new story might take long to finish, but gets its commits pushed to master.
13. Build is green and a tag on master is pushed to QA environment.
14. 2 new stories are delivered and accepted.
15. ...
16. Which staging tag on master would you deploy to production? At any given time there are commits from un-finished/un-delivered stories.


### Solutions:
1. Sure you can use [feature toggle](http://martinfowler.com/bliki/FeatureToggle.html), but it only makes sense for long running (for weeks) set of stories. When every story starts to have a feature toggle, then system gets polluted with
if-else everywhere, which again is difficult to manage and error prone
2. You can also ask engineers to have separate feature branches for each stories and rebase with master often. This brings in its own [over heads](http://martinfowler.com/bliki/FeatureBranch.html)...
* Time spent in merging changes
* It needs a single controller of release branch who pulls the changes and makes sure what goes live is vetted. (This controller can soon become a bottleneck in the process)
* Engineers work in isolation and can not commit intermediate commits unless feature is complete.
3. Use All-Accepted Marker : This is a commit on master below which all stories have been accepted and there are few commits (shuffled with other un-finished) above the marker that can be cleanly cherry-picked.


#### Workflow for All-Accepted Marker Deployment:
1. Find a suitable commit below which all stories are accepted
2. Branch out to new "Release" Branch
3. Inform stake-holders about what features are being released and locked down release marker
4. Cherry-pick related commits from above the marker to release branch
5. Build the release branch and wait for it to be green
6. Deploy release branch to production
7. Automate this entire process

### Deployment Pipline @ Work :
####Getting Started:
<pre><code>
developers-machine:~/workspace/repository (master)$ <b>pipeline help</b>
Tasks:
pipeline help [TASK] # Describe available tasks or one specific task
pipeline release_plan # Prepares a release plan
pipeline setup # Setup Deployment Pipeline Tool
pipeline status # lists all stories with their status
pipeline suitable_release # Suggests a release commit to be picked and also includes a release plan

Options:
[--config=CONFIG] # A ruby file that defines relevant constants & configs. accepts ENV $PIPELINE_CONFIG
# Default: /Users/dev_home/.pipeline_config
</code></pre>


####Find Suitable Commit for All-Accepted Marker:
<pre><code>
developers-machine:~/workspace/repository (master)$ <b>pipeline suitable_release</b>
...
</code></pre>

<sub>\[**1**\]: Team which is motivated for [release-often philosophy](http://radar.oreilly.com/2009/03/continuous-deployment-5-eas.html) so much that it releases to production multiple times a day. It uses DVCS like **[Git](http://git-scm.com)** and agile story tracker like **[PIVOTAL TRACKER](http://www.pivotaltracker.com)**. It has adopted TDD & **[Continious Integration](http://en.wikipedia.org/wiki/Continuous_integration)** as way of life. Every engineer [commits to master all the time](http://martinfowler.com/bliki/FeatureBranch.html#PromiscuousIntegrationVsContinuousIntegration).
</sub>

---------------------------------------------------------------
<sub>
#####Copyright (c) 2012 Abhishek Parolkar [abhishek[at]parolkar[dot]com)

######Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
######The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
######THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</sub>
@@ -0,0 +1,202 @@
#! /usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/pipeline'

class PipelineCmd < Thor
class_option :config, :type => :string,
:desc => "A ruby file that defines relevant constants & configs. accepts ENV $PIPELINE_CONFIG",
:default => ENV["PIPELINE_CONFIG"] || "#{ENV['HOME']}/.pipeline_config"
def initialize(args=[], options={}, config={})
super
load(self.options[:config])
end

desc "setup", "Setup Deployment Pipeline Tool"
method_option :force, :type => :boolean, :default => false, :desc => "Force operation"
def setup
#stub
puts "Setup complete!"
end


desc "status", "lists all stories with their status"
method_option :repository_path, :default => "#{Dir.pwd}", :desc => "Git repository path"
method_option :branch, :default => "master", :desc => "Git branch to consider"
method_option :commit_range, :type => :string, :desc => "Range of commits, eg.\"last_release_tag1..HEAD\""
method_option :html, :type => :boolean, :default => false, :desc => "pretty html output"
def status

c_range = options[:commit_range]
c_range = c_range.split("..")

md_msg = ""

code_repo = CodeRepository.new(options[:repository_path],c_range[0],c_range[1])
tracker = PivotalTracker.new

stories,untagged_commits = tracker.extract_story_ids(code_repo.commits.reverse)


tracker.load_stories(stories.keys,true)

stories_by_status = {}
tracker.stories.each {|story|
stories_by_status[story[:status]] ||= []
stories_by_status[story[:status]] << " * (#{story[:type]}) [#{story[:name]}](#{story[:url]}) requested by **#{story[:requested_by]}** owned by #{code_repo.contributors(stories[story[:id]]).join(', ')} "
}

stories_by_status.each_pair do |status,stories|
md_msg << "\n#{status}: \n\n"
stories.each {|s| md_msg << " #{s} \n"}

end



if untagged_commits.length > 0
md_msg << "\n Following commits have not been tagged, (**why lah?**) \n\n"
untagged_commits.each do |c|
md_msg << " * #{c.oid} #{c.message.gsub("\n"," ")[0...140]} by **#{c.author[:name]}** \n"
end
end

puts "STATUS:"
puts md_msg
if options[:html] == true
markdown = RDiscount.new(md_msg)
temp_html_file = "/tmp/tmp_msg_#{Time.now.to_i}.html"
File.open(temp_html_file, 'w') {|f| f.write(markdown.to_html) }
system("open #{temp_html_file}")
end
end

desc "suitable_release", "Suggests a release commit to be picked and also includes a release plan"
method_option :repository_path, :default => "#{Dir.pwd}", :desc => "Git repository path"
method_option :branch, :default => "master", :desc => "Git branch to consider"
method_option :last_release_commit, :type => :string, :desc => "Commit id (SHA) of previous release "
def suitable_release
last_release_commit = options[:last_release_commit]
code_repo = CodeRepository.new(options[:repository_path],last_release_commit)
tracker = PivotalTracker.new

suitable_release_sha = last_release_commit

code_repo.commits.reverse.each do |commit|
puts "Analysing... #{commit.oid}"
#Check if all stories associated to this commit has been accepted, if yes consider the commit , else break
#Consider the commit if its untagged anyway
commit_suitable = true
story_ids,untagged = tracker.extract_story_ids([commit]) #this will return story_ids and untagged such that they are mutually exclusive.
story_ids.keys.each { |story_id|
story = tracker.story_obj(story_id)
if story.nil? || story[:status] != "accepted"
puts "Unknown story :#{story_id} " if story.nil?
puts "Unsuitable commit because story status is #{story[:status]}"
commit_suitable = false
break
end

suitable_release_sha = commit.oid
puts "Stories accepted for #{commit.oid}, hence considered"
}
unless untagged.empty?
puts "Commit is untagged hence considered"
suitable_release_sha = untagged.first.oid
end

break unless commit_suitable
end


if suitable_release_sha == last_release_commit
puts "No suitable commit to pick for release"
else
puts "Commit that can be pickup up for release is: #{suitable_release_sha}"
end
end


desc "release_plan", "Prepares a release plan"
method_option :repository_path, :default => "#{Dir.pwd}", :desc => "Git repository path"
method_option :branch, :default => "master", :desc => "Git branch to consider"
method_option :last_release_commit, :type => :string, :desc => "Commit id (SHA) of previous release "
method_option :target_release_commit, :type => :string, :desc => "Commit id (SHA) of intended release "
method_option :html, :type => :boolean, :default => false, :desc => "pretty html output"
def release_plan
last_release_commit = options[:last_release_commit]
target_release_commit = options[:target_release_commit]
code_repo = CodeRepository.new(options[:repository_path],last_release_commit)
tracker = PivotalTracker.new
stories,untagged_commits = tracker.extract_story_ids(code_repo.commits.reverse)

commits_ready = []
stories_included = []

all_commits = code_repo.commits.reverse
commits_ready << all_commits.shift
while all_commits.length > 0 && commits_ready.last.oid != target_release_commit
commits_ready << all_commits.shift
end

commits_ready.shift #can ignore first commit, its the last release commit
stories_ready = []
commits_to_cherry_pick = []
sha_list =commits_ready.map(&:oid)
sha_list.each {|c|
s = stories.select {|k,v| v.include?(c)}
s.each_pair{|k,v|
other_commits = v - [c]
other_commits.each {|oc|
if !sha_list.include?(oc)
commits_to_cherry_pick << oc
end
}
}
stories_ready += s.keys
}
stories_ready.uniq!
tracker.load_stories(stories_ready,true)

#cherry-picks have to be arranged in order which appears in repository
ordered_cherry_picks = []
all_commits.each {|c|
ordered_cherry_picks << c.oid if commits_to_cherry_pick.include?(c.oid)
}


md_msg = ""

md_msg << "Release can be locked at commit #{sha_list.last} \n\n"

md_msg << "Stories being released are:\n\n"
tracker.stories.each {|story|
md_msg << " * (#{story[:type]}) [#{story[:name]}](#{story[:url]}) requested by **#{story[:requested_by]}** owned by #{code_repo.contributors(stories[story[:id]]).join(', ')} "
md_msg << "(current status:<font color='red'>#{story[:status]}</font>)" if story[:status] != 'accepted'
md_msg << " \n"
}


md_msg << "\n\nCommits that needs to be cherry-picked as they are part of above stories \n\n"
ordered_cherry_picks.reverse.each {|c|
c = code_repo.lookup(c)
md_msg << " * #{c.oid} #{c.message.gsub("\n"," ")[0...140]} by #{c.author[:name]} \n"
}

puts md_msg

if options[:html] == true
markdown = RDiscount.new(md_msg)
temp_html_file = "/tmp/tmp_msg_#{Time.now.to_i}.html"
File.open(temp_html_file, 'w') {|f| f.write(markdown.to_html) }
system("open #{temp_html_file}")
end


end

end




PipelineCmd.start
@@ -0,0 +1,22 @@
# encoding: utf-8

Gem::Specification.new do |gem|
gem.name = "deployment_pipeline"
gem.description = "Deployment Pipeline makes Continuous Deployment super easy."
gem.homepage = "https://github.com/parolkar/deployment_pipeline"
gem.summary = gem.description
gem.version = "0.0.0"
gem.authors = ["Abhishek Parolkar"]
gem.email = "abhishek@parolkar.com"
gem.has_rdoc = false
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.require_paths = ['lib']
gem.add_dependency "rugged","0.16.0"
gem.add_dependency "thor","0.14.6"
gem.add_dependency "rdiscount"
gem.add_dependency "progressbar","0.11.0"
gem.add_dependency "hpricot"
end

Binary file not shown.

0 comments on commit 3d2cbf2

Please sign in to comment.