pcf_blue_green 0.0.7
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pcf_blue_green.rb +30 -0
- data/lib/pcf_blue_green/version.rb +3 -0
- data/lib/shared-deploy-functions.sh +180 -0
- data/pcf_blue_green.gemspec +35 -0
- data/spec/pcf_blue_green_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b10b6e44b1667c5d4a7cd3b3b4592b2c8cd4e780
|
4
|
+
data.tar.gz: bf7a76935370d4d51d88cd1547e3f6dab21e9db9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f188a42eaba474e19caeaca127ba3b6d4a49484bbf1353df76e28bf297ae6c4adfd2dc9eab9fd61c549748e84886ad7edac20b1fb425ff051261baa7c9efc6f1
|
7
|
+
data.tar.gz: f0bb624d396fe9479e85d2cdb09705cd1b914d800131cd50a2cf7be74fc867d44c519c7ea434c52bfa98ecb677f07c798de05f7b6a8402e2ce90216f035f6e78
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at pawel.bardzinski@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pcf_blue_green"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "pcf_blue_green/version"
|
2
|
+
require 'mixlib/shellout'
|
3
|
+
require 'shellwords'
|
4
|
+
|
5
|
+
|
6
|
+
module PcfBlueGreen
|
7
|
+
class SharedDeployFunctions
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
cmd = "echo $(gem which pcf_blue_green)"
|
11
|
+
shell = Mixlib::ShellOut.new(cmd)
|
12
|
+
shell.run_command
|
13
|
+
gem_path = shell.stdout
|
14
|
+
sdf_path = gem_path.gsub("pcf_blue_green.rb\n", "shared-deploy-functions.sh")
|
15
|
+
@source_cmd = "source \'#{sdf_path}\'"
|
16
|
+
end
|
17
|
+
|
18
|
+
def blue_green_deploy
|
19
|
+
bash("#{@source_cmd} && blue-green")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def bash(command)
|
25
|
+
escaped_command = Shellwords.escape(command)
|
26
|
+
system "bash -c #{escaped_command}"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -o pipefail
|
4
|
+
|
5
|
+
export CF_COLOR=true
|
6
|
+
RCol='\033[0m'
|
7
|
+
BCya='\033[1;36m'
|
8
|
+
BGre='\033[1;32m'
|
9
|
+
BRed='\033[1;31m'
|
10
|
+
BWhi='\033[1;37m'
|
11
|
+
BYel='\033[1;33m'
|
12
|
+
Cya='\033[0;36m'
|
13
|
+
Gre='\033[0;32m'
|
14
|
+
Yel='\033[0;33m'
|
15
|
+
|
16
|
+
function announce-started {
|
17
|
+
echo -e "\n\n${BCya}---"
|
18
|
+
echo -e "${BCya}${1} started."
|
19
|
+
echo -e "${BCya}---${RCol}"
|
20
|
+
echo
|
21
|
+
echo
|
22
|
+
}
|
23
|
+
|
24
|
+
function announce-task {
|
25
|
+
echo -e "\n\n${BWhi}---"
|
26
|
+
echo -e "${BWhi}${1}"
|
27
|
+
echo -e "${BWhi}---${RCol}"
|
28
|
+
}
|
29
|
+
|
30
|
+
function announce-success {
|
31
|
+
echo -e "${BGre}Deploy successful.${RCol}"
|
32
|
+
}
|
33
|
+
|
34
|
+
function run-cmd {
|
35
|
+
echo -e "\n\n${Cya}${@}${RCol}\n"
|
36
|
+
$@
|
37
|
+
}
|
38
|
+
|
39
|
+
function set-ruby {
|
40
|
+
ruby_version=$(ruby --version >/dev/null 2>&1)
|
41
|
+
if [[ $? -eq "0" ]]; then
|
42
|
+
ruby_version=$(ruby --version)
|
43
|
+
echo -e "${Yel}Found Ruby: ${ruby_version}${RCol}"
|
44
|
+
elif [[ -s "$HOME/.rvm/scrfipts/rvm" ]] ; then
|
45
|
+
source "$HOME/.rvm/scriptfs/rvm"
|
46
|
+
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
|
47
|
+
source "/usr/local/rvm/scripts/rvm"
|
48
|
+
else
|
49
|
+
echo -e "${BRed}No Ruby and can't find RVM. Is it instaled?${RCol}"
|
50
|
+
exit -1
|
51
|
+
fi
|
52
|
+
}
|
53
|
+
|
54
|
+
function cf-setup {
|
55
|
+
announce-task "Logging in to ${cf_api}"
|
56
|
+
run-cmd cf api ${cf_api} --skip-ssl-validation
|
57
|
+
set +x
|
58
|
+
cf auth ${cf_user} ${cf_password}
|
59
|
+
run-cmd cf target -o ${cf_org} -s ${cf_space}
|
60
|
+
}
|
61
|
+
|
62
|
+
function cf-push {
|
63
|
+
local app_name=$1
|
64
|
+
local manifest=$2
|
65
|
+
announce-task "Pushing ${app_name}"
|
66
|
+
run-cmd cf push ${app_name} -f ${cf_manifest} --hostname ${app_name}
|
67
|
+
}
|
68
|
+
|
69
|
+
function check-health {
|
70
|
+
local app_url=$1
|
71
|
+
announce-task "Checking health"
|
72
|
+
cf_output=$(echo $(cf env quote2main)| grep -o 'User-Provided:.*')
|
73
|
+
echo "Executing curl of ${app_url}\n\n"
|
74
|
+
if echo $cf_output| egrep -o 'MAINTENANCE_ENABLED: \S*'
|
75
|
+
then
|
76
|
+
kv=$(echo $cf_output| egrep -o 'MAINTENANCE_ENABLED: \S*')
|
77
|
+
arrkv=(${kv// / })
|
78
|
+
if [ ${arrkv[1]} == true ] ; then
|
79
|
+
status=$(curl -sSIL -o /dev/null -w "%{http_code}" ${app_url} --insecure)
|
80
|
+
if [ $status == 503 ] ; then
|
81
|
+
echo -e "${BGre}curl of ${app_url} 503 OK"
|
82
|
+
else
|
83
|
+
echo ERROR: Expecting 503 status
|
84
|
+
exit 1
|
85
|
+
fi
|
86
|
+
else
|
87
|
+
curl -fsSIL --user "${BASIC_AUTH_USERNAME}:${BASIC_AUTH_PASSWORD}" ${app_url} --insecure
|
88
|
+
echo -e "${BGre}curl of ${app_url} 200 OK"
|
89
|
+
fi
|
90
|
+
else
|
91
|
+
curl -fsSIL --user "${BASIC_AUTH_USERNAME}:${BASIC_AUTH_PASSWORD}" ${app_url} --insecure
|
92
|
+
echo -e "${BGre}curl of ${app_url} 200 OK"
|
93
|
+
fi
|
94
|
+
}
|
95
|
+
|
96
|
+
function get-app-url {
|
97
|
+
run-cmd cf apps
|
98
|
+
|
99
|
+
app_url=$(cf apps | grep ${cf_app} | awk '{print $6}' | sed 's/,//')
|
100
|
+
|
101
|
+
echo -e "URL is ${BCya}${app_url}${RCol}"
|
102
|
+
}
|
103
|
+
|
104
|
+
function generate-manifest {
|
105
|
+
cf_manifest=$(mktemp -t "${cf_app}_manifest.XXXXXXXXXX")
|
106
|
+
|
107
|
+
run-cmd cf create-app-manifest ${cf_app} -p ${cf_manifest}
|
108
|
+
|
109
|
+
if [[ ! -z $cf_buildpack ]] #override buildpack
|
110
|
+
then
|
111
|
+
echo -e "\n\n${Cya}perl -p -i -e \"s|buildpack: .*|buildpack: ${cf_buildpack}|\" ${cf_manifest}${RCol}\n"
|
112
|
+
perl -p -i -e "s|buildpack: .*|buildpack: ${cf_buildpack}|" ${cf_manifest}
|
113
|
+
fi
|
114
|
+
}
|
115
|
+
|
116
|
+
function remap-routes {
|
117
|
+
announce-task "Remapping routes..."
|
118
|
+
echo "cf_app is ${cf_app}"
|
119
|
+
echo "green is ${green}"
|
120
|
+
set -x
|
121
|
+
run-cmd cf routes
|
122
|
+
run-cmd cf routes | tail -n +4 | grep ${cf_app} | awk '{print $3" -n "$2}'
|
123
|
+
cf routes | tail -n +4 | grep ${cf_app} | awk '{print $3" -n "$2}' | xargs -n 3 cf map-route ${green}
|
124
|
+
set +x
|
125
|
+
}
|
126
|
+
|
127
|
+
function remove-blue {
|
128
|
+
run-cmd cf delete ${blue} -f
|
129
|
+
run-cmd cf rename $green $blue
|
130
|
+
run-cmd cf delete-route $domain -n $green -f
|
131
|
+
}
|
132
|
+
|
133
|
+
function get-domain {
|
134
|
+
domain=$(cf routes | grep quote2main | awk '{print $3}' | grep "^apps\\." | tail -1)
|
135
|
+
announce-task "Domain is ${domain}"
|
136
|
+
}
|
137
|
+
|
138
|
+
function prep-green {
|
139
|
+
blue=${cf_app}
|
140
|
+
green="${cf_app}-${cf_space}-green"
|
141
|
+
generate-manifest
|
142
|
+
get-domain
|
143
|
+
}
|
144
|
+
|
145
|
+
function finally {
|
146
|
+
rm ${cf_manifest}
|
147
|
+
}
|
148
|
+
|
149
|
+
function on-fail {
|
150
|
+
finally
|
151
|
+
echo -e "${BRed}DEPLOY FAILED${RCol} - you may need to check '${BYel}cf apps${RCol}' and '${BYel}cf routes${RCol}' and do manual cleanup"
|
152
|
+
}
|
153
|
+
|
154
|
+
function blue-green {
|
155
|
+
echo -e "\n${BWhi}Starting blue/green deploy.${RCol}"
|
156
|
+
echo
|
157
|
+
echo
|
158
|
+
announce-started 'blue-green-deploy'
|
159
|
+
|
160
|
+
trap on-fail ERR
|
161
|
+
cd $app_directory
|
162
|
+
cf-setup
|
163
|
+
|
164
|
+
prep-green
|
165
|
+
|
166
|
+
cf-push ${green} ${cf_manifest}
|
167
|
+
check-health "https://${green}.${domain}"
|
168
|
+
|
169
|
+
remap-routes
|
170
|
+
remove-blue
|
171
|
+
announce-success
|
172
|
+
}
|
173
|
+
|
174
|
+
function simple-push {
|
175
|
+
announce-started
|
176
|
+
cd $app_directory
|
177
|
+
cf-setup
|
178
|
+
cf-push ${cf_app} ${cf_manifest}
|
179
|
+
announce-success
|
180
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pcf_blue_green/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pcf_blue_green"
|
8
|
+
spec.version = PcfBlueGreen::VERSION
|
9
|
+
spec.authors = ["Pawel Bardzinski"]
|
10
|
+
spec.email = ["pawel.bardzinski@csaa.com"]
|
11
|
+
|
12
|
+
spec.summary = "gem encapsualting blue-green bash script"
|
13
|
+
spec.description = "This is a gem that encapsulates the blue-green bash script. This allows to run blue-green deployments easily"
|
14
|
+
spec.homepage = "https://github.com/aaa-ncnu-ie/pcf_blue_green"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files`.split("\n")
|
26
|
+
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency 'mixlib-shellout', '~> 2.2', '>= 2.2.6'
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pcf_blue_green
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pawel Bardzinski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mixlib-shellout
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.2.6
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.6
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.13'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.13'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
description: This is a gem that encapsulates the blue-green bash script. This allows
|
76
|
+
to run blue-green deployments easily
|
77
|
+
email:
|
78
|
+
- pawel.bardzinski@csaa.com
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".gitignore"
|
84
|
+
- ".rspec"
|
85
|
+
- CODE_OF_CONDUCT.md
|
86
|
+
- Gemfile
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- bin/console
|
90
|
+
- bin/setup
|
91
|
+
- lib/pcf_blue_green.rb
|
92
|
+
- lib/pcf_blue_green/version.rb
|
93
|
+
- lib/shared-deploy-functions.sh
|
94
|
+
- pcf_blue_green.gemspec
|
95
|
+
- spec/pcf_blue_green_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: https://github.com/aaa-ncnu-ie/pcf_blue_green
|
98
|
+
licenses: []
|
99
|
+
metadata:
|
100
|
+
allowed_push_host: https://rubygems.org
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.6.10
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: gem encapsualting blue-green bash script
|
121
|
+
test_files: []
|