cf-deploy 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d9d3ab27f6234099b40263d3084f85a9977a18d
4
- data.tar.gz: a362835aea9906c7d5e457b2cf160e787a0ca9b8
3
+ metadata.gz: cbe6ee713d98618faadead85006d67ac7c1d4605
4
+ data.tar.gz: 99cf899f683d77a983708101a80532a597e698a4
5
5
  SHA512:
6
- metadata.gz: f700d71e5a1871c84d59fc792b754186921e8f11d8c91a5ad5dc310638f2957e88a9c8a14b164ee352fe26f850f72314813da43692058d1c49a2c5598354d4dd
7
- data.tar.gz: 94a051241f13054e23568946eb33af97da8cff885326bb0e0faf62e41a7e1a56f6d321ffd9341142dff3a240529f64cf910e5cea343b35078cbac209dbb4dfaa
6
+ metadata.gz: 89cadfc6b4d7a97b90e58d3764f0c52d13abe3a178a309b51903016a64c098ba8644fda6f943fe774a43b50c0c9d306ad9e6372d60e7a866ebbb888f48ce2e7a
7
+ data.tar.gz: 023cd1fd9b7fdd51f8842cc06390bfd95672b61642bc6a8894ecf3558f732f4e319f7bb70bffdd2e02c0563bc90e48a2c71a8efa9a0e6ac1f76a7e06cf2a3dd4
data/lib/cf/deploy.rb CHANGED
@@ -32,9 +32,8 @@ module CF
32
32
  def define_login_task
33
33
  return Rake::Task['cf:login'] if Rake::Task.task_defined?('cf:login')
34
34
 
35
- Rake::Task.define_task('cf:login') do
36
- cf.login(config)
37
- end
35
+ task = Rake::Task.define_task('cf:login') { cf.login(config) }
36
+ task.add_description('Login to cf command line')
38
37
  end
39
38
 
40
39
  def define_deploy_tasks(env)
@@ -46,7 +45,7 @@ module CF
46
45
  end
47
46
 
48
47
  def define_deploy_task(env, deployment)
49
- Rake::Task.define_task(deployment[:task_name] => env[:deps]) do
48
+ task = Rake::Task.define_task(deployment[:task_name] => env[:deps]) do
50
49
  unless cf.push(deployment[:manifest])
51
50
  raise "Failed to deploy #{deployment}"
52
51
  end
@@ -57,12 +56,14 @@ module CF
57
56
  end
58
57
  end
59
58
 
60
- unless env[:runtime_memory].nil?
61
- deployment[:app_names].each do |app_name|
62
- cf.scale_memory(app_name, env[:runtime_memory])
59
+ deployment[:apps].each do |app|
60
+ unless env[:runtime_memory].nil? and app[:runtime_memory].nil?
61
+ cf.scale_memory(app[:name], env[:runtime_memory] || app[:runtime_memory])
63
62
  end
64
63
  end
65
64
  end
65
+
66
+ task.add_description("Deploy #{deployment[:app_names].join(', ')}")
66
67
  end
67
68
  end
68
69
  end
@@ -19,14 +19,16 @@ module CF
19
19
  private
20
20
 
21
21
  def define_deployment_task
22
- Rake::Task.define_task(env[:task_name] => env[:deps]) do
22
+ task = Rake::Task.define_task(env[:task_name] => env[:deps]) do
23
23
  task_name = EnvConfig.task_name("#{env[:name]}_#{idle_color(env)}")
24
24
  Rake::Task[task_name].invoke
25
25
  end
26
+
27
+ task.add_description("Deploy #{env}")
26
28
  end
27
29
 
28
30
  def define_flip_task
29
- Rake::Task.define_task("#{env[:task_name]}:flip" => 'cf:login') do
31
+ task = Rake::Task.define_task("#{env[:task_name]}:flip" => 'cf:login') do
30
32
  live_app_name = app_name_from_color(live_color(env))
31
33
  idle_app_name = app_name_from_color(idle_color(env))
32
34
 
@@ -35,14 +37,18 @@ module CF
35
37
  cf.unmap_route(route, live_app_name)
36
38
  end
37
39
  end
40
+
41
+ task.add_description('Flip routes to point at currently idle app')
38
42
  end
39
43
 
40
44
  def define_stop_idle_task
41
- Rake::Task.define_task("#{env[:task_name]}:stop_idle" => 'cf:login') do
45
+ task = Rake::Task.define_task("#{env[:task_name]}:stop_idle" => 'cf:login') do
42
46
  env.app_names_for_colour(idle_color(env)).each do |app_name|
43
47
  cf.stop(app_name)
