pcf_blue_green 0.28 → 0.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pcf_blue_green/version.rb +1 -1
- data/lib/pcf_blue_green.rb +82 -0
- data/lib/shared-deploy-functions.sh +0 -4
- data/pcf_blue_green.gemspec +1 -0
- data/spec/mocks/custom_routes.txt +13 -0
- data/spec/mocks/custom_routes_domain_host.txt +15 -0
- data/spec/mocks/simple_routes.txt +5 -0
- data/spec/pcf_blue_green_spec.rb +158 -2
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 822cec14d1a275a2eb09b8a69bbad96ab2954b5e
|
4
|
+
data.tar.gz: 29bea7873439cff74b113067e0bff1e2b25168ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44a4e30abaec0de6b836f45ab21b0d1ca2904318efeee6dd2ee0611ec52a17394bbb830e82b0b4b19ac9e3f052ec0dd46dbc527ed5f5efc7c919c6f13bab1abd
|
7
|
+
data.tar.gz: 636c83bde99010bfa824f55216e26138b75bc8b4b2314bd412912e7f1d5a617cf59b56c525c3af15f7d6f8fc6908b3d1d2ed50b8085db2dce0d01bb1115186f9
|
data/lib/pcf_blue_green.rb
CHANGED
@@ -6,6 +6,88 @@ require "json"
|
|
6
6
|
module PcfBlueGreen
|
7
7
|
class BlueGreenDeployFailed < StandardError
|
8
8
|
end
|
9
|
+
|
10
|
+
class CleanupBlueFailed < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class Routing
|
15
|
+
|
16
|
+
def initialize(url, user, pass, org, space, call_login = false, opts = {})
|
17
|
+
@options = {:login => '--skip-ssl-validation'}.merge(opts)
|
18
|
+
@url = url
|
19
|
+
@user = user
|
20
|
+
@pass = pass
|
21
|
+
@org = org
|
22
|
+
@space = space
|
23
|
+
@login_options = @options[:login]
|
24
|
+
login if call_login
|
25
|
+
end
|
26
|
+
|
27
|
+
def cleanup_blue
|
28
|
+
remap-routes
|
29
|
+
status = bash("#{@source_cmd} && remove-blue")
|
30
|
+
raise PcfBlueGreen::CleanupBlueFailed unless status
|
31
|
+
bash("#{@source_cmd} && announce-success")
|
32
|
+
end
|
33
|
+
|
34
|
+
def remap_routes
|
35
|
+
puts "Remapping routes..."
|
36
|
+
puts "cf_app is #{ENV['cf_app']}"
|
37
|
+
puts "green is #{ENV['green']}"
|
38
|
+
|
39
|
+
puts cf_routes_output
|
40
|
+
mapped_routes = []
|
41
|
+
|
42
|
+
if ENV['handle_all_paths']
|
43
|
+
cmd = "#{cf_routes_output} | tail -n +2 | awk '($5==ENVIRON[\"cf_app\"]) {print $3\" -n \"$2 \" --path \"substr($4,2) }' | xargs -n 5 #{map_route_command} #{ENV['green']}"
|
44
|
+
shell = Mixlib::ShellOut.new(cmd)
|
45
|
+
shell.run_command
|
46
|
+
unless shell.stderr.empty?
|
47
|
+
puts shell.stderr
|
48
|
+
raise PcfBlueGreen::CleanupBlueFailed
|
49
|
+
end
|
50
|
+
mapped_routes += shell.stdout.split("\n")
|
51
|
+
end
|
52
|
+
cmd = "#{cf_routes_output} | tail -n +2 | awk '($4==ENVIRON[\"cf_app\"]) {print $3\" -n \" $2}' | xargs -n 3 #{map_route_command} #{ENV['green']}"
|
53
|
+
shell = Mixlib::ShellOut.new(cmd)
|
54
|
+
shell.run_command
|
55
|
+
unless shell.stderr.empty?
|
56
|
+
puts shell.stderr
|
57
|
+
raise PcfBlueGreen::CleanupBlueFailed
|
58
|
+
end
|
59
|
+
mapped_routes += shell.stdout.split("\n")
|
60
|
+
|
61
|
+
mapped_routes
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def login
|
67
|
+
puts "Logging in to #{@url}"
|
68
|
+
cf_login = "cf login -a #{@url} -u #{@user} -p '#{@pass}' -o #{@org} -s #{@space} #{@login_options} > /dev/null"
|
69
|
+
cmd = "#{cf_login}"
|
70
|
+
shell = Mixlib::ShellOut.new(cmd)
|
71
|
+
shell.run_command
|
72
|
+
end
|
73
|
+
|
74
|
+
def cf_routes_output
|
75
|
+
cmd = "cf routes"
|
76
|
+
shell = Mixlib::ShellOut.new(cmd)
|
77
|
+
shell.run_command
|
78
|
+
shell.stdout
|
79
|
+
end
|
80
|
+
|
81
|
+
def map_route_command
|
82
|
+
"cf map-route"
|
83
|
+
end
|
84
|
+
|
85
|
+
def bash(command)
|
86
|
+
escaped_command = Shellwords.escape(command)
|
87
|
+
system "bash -c #{escaped_command}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
9
91
|
class SharedDeployFunctions
|
10
92
|
|
11
93
|
def initialize
|
data/pcf_blue_green.gemspec
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
space host domain port path type apps service
|
3
|
+
app-space onemoreapp apps.prod.domain.com onemoreapp
|
4
|
+
app-space otherapp apps.prod.domain.com otherapp
|
5
|
+
app-space customapp apps.prod.domain.com customapp
|
6
|
+
app-space otherapp apps.prod.domain.com customapp
|
7
|
+
app-space customapp apps.prod.otherdomain.com otherapp
|
8
|
+
app-space customapp apps.prod.domain.com /somepath1 customapp
|
9
|
+
app-space otherapp apps.prod.domain.com /somepath2 customapp
|
10
|
+
app-space otherapp apps.prod.domain.com /somepath3 customapp
|
11
|
+
app-space otherapp apps.prod.domain.com /somepath4 otherapp
|
12
|
+
app-space otherapp apps.prod.domain.com /somepath5 otherapp
|
13
|
+
app-space otherapp apps.prod.domain.com /somepath6 otherapp
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
space host domain port path type apps service
|
3
|
+
app-space first-app apps.prod.domain.com.com first-app
|
4
|
+
app-space second-app apps.prod.domain.com.com second-app
|
5
|
+
app-space third-app apps.prod.domain.com.com third-app
|
6
|
+
app-space third-app apps.prod.otherdomain.com third-app
|
7
|
+
app-space third-app apps.prod.domain.com.com /firstapp-path1 second-app
|
8
|
+
app-space third-app apps.prod.domain.com.com /firstapp-path2 second-app
|
9
|
+
app-space third-app apps.prod.domain.com.com /firstapp-path3 second-app
|
10
|
+
app-space third-app apps.prod.domain.com.com /firstapp-path4 second-app
|
11
|
+
app-space third-app apps.prod.domain.com.com /firstapp-path5 second-app
|
12
|
+
app-space third-app apps.prod.otherdomain.com /otherdomainpath first-app
|
13
|
+
app-space third-app apps.prod.domain.com.com /secondapp-path second-app
|
14
|
+
app-space third-app apps.prod.domain.com.com /secondapp-path second-app
|
15
|
+
app-space third-app-other-host apps.prod.otherdomain.com third-app
|
data/spec/pcf_blue_green_spec.rb
CHANGED
@@ -5,7 +5,163 @@ describe PcfBlueGreen do
|
|
5
5
|
expect(PcfBlueGreen::VERSION).not_to be nil
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
describe "blue green deploy clean-up" do
|
9
|
+
context 'main route domain' do
|
10
|
+
it 're-maps routes correctly for simple routes' do
|
11
|
+
|
12
|
+
expected_routes = %{simpleapp-app-space-green apps.prod.domain.com -n simpleapp}
|
13
|
+
|
14
|
+
ENV['APP_SPACE'] = 'app-space'
|
15
|
+
ENV['APP_NAME'] = 'simpleapp'
|
16
|
+
ENV['cf_app'] = 'simpleapp'
|
17
|
+
ENV['cf_api'] = 'https://api.sys.sandbox.test.com'
|
18
|
+
ENV['cf_user'] = 'testuser'
|
19
|
+
ENV['cf_password'] = 'password'
|
20
|
+
ENV['cf_org'] = 'ds'
|
21
|
+
ENV['green'] = 'simpleapp-app-space-green'
|
22
|
+
|
23
|
+
space = ENV['APP_SPACE']
|
24
|
+
app = ENV['APP_NAME']
|
25
|
+
api_url = ENV['cf_api']
|
26
|
+
username = ENV['cf_user']
|
27
|
+
password = ENV['cf_password']
|
28
|
+
org = ENV['cf_org']
|
29
|
+
|
30
|
+
|
31
|
+
@pcf_blue_green = PcfBlueGreen::Routing.new(api_url, username, password, org, space, login = false)
|
32
|
+
@pcf_blue_green.stub(:cf_routes_output).and_return('cat spec/mocks/simple_routes.txt')
|
33
|
+
@pcf_blue_green.stub(:map_route_command).and_return('echo')
|
34
|
+
expect(expected_routes).to eq(@pcf_blue_green.remap_routes.uniq.join(",\n"))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "it doesn't re-map routes with a path. Also doesn't re-map routes for other applications. Even with the same hostname" do
|
38
|
+
|
39
|
+
expected_routes = %{customapp-app-space-green apps.prod.domain.com -n customapp,
|
40
|
+
customapp-app-space-green apps.prod.domain.com -n otherapp}
|
41
|
+
|
42
|
+
|
43
|
+
ENV['APP_SPACE'] = 'app-space'
|
44
|
+
ENV['APP_NAME'] = 'customapp'
|
45
|
+
ENV['cf_app'] = 'customapp'
|
46
|
+
ENV['cf_api'] = 'https://api.sys.sandbox.test.com'
|
47
|
+
ENV['cf_user'] = 'testuser'
|
48
|
+
ENV['cf_password'] = 'password'
|
49
|
+
ENV['cf_org'] = 'ds'
|
50
|
+
ENV['green'] = 'customapp-app-space-green'
|
51
|
+
|
52
|
+
space = ENV['APP_SPACE']
|
53
|
+
app = ENV['APP_NAME']
|
54
|
+
api_url = ENV['cf_api']
|
55
|
+
username = ENV['cf_user']
|
56
|
+
password = ENV['cf_password']
|
57
|
+
org = ENV['cf_org']
|
58
|
+
|
59
|
+
|
60
|
+
@pcf_blue_green = PcfBlueGreen::Routing.new(api_url, username, password, org, space, login = false)
|
61
|
+
@pcf_blue_green.stub(:cf_routes_output).and_return('cat spec/mocks/custom_routes.txt')
|
62
|
+
@pcf_blue_green.stub(:map_route_command).and_return('echo')
|
63
|
+
expect(expected_routes).to eq(@pcf_blue_green.remap_routes.uniq.join(",\n"))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'handle_all_paths' do
|
68
|
+
it "re-maps the application routes including paths and custom domains" do
|
69
|
+
|
70
|
+
expected_routes = %{customapp-app-space-green apps.prod.domain.com -n customapp --path somepath1,
|
71
|
+
customapp-app-space-green apps.prod.domain.com -n otherapp --path somepath2,
|
72
|
+
customapp-app-space-green apps.prod.domain.com -n otherapp --path somepath3,
|
73
|
+
customapp-app-space-green apps.prod.domain.com -n customapp,
|
74
|
+
customapp-app-space-green apps.prod.domain.com -n otherapp}
|
75
|
+
|
76
|
+
|
77
|
+
ENV['APP_SPACE'] = 'app-space'
|
78
|
+
ENV['APP_NAME'] = 'customapp'
|
79
|
+
ENV['cf_app'] = 'customapp'
|
80
|
+
ENV['cf_api'] = 'https://api.sys.sandbox.test.com'
|
81
|
+
ENV['cf_user'] = 'testuser'
|
82
|
+
ENV['cf_password'] = 'password'
|
83
|
+
ENV['cf_org'] = 'ds'
|
84
|
+
ENV['green'] = 'customapp-app-space-green'
|
85
|
+
ENV['handle_all_paths'] = 'true'
|
86
|
+
|
87
|
+
space = ENV['APP_SPACE']
|
88
|
+
app = ENV['APP_NAME']
|
89
|
+
api_url = ENV['cf_api']
|
90
|
+
username = ENV['cf_user']
|
91
|
+
password = ENV['cf_password']
|
92
|
+
org = ENV['cf_org']
|
93
|
+
|
94
|
+
|
95
|
+
@pcf_blue_green = PcfBlueGreen::Routing.new(api_url, username, password, org, space, login = false)
|
96
|
+
@pcf_blue_green.stub(:cf_routes_output).and_return('cat spec/mocks/custom_routes.txt')
|
97
|
+
@pcf_blue_green.stub(:map_route_command).and_return('echo')
|
98
|
+
expect(expected_routes).to eq(@pcf_blue_green.remap_routes.uniq.join(",\n"))
|
99
|
+
end
|
100
|
+
it "re-maps application routes including paths" do
|
101
|
+
|
102
|
+
expected_routes = %{second-app-app-space-green apps.prod.domain.com.com -n third-app --path firstapp-path1,
|
103
|
+
second-app-app-space-green apps.prod.domain.com.com -n third-app --path firstapp-path2,
|
104
|
+
second-app-app-space-green apps.prod.domain.com.com -n third-app --path firstapp-path3,
|
105
|
+
second-app-app-space-green apps.prod.domain.com.com -n third-app --path firstapp-path4,
|
106
|
+
second-app-app-space-green apps.prod.domain.com.com -n third-app --path firstapp-path5,
|
107
|
+
second-app-app-space-green apps.prod.domain.com.com -n third-app --path secondapp-path,
|
108
|
+
second-app-app-space-green apps.prod.domain.com.com -n second-app}
|
109
|
+
|
110
|
+
|
111
|
+
ENV['APP_SPACE'] = 'app-space'
|
112
|
+
ENV['APP_NAME'] = 'second-app'
|
113
|
+
ENV['cf_app'] = 'second-app'
|
114
|
+
ENV['cf_api'] = 'https://api.sys.sandbox.test.com'
|
115
|
+
ENV['cf_user'] = 'testuser'
|
116
|
+
ENV['cf_password'] = 'password'
|
117
|
+
ENV['cf_org'] = 'ds'
|
118
|
+
ENV['green'] = 'second-app-app-space-green'
|
119
|
+
ENV['handle_all_paths'] = 'true'
|
120
|
+
|
121
|
+
space = ENV['APP_SPACE']
|
122
|
+
app = ENV['APP_NAME']
|
123
|
+
api_url = ENV['cf_api']
|
124
|
+
username = ENV['cf_user']
|
125
|
+
password = ENV['cf_password']
|
126
|
+
org = ENV['cf_org']
|
127
|
+
|
128
|
+
|
129
|
+
@pcf_blue_green = PcfBlueGreen::Routing.new(api_url, username, password, org, space, login = false)
|
130
|
+
@pcf_blue_green.stub(:cf_routes_output).and_return('cat spec/mocks/custom_routes_domain_host.txt')
|
131
|
+
@pcf_blue_green.stub(:map_route_command).and_return('echo')
|
132
|
+
expect(expected_routes).to eq(@pcf_blue_green.remap_routes.uniq.join(",\n"))
|
133
|
+
end
|
134
|
+
|
135
|
+
it "re-maps application routes including paths. Also true for custom domain and host" do
|
136
|
+
|
137
|
+
expected_routes = %{third-app-app-space-green apps.prod.domain.com.com -n third-app,
|
138
|
+
third-app-app-space-green apps.prod.otherdomain.com -n third-app,
|
139
|
+
third-app-app-space-green apps.prod.otherdomain.com -n third-app-other-host}
|
140
|
+
|
141
|
+
|
142
|
+
ENV['APP_SPACE'] = 'app-space'
|
143
|
+
ENV['APP_NAME'] = 'third-app'
|
144
|
+
ENV['cf_app'] = 'third-app'
|
145
|
+
ENV['cf_api'] = 'https://api.sys.sandbox.test.com'
|
146
|
+
ENV['cf_user'] = 'testuser'
|
147
|
+
ENV['cf_password'] = 'password'
|
148
|
+
ENV['cf_org'] = 'ds'
|
149
|
+
ENV['green'] = 'third-app-app-space-green'
|
150
|
+
ENV['handle_all_paths'] = 'true'
|
151
|
+
|
152
|
+
space = ENV['APP_SPACE']
|
153
|
+
app = ENV['APP_NAME']
|
154
|
+
api_url = ENV['cf_api']
|
155
|
+
username = ENV['cf_user']
|
156
|
+
password = ENV['cf_password']
|
157
|
+
org = ENV['cf_org']
|
158
|
+
|
159
|
+
|
160
|
+
@pcf_blue_green = PcfBlueGreen::Routing.new(api_url, username, password, org, space, login = false)
|
161
|
+
@pcf_blue_green.stub(:cf_routes_output).and_return('cat spec/mocks/custom_routes_domain_host.txt')
|
162
|
+
@pcf_blue_green.stub(:map_route_command).and_return('echo')
|
163
|
+
expect(expected_routes).to eq(@pcf_blue_green.remap_routes.uniq.join(",\n"))
|
164
|
+
end
|
165
|
+
end
|
10
166
|
end
|
11
167
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcf_blue_green
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.30'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pawel Bardzinski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: pry
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
75
89
|
description: This is a gem that encapsulates the blue-green bash script. This allows
|
76
90
|
to run blue-green deployments easily
|
77
91
|
email:
|
@@ -92,6 +106,9 @@ files:
|
|
92
106
|
- lib/pcf_blue_green/version.rb
|
93
107
|
- lib/shared-deploy-functions.sh
|
94
108
|
- pcf_blue_green.gemspec
|
109
|
+
- spec/mocks/custom_routes.txt
|
110
|
+
- spec/mocks/custom_routes_domain_host.txt
|
111
|
+
- spec/mocks/simple_routes.txt
|
95
112
|
- spec/pcf_blue_green_spec.rb
|
96
113
|
- spec/spec_helper.rb
|
97
114
|
homepage: https://github.com/aaa-ncnu-ie/pcf_blue_green
|