keel 0.1.0
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/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/keel.gemspec +28 -0
- data/lib/generators/keel/config_generator.rb +13 -0
- data/lib/generators/keel/controller_generator.rb +59 -0
- data/lib/generators/keel/service_generator.rb +55 -0
- data/lib/generators/keel/templates/gc-controller.yml.erb +58 -0
- data/lib/generators/keel/templates/gc-service.yml.erb +15 -0
- data/lib/generators/keel/templates/gcloud.yml +19 -0
- data/lib/keel/gcloud/auth.rb +32 -0
- data/lib/keel/gcloud/cli.rb +22 -0
- data/lib/keel/gcloud/component.rb +24 -0
- data/lib/keel/gcloud/config.rb +109 -0
- data/lib/keel/gcloud/kubernetes/namespace.rb +62 -0
- data/lib/keel/gcloud/kubernetes/pod.rb +96 -0
- data/lib/keel/gcloud/kubernetes/replication_controller.rb +117 -0
- data/lib/keel/gcloud/kubernetes.rb +3 -0
- data/lib/keel/gcloud/notifier/base.rb +39 -0
- data/lib/keel/gcloud/notifier/new_relic.rb +17 -0
- data/lib/keel/gcloud/notifier.rb +2 -0
- data/lib/keel/gcloud/prompter.rb +88 -0
- data/lib/keel/gcloud.rb +7 -0
- data/lib/keel/railtie.rb +7 -0
- data/lib/keel/version.rb +3 -0
- data/lib/keel.rb +7 -0
- data/lib/tasks/keel.rake +157 -0
- metadata +147 -0
data/lib/tasks/keel.rake
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
namespace :keel do
|
2
|
+
desc 'Deploy the specified SHA to a given environment'
|
3
|
+
task :deploy, [:environment, :deploy_sha] do |_, args|
|
4
|
+
prompter = Keel::GCloud::Prompter.new
|
5
|
+
config = Keel::GCloud::Config.new
|
6
|
+
app = config.app_name
|
7
|
+
|
8
|
+
# Fetch namespaces from k8s
|
9
|
+
namespaces = Keel::GCloud::Kubernetes::Namespace.fetch_all
|
10
|
+
unless namespaces
|
11
|
+
message = 'Unable to connect to Kubernetes, please try again later...'
|
12
|
+
prompter.print message, :error
|
13
|
+
abort
|
14
|
+
end
|
15
|
+
|
16
|
+
# Prompt the user for the env and git commit to deploy
|
17
|
+
deploy_env = prompter.prompt_for_namespace namespaces, args[:environment]
|
18
|
+
deploy_sha = prompter.prompt_for_sha args[:deploy_sha]
|
19
|
+
|
20
|
+
# Retrieve a replication controller configuration from the cluster
|
21
|
+
rcs = Keel::GCloud::Kubernetes::ReplicationController.fetch_all deploy_env, app
|
22
|
+
unless rcs
|
23
|
+
message = 'Unable to connect to Kubernetes, please try again later...'
|
24
|
+
prompter.print message, :error
|
25
|
+
abort
|
26
|
+
end
|
27
|
+
rc = rcs.first
|
28
|
+
|
29
|
+
unless rc
|
30
|
+
message = "Could not find a replication controller for the \"#{deploy_env}\" environment"
|
31
|
+
prompter.print message, :error
|
32
|
+
abort
|
33
|
+
end
|
34
|
+
|
35
|
+
# Prep deployment:
|
36
|
+
# 1. Update image
|
37
|
+
# 2. Update replica count
|
38
|
+
# 3. Write out to a tmp file
|
39
|
+
# 4. Replace the running controller
|
40
|
+
# - this will create 1 new pod with the updated code
|
41
|
+
|
42
|
+
# We can get away with first since it is a single container pod
|
43
|
+
container = rc.containers.first
|
44
|
+
container['image'] = "gcr.io/quepid-1051/quails:#{deploy_sha}"
|
45
|
+
rc.increment_replica_count
|
46
|
+
rc.update
|
47
|
+
|
48
|
+
# Get a list of pods for the RC, this must be done pre-change
|
49
|
+
pods = Keel::GCloud::Kubernetes::Pod.fetch_all deploy_env, app
|
50
|
+
unless pods
|
51
|
+
message = 'Unable to connect to Kubernetes, please try again later...'
|
52
|
+
prompter.print message, :error
|
53
|
+
abort
|
54
|
+
end
|
55
|
+
|
56
|
+
# Iterate over all pods, checking to see if they are running
|
57
|
+
all_pods_running = false
|
58
|
+
while !all_pods_running do
|
59
|
+
prompter.print 'Waiting for new pods to start', :info
|
60
|
+
sleep 5
|
61
|
+
new_pods = Keel::GCloud::Kubernetes::Pod.fetch_all deploy_env, app
|
62
|
+
|
63
|
+
all_pods_running = true
|
64
|
+
new_pods.each do |pod|
|
65
|
+
if !pod.running?
|
66
|
+
prompter.print "Pod \"#{pod.name}\" is not running", :info
|
67
|
+
all_pods_running = false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Nuke old pods
|
73
|
+
pods.each do |pod|
|
74
|
+
pod.delete
|
75
|
+
sleep 3
|
76
|
+
end
|
77
|
+
|
78
|
+
# Bring the replica count down and resubmit to the cluster,
|
79
|
+
# this kills the 1 extra pod
|
80
|
+
rcs = Keel::GCloud::Kubernetes::ReplicationController.fetch_all deploy_env, app
|
81
|
+
rc = rcs.first
|
82
|
+
rc.decrement_replica_count
|
83
|
+
rc.update
|
84
|
+
|
85
|
+
prompter.print 'Notifying NewRelic of deployment', :info
|
86
|
+
notifier = Keel::GCloud::Notifier::NewRelic.new env: deploy_env, sha: deploy_sha
|
87
|
+
notifier.notify
|
88
|
+
|
89
|
+
prompter.print 'Deployment complete', :success
|
90
|
+
end
|
91
|
+
|
92
|
+
desc 'Configures the local machine for communication with gcloud and k8s'
|
93
|
+
task :setup do |_|
|
94
|
+
prompter = Keel::GCloud::Prompter.new
|
95
|
+
config = Keel::GCloud::Config.new
|
96
|
+
|
97
|
+
if config.executable_missing?
|
98
|
+
message = 'Install Google Cloud command line tools'
|
99
|
+
message += "\n"
|
100
|
+
message += 'See: https://cloud.google.com/sdk/'
|
101
|
+
|
102
|
+
abort message.red
|
103
|
+
end
|
104
|
+
|
105
|
+
if config.system_configured?
|
106
|
+
abort 'App appears to already be configured on your system.'.green
|
107
|
+
end
|
108
|
+
|
109
|
+
prompter.print 'Updating tools', :info
|
110
|
+
Keel::GCloud::Component.update
|
111
|
+
|
112
|
+
prompter.print 'Authenticating with Google Cloud', :info
|
113
|
+
Keel::GCloud::Auth.authenticate
|
114
|
+
|
115
|
+
prompter.print 'Install Kubernetes', :info
|
116
|
+
Keel::GCloud::Component.install_k8s
|
117
|
+
|
118
|
+
prompter.print 'Setting gcloud properties', :info
|
119
|
+
config.set_properties
|
120
|
+
|
121
|
+
prompter.print 'Pulling Kubernetes auth configuration', :info
|
122
|
+
auth = Keel::GCloud::Auth.new config: config
|
123
|
+
auth.authenticate_k8s
|
124
|
+
end
|
125
|
+
|
126
|
+
desc 'Pulls logs for a given environment'
|
127
|
+
task :logs, [:environment] do |_, args|
|
128
|
+
prompter = Keel::GCloud::Prompter.new
|
129
|
+
config = Keel::GCloud::Config.new
|
130
|
+
app = config.app_name
|
131
|
+
|
132
|
+
# Fetch namespaces from k8s
|
133
|
+
namespaces = Keel::GCloud::Kubernetes::Namespace.fetch_all
|
134
|
+
unless namespaces
|
135
|
+
message = 'Unable to connect to Kubernetes, please try again later...'
|
136
|
+
prompter.print message, :error
|
137
|
+
abort
|
138
|
+
end
|
139
|
+
|
140
|
+
# Prompt the user for the env and to log and whether to tail the logs
|
141
|
+
deploy_env = prompter.prompt_for_namespace namespaces, args[:environment]
|
142
|
+
tail = prompter.prompt_for_tailing_logs
|
143
|
+
|
144
|
+
prompter.print "Getting pod information for #{deploy_env}", :info
|
145
|
+
pods = Keel::GCloud::Kubernetes::Pod.fetch_all deploy_env, app
|
146
|
+
|
147
|
+
unless pods.length > 0
|
148
|
+
message = "Could not find pods in the \"#{deploy_env}\" environment."
|
149
|
+
prompter.print message, :error
|
150
|
+
abort
|
151
|
+
end
|
152
|
+
|
153
|
+
# It seems that the first pod is the one we really want to look at for logs
|
154
|
+
pod = pods.first
|
155
|
+
pod.logs tail
|
156
|
+
end
|
157
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Youssef Chaker
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: inquirer
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
description: This gem lets you deploy your Rails application to your Kubernetes cluster.
|
84
|
+
email:
|
85
|
+
- ychaker@o19s.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- keel.gemspec
|
100
|
+
- lib/generators/keel/config_generator.rb
|
101
|
+
- lib/generators/keel/controller_generator.rb
|
102
|
+
- lib/generators/keel/service_generator.rb
|
103
|
+
- lib/generators/keel/templates/gc-controller.yml.erb
|
104
|
+
- lib/generators/keel/templates/gc-service.yml.erb
|
105
|
+
- lib/generators/keel/templates/gcloud.yml
|
106
|
+
- lib/keel.rb
|
107
|
+
- lib/keel/gcloud.rb
|
108
|
+
- lib/keel/gcloud/auth.rb
|
109
|
+
- lib/keel/gcloud/cli.rb
|
110
|
+
- lib/keel/gcloud/component.rb
|
111
|
+
- lib/keel/gcloud/config.rb
|
112
|
+
- lib/keel/gcloud/kubernetes.rb
|
113
|
+
- lib/keel/gcloud/kubernetes/namespace.rb
|
114
|
+
- lib/keel/gcloud/kubernetes/pod.rb
|
115
|
+
- lib/keel/gcloud/kubernetes/replication_controller.rb
|
116
|
+
- lib/keel/gcloud/notifier.rb
|
117
|
+
- lib/keel/gcloud/notifier/base.rb
|
118
|
+
- lib/keel/gcloud/notifier/new_relic.rb
|
119
|
+
- lib/keel/gcloud/prompter.rb
|
120
|
+
- lib/keel/railtie.rb
|
121
|
+
- lib/keel/version.rb
|
122
|
+
- lib/tasks/keel.rake
|
123
|
+
homepage: https://github.com/o19s/keel
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.5
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Deploy your Rails app to Kubernetes.
|
147
|
+
test_files: []
|