44
48
  end
45
49
  end
50
+
51
+ task.add_description('Stop currently idle app')
46
52
  end
47
53
 
48
54
  def app_name_from_color(colour)
@@ -30,7 +30,8 @@ module CF
30
30
  def deployment_for_manifest(manifest)
31
31
  { task_name: deployment_task_name(manifest),
32
32
  manifest: manifest,
33
- app_names: app_names_for_manifest(manifest) }
33
+ app_names: app_names_for_manifest(manifest),
34
+ apps: apps_for_manifest(manifest) }
34
35
  end
35
36
 
36
37
  def deployment_task_name(manifest)
@@ -41,14 +42,20 @@ module CF
41
42
  end
42
43
  end
43
44
 
44
- def app_names_for_manifest(manifest)
45
+ def apps_for_manifest(manifest)
45
46
  config = YAML.load_file(manifest)
46
47
 
47
48
  if config['applications'].nil?
48
49
  raise "No applications defined in YAML manifest #{manifest}"
49
50
  end
50
51
 
51
- config['applications'].map { |a| a['name'] }
52
+ config['applications'].map do |app|
53
+ app.reduce({}) { |app, (k, v)| app.merge(k.to_sym => v) }
54
+ end
55
+ end
56
+
57
+ def app_names_for_manifest(manifest)
58
+ apps_for_manifest(manifest).map { |a| a[:name] }
52
59
  end
53
60
 
54
61
  def app_name_for_colour(colour)
@@ -1,5 +1,5 @@
1
1
  module CF
2
2
  class Deploy
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.7'
4
4
  end
5
5
  end
@@ -65,19 +65,32 @@ describe CF::Deploy do
65
65
  Rake::Task['cf:deploy:test'].invoke
66
66
  end
67
67
 
68
- it 'should change memory after deployment if runtime_memory specified' do
68
+ it 'should change memory after deployment if runtime_memory specified in manifest' do
69
69
  Dir.chdir('spec/') do
70
70
  described_class.rake_tasks! do
71
- environment :staging do
72
- runtime_memory '256M'
73
- end
71
+ environment :staging
74
72
  end
75
73
  end
76
74
 
77
75
  expect(Kernel).to receive(:system).with('cf login').ordered
78
- expect(Kernel).to receive(:system).with('cf push -f manifests/staging.yml').and_return(true).ordered
76
+ expect(Kernel).to receive(:system).with('cf push -f manifests/staging_with_runtime.yml').and_return(true).ordered
79
77
  expect(Kernel).to receive(:system).with('cf scale staging-app -f -m 256M').and_return(true).ordered
80
- Rake::Task['cf:deploy:staging'].invoke
78
+ Rake::Task['cf:deploy:staging_with_runtime'].invoke
79
+ end
80
+
81
+ it 'should change memory after deployment if runtime_memory specified in cf:deploy config' do
82
+ Dir.chdir('spec/') do
83
+ described_class.rake_tasks! do
84
+ environment :staging_with_runtime do
85
+ runtime_memory '512M'
86
+ end
87
+ end
88
+ end
89
+
90
+ expect(Kernel).to receive(:system).with('cf login').ordered
91
+ expect(Kernel).to receive(:system).with('cf push -f manifests/staging_with_runtime.yml').and_return(true).ordered
92
+ expect(Kernel).to receive(:system).with('cf scale staging-app -f -m 512M').and_return(true).ordered
93
+ Rake::Task['cf:deploy:staging_with_runtime'].invoke
81
94
  end
82
95
 
83
96
  it 'should not map routes if push command fails' do
@@ -0,0 +1,13 @@
1
+ describe CF::Deploy::EnvConfig do
2
+ let(:env_config) { described_class.new(:staging, 'assets:precompile', ['spec/manifests/staging_with_runtime.yml']) }
3
+
4
+ context 'when reading application names' do
5
+ subject { env_config[:deployments].first[:app_names] }
6
+ it { is_expected.to include('staging-app') }
7
+ end
8
+
9
+ context 'when reading application level config' do
10
+ subject { env_config[:deployments].first[:apps] }
11
+ it { is_expected.to include(a_hash_including(name: 'staging-app', runtime_memory: '256M')) }
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Morton
@@ -100,6 +100,7 @@ files:
100
100
  - lib/cf/deploy/version.rb
101
101
  - spec/blue_green_task_spec.rb
102
102
  - spec/deploy_task_spec.rb
103
+ - spec/env_config_spec.rb
103
104
  - spec/flip_task_spec.rb
104
105
  - spec/login_task_spec.rb
105
106
  - spec/rake_tasks_spec.rb