heroku_san 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change log (curated)
2
2
 
3
+ ## v3.0.1
4
+
5
+ * Fix deploy:force bugs (#84 & #85)
6
+
3
7
  ## v3.0.0
4
8
 
5
9
  * New feature: support for Rack apps (e.g. Sinatra)
@@ -0,0 +1,56 @@
1
+ # Deploy Strategies
2
+
3
+ If you look at the network graphs of `heroku_san` on github, you'll see a number of branches where the only change is the deletion of the following line from the `deploy` task:
4
+
5
+ - stage.migrate
6
+
7
+ If more than a few people are will to take the effort to fork a gem just so they can delete 1 line, something smells. The reason is that these forkers were using something other than Rails+ActiveRecord+SQL in their project. Some were using Sinatra, others were using Rails, but with CouchDB.
8
+
9
+ The _raison d'être_ for the `heroku_san` gem is to make Heroku deploys dirt simple. So, if people are making whole forks to customize the deploy task, we should make it less painful.
10
+
11
+ ## Enter strategies
12
+
13
+ [Strategies](need_ref) are an object oriented programming pattern for creating pluggable execution control. There's is now a new class of objects that inherit from `HerokuSan::Deploy::Base`. These objects now control how deploys are executed for you. The Rails strategy, `HerokuSan::Deploy::Base` does exactly what HerokuSan has always done:
14
+
15
+ * push to git@heroku.com
16
+ * call rake db:migrate
17
+ * restart
18
+
19
+ On the other hand, the Sinatra strategy, `HerokuSan::Deploy::Sinatra` does nothing more than the base strategy:
20
+
21
+ * push to git@heroku.com
22
+
23
+ You can create your own strategies and then configure HerokuSan to use it instead of its default:
24
+
25
+ ## Rails 3 projects
26
+
27
+ Amend your `Rakefile`:
28
+
29
+ require 'heroku_san'
30
+
31
+ class MyStrategy < HerokuSan::Deploy::Base
32
+ def deploy
33
+ super
34
+ # call my own code to do something unique
35
+ end
36
+ end
37
+
38
+ HerokuSan.project = HerokuSan::Project.new(Rails.root.join("config","heroku.yml"), :deploy => MyStrategy)
39
+
40
+ ## Sinatra (and other Rack based apps)
41
+
42
+ Amend your `Rakefile`
43
+
44
+ require 'heroku_san'
45
+
46
+ class MyStrategy < HerokuSan::Deploy::Base
47
+ def deploy
48
+ super
49
+ # call my own code to do something unique
50
+ end
51
+ end
52
+
53
+ config_file = File.join(File.expand_path(File.dirname(__FILE__)), 'config', 'heroku.yml')
54
+ HerokuSan.project = HerokuSan::Project.new(config_file, :deploy => MyStrategy)
55
+
56
+ load "heroku_san/tasks.rb"
@@ -52,7 +52,6 @@ When /^I add heroku_san to the Gemfile$/ do
52
52
  gem 'heroku_san', :path => '../../../.'
53
53
  end
54
54
  EOT
55
-
56
55
  end
57
56
 
58
57
  When /^I run bundle install$/ do
@@ -92,6 +91,7 @@ When /^I create my project on Heroku$/ do
92
91
  ---
93
92
  test_app:
94
93
  app: #{@app}
94
+
95
95
  EOT
96
96
  end
97
97
 
@@ -119,6 +119,7 @@ When /^I configure my project$/ do
119
119
  app: #{@app}
120
120
  config:
121
121
  DROIDS: marvin
122
+
122
123
  EOT
123
124
  cmd = 'bundle exec rake test_app heroku:config'
124
125
  run_simple cmd
@@ -187,6 +188,7 @@ When /^I install an addon$/ do
187
188
  app: #{@app}
188
189
  addons:
189
190
  - deployhooks:campfire
191
+
190
192
  END_CONFIG
191
193
 
192
194
  run_simple 'bundle exec rake test_app heroku:addons'
@@ -212,7 +214,7 @@ end
212
214
  def overwrite_simple_config_file
213
215
  overwrite_file 'config/heroku.yml', <<EOT.strip_heredoc
214
216
  ---
215
- test_app:
217
+ test_app:
218
+
216
219
  EOT
217
-
218
220
  end
@@ -1,13 +1,14 @@
1
1
  module HerokuSan
2
2
  module Deploy
3
3
  class Base
4
- def initialize(stage, args = {})
4
+ def initialize(stage, commit = nil, force = nil)
5
5
  @stage = stage
6
- @args = args
6
+ @commit = commit
7
+ @force = force
7
8
  end
8
9
 
9
10
  def deploy
10
- @stage.push(@args[:commit], @args[:force])
11
+ @stage.push(@commit, @force)
11
12
  end
12
13
  end
13
14
  end
@@ -0,0 +1,11 @@
1
+ require 'heroku_san/deploy/base'
2
+
3
+ module HerokuSan
4
+ module Deploy
5
+ class Noop < Base
6
+ def deploy
7
+ # do nothing
8
+ end
9
+ end
10
+ end
11
+ end
@@ -2,11 +2,12 @@ require 'heroku_san/deploy/base'
2
2
 
3
3
  module HerokuSan
4
4
  module Deploy
5
- class Rails < HerokuSan::Deploy::Base
5
+ class Rails < Base
6
6
  def deploy
7
- $stderr.puts super
8
- $stderr.puts @stage.rake('db:migrate')
9
- $stderr.puts @stage.restart
7
+ # TODO: Add announce/logger
8
+ super
9
+ @stage.rake('db:migrate')
10
+ @stage.restart
10
11
  end
11
12
  end
12
13
  end
@@ -2,9 +2,9 @@ require 'heroku_san/deploy/base'
2
2
 
3
3
  module HerokuSan
4
4
  module Deploy
5
- class Sinatra < HerokuSan::Deploy::Base
5
+ class Sinatra < Base
6
6
  def deploy
7
- $stderr.puts super
7
+ super
8
8
  end
9
9
  end
10
10
  end
@@ -13,11 +13,13 @@ module HerokuSan
13
13
  @app_settings = {}
14
14
  config = parse(@config_file)
15
15
  config.each do |stage, settings|
16
+ # TODO: Push this eval later (j.i.t.)
16
17
  @app_settings[stage] = HerokuSan::Stage.new(stage, settings.merge(options.slice(:deploy)))
17
18
  end
18
19
  end
19
20
 
20
21
  def create_config
22
+ # TODO: Convert true/false returns to success/exception
21
23
  template = File.expand_path(File.join(File.dirname(__FILE__), '../templates', 'heroku.example.yml'))
22
24
  if File.exists?(@config_file)
23
25
  false
@@ -43,11 +45,10 @@ module HerokuSan
43
45
  end
44
46
 
45
47
  def apps
46
- if !@apps.empty?
48
+ if @apps.present?
47
49
  @apps
48
50
  else
49
- @apps = case all.size
50
- when 1
51
+ @apps = if all.size == 1
51
52
  $stdout.puts "Defaulting to #{all.first.inspect} since only one app is defined"
52
53
  all
53
54
  else
@@ -65,8 +65,8 @@ module HerokuSan
65
65
  restart
66
66
  end
67
67
 
68
- def deploy(args = {})
69
- strategy = @options['deploy'].new(self, args)
68
+ def deploy(commit = nil, force = nil)
69
+ strategy = @options['deploy'].new(self, commit, force)
70
70
  strategy.deploy
71
71
  end
72
72
 
@@ -170,7 +170,7 @@ namespace :heroku do
170
170
  desc "Pushes the given commit (default: HEAD)"
171
171
  task :push, :commit do |t, args|
172
172
  each_heroku_app do |stage|
173
- stage.push(args[:commit])
173
+ stage.push(args.commit)
174
174
  end
175
175
  end
176
176
 
@@ -178,7 +178,7 @@ namespace :heroku do
178
178
  desc "Force-pushes the given commit (default: HEAD)"
179
179
  task :force, :commit do |t, args|
180
180
  each_heroku_app do |stage|
181
- stage.push(args[:commit], :force)
181
+ stage.push(args.commit, :force)
182
182
  end
183
183
  end
184
184
  end
@@ -207,19 +207,19 @@ namespace :heroku do
207
207
  end
208
208
  end
209
209
 
210
- desc "Pushes the given commit, migrates and restarts (default: HEAD)"
210
+ desc "Deploys the app (default: HEAD)"
211
211
  task :deploy, [:commit] => [:before_deploy] do |t, args|
212
212
  each_heroku_app do |stage|
213
- stage.deploy(args)
213
+ stage.deploy(args.commit)
214
214
  end
215
215
  Rake::Task[:after_deploy].execute
216
216
  end
217
217
 
218
218
  namespace :deploy do
219
- desc "Force-pushes the given commit, migrates and restarts (default: HEAD)"
219
+ desc "Deploys the app with push --force (default: HEAD)"
220
220
  task :force, [:commit] => [:before_deploy] do |t, args|
221
221
  each_heroku_app do |stage|
222
- stage.deploy(args.merge(:force => true))
222
+ stage.deploy(args.commit, :force)
223
223
  end
224
224
  Rake::Task[:after_deploy].execute
225
225
  end
@@ -1,3 +1,3 @@
1
1
  module HerokuSan
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -6,26 +6,26 @@ module HerokuSan
6
6
  let(:stage) { HerokuSan::Stage.new('test', {"app" => "awesomeapp", "deploy" => 'HerokuSan::Deploy::Base'}) }
7
7
 
8
8
  it "calls push" do
9
- subject = described_class.new(stage, {})
9
+ subject = described_class.new(stage)
10
10
  stage.should_receive(:push).with(nil, nil)
11
11
  subject.deploy
12
12
  end
13
13
 
14
14
  it "calls push(sha)" do
15
- subject = described_class.new(stage, {:commit => 'sha'})
15
+ subject = described_class.new(stage, 'sha')
16
16
  stage.should_receive(:push).with('sha', nil)
17
17
  subject.deploy
18
18
  end
19
19
 
20
20
  it "calls push(nil, :force)" do
21
- subject = described_class.new(stage, {:force => true})
22
- stage.should_receive(:push).with(nil, true)
21
+ subject = described_class.new(stage, nil, :force)
22
+ stage.should_receive(:push).with(nil, :force)
23
23
  subject.deploy
24
24
  end
25
25
 
26
26
  it "calls push(sha, :force)" do
27
- subject = described_class.new(stage, {:commit => 'sha', :force => true})
28
- stage.should_receive(:push).with('sha', true)
27
+ subject = described_class.new(stage, 'sha', :force)
28
+ stage.should_receive(:push).with('sha', :force)
29
29
  subject.deploy
30
30
  end
31
31
  end
@@ -5,11 +5,11 @@ module HerokuSan
5
5
  describe Rails do
6
6
  let(:stage) { HerokuSan::Stage.new('test', {"app" => "awesomeapp", "deploy" => 'HerokuSan::Deploy::Rails'}) }
7
7
 
8
- it "calls migrate" do
8
+ it "calls push, rake db:migrate & restart" do
9
9
  subject = described_class.new(stage, {})
10
- stage.should_receive(:push) # "mock" super
11
- stage.should_receive(:rake).with('db:migrate')
12
- stage.should_receive(:restart)
10
+ stage.should_receive(:push) { "pushed" } # "mock" super
11
+ stage.should_receive(:rake).with('db:migrate') { "migrated" }
12
+ stage.should_receive(:restart) { "restarted" }
13
13
  subject.deploy
14
14
  end
15
15
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 0
8
- - 0
9
- version: 3.0.0
8
+ - 1
9
+ version: 3.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Elijah Miller
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-05-12 00:00:00 -07:00
20
+ date: 2012-05-16 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -159,6 +159,7 @@ files:
159
159
  - autotest/discover.rb
160
160
  - cucumber.yml
161
161
  - examples/auto_tagger.rake
162
+ - examples/deploy_strategies.md
162
163
  - examples/push_revision.rake
163
164
  - features/config.feature
164
165
  - features/extended-config.feature
@@ -170,6 +171,7 @@ files:
170
171
  - lib/git.rb
171
172
  - lib/heroku_san.rb
172
173
  - lib/heroku_san/deploy/base.rb
174
+ - lib/heroku_san/deploy/noop.rb
173
175
  - lib/heroku_san/deploy/rails.rb
174
176
  - lib/heroku_san/deploy/sinatra.rb
175
177
  - lib/heroku_san/project.rb