cf-deploy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7fdd5ef4f413ab5caec0fd8d6a52a23a04cf7b3f
4
+ data.tar.gz: 2746b6d22beb57314cec0c099fef9f6619c3c6e0
5
+ SHA512:
6
+ metadata.gz: 1efac37c88afe74c86a13feab83b4bc5fa52f7d28d84ae6b8fe93eb6d655b000f6ffeaee101353512066e826060141029d4de5160aca4771c858ef3f86769934
7
+ data.tar.gz: 59290656c37a5e1b4834ffd6053bb99ef2296bfbda21f0c7ec3e8f0048e9d19fcbdb1011c71f6323a5892f74bcb9b07a4cd820ecb4f87f6abc064af76189177c
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Made by Made Ltd
1
+ Copyright (c) 2014 Made Tech Ltd
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Rake tasks for deploying to CloudFoundry v6+
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/madebymade/cf-deploy/badges/gpa.svg)](https://codeclimate.com/github/madebymade/cf-deploy)
4
+ [![Build Status](https://travis-ci.org/madebymade/cf-deploy.svg?branch=master)](https://travis-ci.org/madebymade/cf-deploy)
5
+ [![Test Coverage](https://codeclimate.com/github/madebymade/cf-deploy/badges/coverage.svg)](https://codeclimate.com/github/madebymade/cf-deploy)
6
+
3
7
  This gem provides the functionality you need to deploy your rails application to
4
8
  a [CloudFoundry][CloudFoundry] provider like [Pivotal][Pivotal].
5
9
 
@@ -60,6 +64,8 @@ CF::Deploy.rake_tasks! do
60
64
  environment :production => [:clean, 'assets:precompile'] do
61
65
  route 'example.com'
62
66
  route 'example.com', 'admin'
67
+ flip_route 'yourwebsite', 'www'
68
+ flip_route 'yourwebsite', 'www-origin'
63
69
  end
64
70
  end
65
71
  ```
@@ -98,6 +104,8 @@ CF::Deploy.rake_tasks! do
98
104
 
99
105
  environment :production => 'assets:precompile' do
100
106
  route 'example-app.io'
107
+ flip_route 'yourwebsite', 'www'
108
+ flip_route 'yourwebsite', 'www-origin'
101
109
  end
102
110
  end
103
111
  ```
@@ -147,7 +155,7 @@ CF::Deploy.rake_tasks! do
147
155
  environment :staging => 'assets:precompile'
148
156
 
149
157
  environment :production => 'assets:precompile' do
150
- route 'example-app.io'
158
+ flip_route 'example-app.io'
151
159
  end
152
160
  end
153
161
  ```
@@ -235,17 +243,17 @@ deployed and live.
235
243
 
236
244
  [![made](https://s3-eu-west-1.amazonaws.com/made-assets/googleapps/google-apps.png)][made]
237
245
 
238
- Developed and maintained by [Made][made]. Key contributions:
246
+ Developed and maintained by [Made Tech][made]. Key contributions:
239
247
 
240
248
  * [Luke Morton](https://github.com/DrPheltRight)
241
249
 
242
250
  ## License
243
251
 
244
- Copyright © 2014 Made by Made Ltd. It is free software, and may be
252
+ Copyright © 2014 Made Tech Ltd. It is free software, and may be
245
253
  redistributed under the terms specified in the [MIT-LICENSE][license] file.
246
254
 
247
255
  [CloudFoundry]: http://www.cloudfoundry.org/
248
256
  [Pivotal]: https://run.pivotal.io/
249
257
  [cli]: https://github.com/cloudfoundry/cli/releases
250
- [made]: http://www.madetech.co.uk?ref=github&repo=ydtd_frontend
258
+ [made]: http://www.madetech.co.uk?ref=github&repo=cf-deploy
251
259
  [license]: https://github.com/madebymade/cf-deploy/blob/master/LICENSE
data/lib/cf/deploy.rb CHANGED
@@ -2,25 +2,26 @@ require 'cf/deploy/version'
2
2
  require 'cf/deploy/config'
3
3
  require 'cf/deploy/env_config'
4
4
  require 'cf/deploy/commands'
5
+ require 'cf/deploy/blue_green'
5
6
  require 'rake'
6
7
 
7
8
  module CF
8
9
  class Deploy
9
10
  class << self
10
11
  def rake_tasks!(&block)
11
- new(Config.new(&block)).tasks
12
+ new(:config => Config.new(&block), :commands => Commands.new).rake_tasks!
12
13
  end
13
14
  end
14
15
 
15
- include Commands
16
+ attr_accessor :config_task, :config, :cf
16
17
 
17
- attr_accessor :config
18
-
19
- def initialize(config)
20
- @config = config
18
+ def initialize(config_task)
19
+ @config_task = config_task
20
+ @config = config_task[:config]
21
+ @cf = config_task[:commands]
21
22
  end
22
23
 
23
- def tasks
24
+ def rake_tasks!
24
25
  [define_login_task].concat(deploy_tasks)
25
26
  end
26
27
 
@@ -32,39 +33,27 @@ module CF
32
33
  return Rake::Task['cf:login'] if Rake::Task.task_defined?('cf:login')
33
34
 
34
35
  Rake::Task.define_task('cf:login') do
35
- login(config)
36
+ cf.login(config)
36
37
  end
37
38
  end
38
39
 
39
40
  def define_deploy_task(env)
40
- blue_green_task(env) if env[:deployments].size > 1
41
+ BlueGreen.new(env, config_task) if env[:deployments].size > 1
41
42
 
42
43
  env[:deployments].each do |deployment|
43
44
  Rake::Task.define_task(deployment[:task_name] => env[:deps]) do
44
- push(deployment[:manifest])
45
+ unless cf.push(deployment[:manifest])
46
+ raise "Failed to deploy #{deployment}"
47
+ end
45
48
 
46
49
  env[:routes].each do |route|
47
50
  deployment[:app_names].each do |app_name|
48
- map_route(route, app_name)
51
+ cf.map_route(route, app_name)
49
52
  end
50
53
  end
51
54
  end
52
55
  end
53
56
  end
54
57
 
55
- def first_domain(env)
56
- env[:routes].first.values_at(:host, :domain).compact.join('.')
57
- end
58
-
59
- def next_production(env)
60
- current_production(first_domain(env)) != 'blue' ? 'blue' : 'green'
61
- end
62
-
63
- def blue_green_task(env)
64
- Rake::Task.define_task(env[:task_name] => env[:deps]) do
65
- task_name = EnvConfig.task_name("#{env[:name]}_#{next_production(env)}")
66
- Rake::Task[task_name].invoke
67
- end
68
- end
69
58
  end
70
59
  end
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+
3
+ module CF
4
+ class Deploy
5
+ class BlueGreen
6
+
7
+ attr_accessor :env, :config_task, :config, :cf
8
+
9
+ def initialize(env, config_task)
10
+ @env = env
11
+ @config_task = config_task
12
+ @config = config_task[:config]
13
+ @cf = config_task[:commands]
14
+
15
+ Rake::Task.define_task(env[:task_name] => env[:deps]) do
16
+ task_name = EnvConfig.task_name("#{env[:name]}_#{next_production_colour(env)}")
17
+ Rake::Task[task_name].invoke
18
+ end
19
+
20
+ Rake::Task.define_task("cf:deploy:production:flip") do
21
+ cf.login(config)
22
+
23
+ current_app_in_production = app_name_from_color(current_production_colour(env))
24
+ next_app_in_production = app_name_from_color(next_production_colour(env))
25
+
26
+ env[:flip_routes].each do |route|
27
+ cf.map_route(route, "#{next_app_in_production}")
28
+ cf.unmap_route(route, "#{current_app_in_production}")
29
+ end
30
+ end
31
+ end
32
+
33
+ def define_login_task
34
+ return Rake::Task['cf:login'] if Rake::Task.task_defined?('cf:login')
35
+
36
+ Rake::Task.define_task('cf:login') do
37
+ cf.login(config)
38
+ end
39
+ end
40
+
41
+ def app_name_from_color(colour)
42
+ env.app_name_for_colour(colour)
43
+ end
44
+
45
+ def match_flip_route_grep(env)
46
+ if env[:flip_routes].empty?
47
+ raise 'Blue/green deploys require at least one flip_route'
48
+ end
49
+
50
+ env[:flip_routes].first.values_at(:hostname, :domain).compact.join(' *')
51
+ end
52
+
53
+ def current_production_colour(env)
54
+ cf.current_production(match_flip_route_grep(env))
55
+ end
56
+
57
+ def next_production_colour(env)
58
+ current_production_colour(env) != 'blue' ? 'blue' : 'green'
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -1,6 +1,6 @@
1
1
  module CF
2
2
  class Deploy
3
- module Commands
3
+ class Commands
4
4
  def login(config)
5
5
  login_cmd = ['cf login']
6
6
 
@@ -15,14 +15,25 @@ module CF
15
15
  Kernel.system("cf push -f #{manifest}")
16
16
  end
17
17
 
18
+ def stop(app_name)
19
+ stop_cmd = "cf stop #{app_name}"
20
+ Kernel.system(stop_cmd)
21
+ end
22
+
18
23
  def map_route(route, app_name)
19
24
  map_cmd = "cf map-route #{app_name} #{route[:domain]}"
20
25
  map_cmd = "#{map_cmd} -n #{route[:hostname]}" unless route[:hostname].nil?
21
26
  Kernel.system(map_cmd)
22
27
  end
23
28
 
24
- def current_production(domain)
25
- io = IO.popen("cf routes | grep #{domain}")
29
+ def unmap_route(route, app_name)
30
+ unmap_cmd = "cf unmap-route #{app_name} #{route[:domain]}"
31
+ unmap_cmd = "#{unmap_cmd} -n #{route[:hostname]}" unless route[:hostname].nil?
32
+ Kernel.system(unmap_cmd)
33
+ end
34
+
35
+ def current_production(host)
36
+ io = IO.popen("cf routes | grep '#{host}'")
26
37
  matches = /(blue|green)/.match(io.read)
27
38
  io.close
28
39
  return if matches.nil?
@@ -30,20 +30,23 @@ module CF
30
30
 
31
31
  def manifests_by_env
32
32
  Dir[self[:manifest_glob]].reduce({}) do |envs, manifest|
33
- if manifest =~ /_blue.yml$/
34
- env = File.basename(manifest, '_blue.yml').to_sym
35
- elsif manifest =~ /_green.yml$/
36
- env = File.basename(manifest, '_green.yml').to_sym
37
- else
38
- env = File.basename(manifest, '.yml').to_sym
39
- end
40
-
33
+ env = manifest_env(manifest)
41
34
  envs[env] ||= []
42
35
  envs[env] << manifest
43
36
  envs
44
37
  end
45
38
  end
46
39
 
40
+ def manifest_env(manifest)
41
+ if manifest =~ /_blue.yml$/
42
+ File.basename(manifest, '_blue.yml').to_sym
43
+ elsif manifest =~ /_green.yml$/
44
+ File.basename(manifest, '_green.yml').to_sym
45
+ else
46
+ File.basename(manifest, '.yml').to_sym
47
+ end
48
+ end
49
+
47
50
  def environments(manifests_by_env)
48
51
  environments = []
49
52
 
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'pathname'
2
3
 
3
4
  module CF
4
5
  class Deploy
@@ -12,10 +13,13 @@ module CF
12
13
  :task_name => EnvConfig.task_name(name),
13
14
  :deps => deps,
14
15
  :routes => [],
16
+ :flip_routes => [],
15
17
  :manifests => manifests)
16
18
 
17
19
  instance_eval(&block) if block_given?
18
20
 
21
+ raise "No manifests found for #{name}" if manifests.empty?
22
+
19
23
  self[:deployments] = deployments
20
24
  end
21
25
 
@@ -24,19 +28,34 @@ module CF
24
28
  end
25
29
 
26
30
  def deployment_for_manifest(manifest)
31
+ {:task_name => deployment_task_name(manifest),
32
+ :manifest => manifest,
33
+ :app_names => app_names_for_manifest(manifest)}
34
+ end
35
+
36
+ def deployment_task_name(manifest)
27
37
  if self[:manifests].size > 1
28
- task_name = EnvConfig.task_name(File.basename(manifest, '.yml').to_sym)
38
+ EnvConfig.task_name(File.basename(manifest, '.yml').to_sym)
29
39
  else
30
- task_name = self[:task_name]
40
+ self[:task_name]
31
41
  end
32
-
33
- {:task_name => task_name,
34
- :manifest => manifest,
35
- :app_names => app_names_for_manifest(manifest)}
36
42
  end
37
43
 
38
44
  def app_names_for_manifest(manifest)
39
- YAML.load_file(manifest)['applications'].map { |a| a['name'] }
45
+ config = YAML.load_file(manifest)
46
+
47
+ if config['applications'].nil?
48
+ raise "No applications defined in YAML manifest #{manifest}"
49
+ end
50
+
51
+ config['applications'].map { |a| a['name'] }
52
+ end
53
+
54
+ def app_name_for_colour(colour)
55
+ self[:manifests].map { |manifest|
56
+ name = app_names_for_manifest(File.expand_path("#{manifest}")).first
57
+ return name if name.include?(colour)
58
+ }
40
59
  end
41
60
 
42
61
  # Environment config setter methods
@@ -52,6 +71,10 @@ module CF
52
71
  def route(domain, hostname = nil)
53
72
  self[:routes] << {:domain => domain, :hostname => hostname}
54
73
  end
74
+
75
+ def flip_route(domain, hostname =nil)
76
+ self[:flip_routes] << {:domain => domain, :hostname => hostname}
77
+ end
55
78
  end
56
79
  end
57
80
  end
@@ -1,5 +1,5 @@
1
1
  module CF
2
2
  class Deploy
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -12,8 +12,8 @@ describe CF::Deploy do
12
12
  Dir.chdir('spec/') do
13
13
  described_class.rake_tasks! do
14
14
  environment :production do
15
- route 'example.com'
16
- route 'example.com', '2'
15
+ flip_route 'yourwebsite.com', 'www'
16
+ flip_route 'yourwebsite.com', 'www-origin'
17
17
  end
18
18
  end
19
19
  end
@@ -27,34 +27,48 @@ describe CF::Deploy do
27
27
  it 'should deploy blue if not currently deployed' do
28
28
  rake_tasks!
29
29
  expect(Kernel).to receive(:system).with('cf login').ordered
30
- expect(IO).to receive(:popen).with('cf routes | grep example.com') { double(:read => '', :close => nil) }
31
- expect(Kernel).to receive(:system).with('cf push -f manifests/production_blue.yml').ordered
32
- expect(Kernel).to receive(:system).with('cf map-route production-blue-app example.com').ordered
33
- expect(Kernel).to receive(:system).with('cf map-route production-blue-app example.com -n 2').ordered
30
+ expect(IO).to receive(:popen).with("cf routes | grep 'www *yourwebsite.com'") { double(:read => '', :close => nil) }
31
+ expect(Kernel).to receive(:system).with('cf push -f manifests/production_blue.yml').and_return(true).ordered
34
32
  Rake::Task['cf:deploy:production'].invoke
35
33
  end
36
34
 
37
35
  it 'should deploy blue if green currently deployed' do
38
36
  rake_tasks!
39
37
  expect(Kernel).to receive(:system).with('cf login').ordered
40
- expect(IO).to receive(:popen).with('cf routes | grep example.com') { double(:read => 'production-green-app', :close => nil) }
41
- expect(Kernel).to receive(:system).with('cf push -f manifests/production_blue.yml').ordered
42
- expect(Kernel).to receive(:system).with('cf map-route production-blue-app example.com').ordered
43
- expect(Kernel).to receive(:system).with('cf map-route production-blue-app example.com -n 2').ordered
38
+ expect(IO).to receive(:popen).with("cf routes | grep 'www *yourwebsite.com'") { double(:read => 'production-green-app', :close => nil) }
39
+ expect(Kernel).to receive(:system).with('cf push -f manifests/production_blue.yml').and_return(true).ordered
44
40
  Rake::Task['cf:deploy:production'].invoke
45
41
  end
46
42
 
47
43
  it 'should deploy green if blue currently deployed' do
48
44
  rake_tasks!
49
45
  expect(Kernel).to receive(:system).with('cf login').ordered
50
- expect(IO).to receive(:popen).with('cf routes | grep example.com') { double(:read => 'production-blue-app', :close => nil) }
51
- expect(Kernel).to receive(:system).with('cf push -f manifests/production_green.yml').ordered
52
- expect(Kernel).to receive(:system).with('cf map-route production-green-app example.com').ordered
53
- expect(Kernel).to receive(:system).with('cf map-route production-green-app example.com -n 2').ordered
46
+ expect(IO).to receive(:popen).with("cf routes | grep 'www *yourwebsite.com'") { double(:read => 'production-blue-app', :close => nil) }
47
+ expect(Kernel).to receive(:system).with('cf push -f manifests/production_green.yml').and_return(true).ordered
54
48
  Rake::Task['cf:deploy:production'].invoke
55
49
  end
56
50
 
57
- xit 'should throw exception if no routes defined for blue/green task' do
51
+ it 'should ignore flip_routes' do
52
+ rake_tasks!
53
+ expect(Kernel).to_not receive(:system).with('cf map-route production-blue-app yourwebsite.com -n www').ordered
54
+ expect(Kernel).to_not receive(:system).with('cf map-route production-blue-app yourwebsite.com -n www-origin').ordered
55
+ end
56
+
57
+ it 'should throw exception if no routes defined for blue/green task' do
58
+ Dir.chdir('spec/') do
59
+ described_class.rake_tasks! do
60
+ environment :production
61
+ end
62
+ end
63
+
64
+ allow(Kernel).to receive(:system)
65
+ expect do
66
+ Rake::Task['cf:deploy:production'].invoke
67
+ end.to raise_error
68
+ end
69
+
70
+ it 'should run prerequisite tasks' do
71
+ rake_tasks!
58
72
  end
59
73
  end
60
74
  end
@@ -14,7 +14,7 @@ describe CF::Deploy do
14
14
  end
15
15
 
16
16
  expect(Kernel).to receive(:system).with('cf login').ordered
17
- expect(Kernel).to receive(:system).with('cf push -f manifests/staging.yml').ordered
17
+ expect(Kernel).to receive(:system).with('cf push -f manifests/staging.yml').and_return(true).ordered
18
18
  Rake::Task['cf:deploy:staging'].invoke
19
19
  end
20
20
 
@@ -28,7 +28,7 @@ describe CF::Deploy do
28
28
  end
29
29
 
30
30
  expect(Kernel).to receive(:system).with('cf login').ordered
31
- expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').ordered
31
+ expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').and_return(true).ordered
32
32
  expect(Kernel).to receive(:system).with('cf map-route test-app testexample.com').ordered
33
33
  Rake::Task['cf:deploy:test'].invoke
34
34
  end
@@ -43,7 +43,7 @@ describe CF::Deploy do
43
43
  end
44
44
 
45
45
  expect(Kernel).to receive(:system).with('cf login').ordered
46
- expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').ordered
46
+ expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').and_return(true).ordered
47
47
  expect(Kernel).to receive(:system).with('cf map-route test-app example.com -n test')
48
48
  Rake::Task['cf:deploy:test'].invoke
49
49
  end
@@ -59,19 +59,60 @@ describe CF::Deploy do
59
59
  end
60
60
 
61
61
  expect(Kernel).to receive(:system).with('cf login').ordered
62
- expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').ordered
62
+ expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').and_return(true).ordered
63
63
  expect(Kernel).to receive(:system).with('cf map-route test-app example.com').ordered
64
64
  expect(Kernel).to receive(:system).with('cf map-route test-app example.com -n 2').ordered
65
65
  Rake::Task['cf:deploy:test'].invoke
66
66
  end
67
67
 
68
- xit 'should not map routes if push fails' do
68
+ it 'should not map routes if push command fails' do
69
+ Dir.chdir('spec/') do
70
+ described_class.rake_tasks! do
71
+ environment :test do
72
+ route 'example.com'
73
+ end
74
+ end
75
+ end
76
+
77
+ expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').and_return(nil)
78
+ expect(Kernel).to_not receive(:system).with('cf map-route test-app example.com')
79
+ expect do
80
+ Rake::Task['cf:deploy:test'].invoke
81
+ end.to raise_error
69
82
  end
70
83
 
71
- xit 'should throw decent error if manifest does not exist' do
84
+ it 'should not map routes if push command returns non-zero status' do
85
+ Dir.chdir('spec/') do
86
+ described_class.rake_tasks! do
87
+ environment :test do
88
+ route 'example.com'
89
+ end
90
+ end
91
+ end
92
+
93
+ expect(Kernel).to receive(:system).with('cf push -f manifests/test.yml').and_return(false)
94
+ expect(Kernel).to_not receive(:system).with('cf map-route test-app example.com')
95
+ expect do
96
+ Rake::Task['cf:deploy:test'].invoke
97
+ end.to raise_error
72
98
  end
73
99
 
74
- xit 'should throw decent error if manifest invalid' do
100
+ it 'should throw decent error if manifest does not exist' do
101
+ expect do
102
+ described_class.rake_tasks! do
103
+ environment :undefined
104
+ end
105
+ end.to raise_error
106
+ end
107
+
108
+ it 'should throw decent error if manifest invalid' do
109
+ expect do
110
+ described_class.rake_tasks! do
111
+ environment :invalid_manifest do
112
+ manifest 'spec/spec_helper.rb'
113
+ end
114
+ end
115
+ end.to raise_error
75
116
  end
76
117
 
77
118
  it 'should allow individual manifest to be specified' do
@@ -84,7 +125,7 @@ describe CF::Deploy do
84
125
  end
85
126
 
86
127
  expect(Kernel).to receive(:system).with('cf login').ordered
87
- expect(Kernel).to receive(:system).with('cf push -f manifests/staging.yml').ordered
128
+ expect(Kernel).to receive(:system).with('cf push -f manifests/staging.yml').and_return(true).ordered
88
129
  Rake::Task['cf:deploy:custom_manifest'].invoke
89
130
  end
90
131
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'cf-deploy'
3
+ require 'rake'
4
+
5
+ describe CF::Deploy do
6
+ before :each do
7
+ Rake::Task.clear
8
+ end
9
+
10
+ context 'Flip production environments' do
11
+
12
+ let :rake_tasks! do
13
+ described_class.rake_tasks! do
14
+ environment :production do
15
+ flip_route 'yourwebsite.com', 'www'
16
+ flip_route 'yourwebsite.com', 'www-origin'
17
+ end
18
+ end
19
+ end
20
+
21
+ it 'should map to blue if green is currently mapped' do
22
+ Dir.chdir('spec/') do
23
+ rake_tasks!
24
+ expect(Kernel).to receive(:system).with('cf login').ordered
25
+ expect(IO).to receive(:popen).with("cf routes | grep 'www *yourwebsite.com'") { double(:read => 'production-green-app', :close => nil) }
26
+ expect(Kernel).to receive(:system).with('cf map-route production-blue-app yourwebsite.com -n www').ordered
27
+ expect(Kernel).to receive(:system).with('cf unmap-route production-green-app yourwebsite.com -n www').ordered
28
+ expect(IO).to receive(:popen).with("cf routes | grep 'www *yourwebsite.com'") { double(:read => 'production-green-app', :close => nil) }
29
+ expect(Kernel).to receive(:system).with('cf map-route production-blue-app yourwebsite.com -n www-origin').ordered
30
+ expect(Kernel).to receive(:system).with('cf unmap-route production-green-app yourwebsite.com -n www-origin').ordered
31
+ Rake::Task['cf:deploy:production:flip'].invoke
32
+ end
33
+ end
34
+
35
+ it 'should map to green if blue is currently mapped' do
36
+ Dir.chdir('spec/') do
37
+ rake_tasks!
38
+ expect(Kernel).to receive(:system).with('cf login').ordered
39
+ expect(IO).to receive(:popen).with("cf routes | grep 'www *yourwebsite.com'") { double(:read => 'production-blue-app', :close => nil) }
40
+ expect(Kernel).to receive(:system).with('cf map-route production-green-app yourwebsite.com -n www').ordered
41
+ expect(Kernel).to receive(:system).with('cf unmap-route production-blue-app yourwebsite.com -n www').ordered
42
+ expect(IO).to receive(:popen).with("cf routes | grep 'www *yourwebsite.com'") { double(:read => 'production-blue-app', :close => nil) }
43
+ expect(Kernel).to receive(:system).with('cf map-route production-green-app yourwebsite.com -n www-origin').ordered
44
+ expect(Kernel).to receive(:system).with('cf unmap-route production-blue-app yourwebsite.com -n www-origin').ordered
45
+ Rake::Task['cf:deploy:production:flip'].invoke
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -41,11 +41,13 @@ describe CF::Deploy do
41
41
  described_class.rake_tasks! do
42
42
  environment :staging => 'asset:precompile'
43
43
  environment :test => ['asset:precompile', :clean]
44
+ environment :production => 'asset:precompile'
44
45
  end
45
46
  end
46
47
 
47
48
  expect(Rake::Task['cf:deploy:staging'].prerequisite_tasks[1]).to be(expected_task_1)
48
49
  expect(Rake::Task['cf:deploy:test'].prerequisite_tasks[2]).to be(expected_task_2)
50
+ expect(Rake::Task['cf:deploy:production'].prerequisite_tasks[1]).to be(expected_task_1)
49
51
  end
50
52
 
51
53
  it 'should have a configurable manifest glob options' do
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,3 @@
1
- require 'simplecov'
2
- require 'coveralls'
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
3
 
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
8
-
9
- SimpleCov.start
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Luke Morton
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-11-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: simplecov
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,34 +62,32 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
77
68
  version: 0.7.1
78
69
  - !ruby/object:Gem::Dependency
79
- name: coveralls
70
+ name: codeclimate-test-reporter
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ~>
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
- version: 0.7.0
75
+ version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ~>
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
- version: 0.7.0
82
+ version: '0'
94
83
  description:
95
84
  email:
96
- - luke@madebymade.co.uk
85
+ - luke@madetech.co.uk
97
86
  executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
90
+ - lib/cf/deploy/blue_green.rb
101
91
  - lib/cf/deploy/commands.rb
102
92
  - lib/cf/deploy/config.rb
103
93
  - lib/cf/deploy/env_config.rb
@@ -106,6 +96,7 @@ files:
106
96
  - lib/cf-deploy.rb
107
97
  - spec/blue_green_task_spec.rb
108
98
  - spec/deploy_task_spec.rb
99
+ - spec/flip_task_spec.rb
109
100
  - spec/login_task_spec.rb
110
101
  - spec/rake_tasks_spec.rb
111
102
  - spec/spec_helper.rb
@@ -114,32 +105,25 @@ files:
114
105
  homepage: https://github.com/madebymade/cf-deploy
115
106
  licenses:
116
107
  - MIT
108
+ metadata: {}
117
109
  post_install_message:
118
110
  rdoc_options: []
119
111
  require_paths:
120
112
  - lib
121
113
  required_ruby_version: !ruby/object:Gem::Requirement
122
- none: false
123
114
  requirements:
124
- - - ! '>='
115
+ - - '>='
125
116
  - !ruby/object:Gem::Version
126
117
  version: '0'
127
- segments:
128
- - 0
129
- hash: 3630708785980553311
130
118
  required_rubygems_version: !ruby/object:Gem::Requirement
131
- none: false
132
119
  requirements:
133
- - - ! '>='
120
+ - - '>='
134
121
  - !ruby/object:Gem::Version
135
122
  version: '0'
136
- segments:
137
- - 0
138
- hash: 3630708785980553311
139
123
  requirements: []
140
124
  rubyforge_project:
141
- rubygems_version: 1.8.23
125
+ rubygems_version: 2.0.3
142
126
  signing_key:
143
- specification_version: 3
127
+ specification_version: 4
144
128
  summary: Rake tasks for deploying to CloudFoundry v6+
145
129
  test_files: []