kuby-core 0.2.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +58 -0
- data/Gemfile +0 -4
- data/README.md +3 -160
- data/kuby-core.gemspec +5 -4
- data/lib/ext/krane/kubernetes_resource.rb +16 -0
- data/lib/kuby.rb +32 -17
- data/lib/kuby/definition.rb +20 -14
- data/lib/kuby/docker.rb +2 -1
- data/lib/kuby/docker/alpine.rb +0 -1
- data/lib/kuby/docker/assets_phase.rb +1 -1
- data/lib/kuby/docker/bundler_phase.rb +4 -2
- data/lib/kuby/docker/copy_phase.rb +1 -1
- data/lib/kuby/docker/inline_layer.rb +15 -0
- data/lib/kuby/docker/{phase.rb → layer.rb} +6 -5
- data/lib/kuby/docker/layer_stack.rb +30 -4
- data/lib/kuby/docker/metadata.rb +27 -1
- data/lib/kuby/docker/package_phase.rb +1 -1
- data/lib/kuby/docker/packages.rb +5 -4
- data/lib/kuby/docker/packages/simple_managed_package.rb +25 -0
- data/lib/kuby/docker/setup_phase.rb +1 -1
- data/lib/kuby/docker/spec.rb +4 -4
- data/lib/kuby/docker/tags.rb +18 -0
- data/lib/kuby/docker/webserver_phase.rb +1 -1
- data/lib/kuby/docker/yarn_phase.rb +1 -1
- data/lib/kuby/environment.rb +22 -0
- data/lib/kuby/kubernetes.rb +1 -0
- data/lib/kuby/kubernetes/deploy_task.rb +33 -0
- data/lib/kuby/kubernetes/deployer.rb +1 -2
- data/lib/kuby/kubernetes/minikube_provider.rb +5 -5
- data/lib/kuby/kubernetes/plugins/nginx_ingress.rb +12 -0
- data/lib/kuby/kubernetes/plugins/rails_app/database.rb +30 -9
- data/lib/kuby/kubernetes/plugins/rails_app/generators/kuby.rb +83 -0
- data/lib/kuby/kubernetes/plugins/rails_app/mysql.rb +17 -5
- data/lib/kuby/kubernetes/plugins/rails_app/plugin.rb +28 -42
- data/lib/kuby/kubernetes/plugins/rails_app/postgres.rb +132 -0
- data/lib/kuby/kubernetes/plugins/rails_app/sqlite.rb +20 -0
- data/lib/kuby/kubernetes/plugins/rails_app/tasks.rake +9 -4
- data/lib/kuby/kubernetes/spec.rb +52 -37
- data/lib/kuby/railtie.rb +0 -4
- data/lib/kuby/tasks.rb +18 -0
- data/lib/kuby/tasks/kuby.rake +24 -17
- data/lib/kuby/version.rb +1 -1
- metadata +21 -15
@@ -3,11 +3,16 @@ require 'rake'
|
|
3
3
|
namespace :kuby do
|
4
4
|
namespace :rails_app do
|
5
5
|
namespace :db do
|
6
|
-
task rewrite_config
|
7
|
-
|
6
|
+
task :rewrite_config do
|
7
|
+
Kuby.load!
|
8
|
+
|
9
|
+
config_file = File.join(Kuby.definition.kubernetes.plugin(:rails_app).root, 'config', 'database.yml')
|
8
10
|
database = Kuby.definition.kubernetes.plugin(:rails_app).database
|
9
|
-
|
10
|
-
|
11
|
+
|
12
|
+
if database.respond_to?(:rewritten_configs)
|
13
|
+
File.write(config_file, YAML.dump(database.rewritten_configs))
|
14
|
+
Kuby.logger.info("Wrote #{config_file}")
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
task :create_unless_exists do
|
data/lib/kuby/kubernetes/spec.rb
CHANGED
@@ -5,7 +5,7 @@ module Kuby
|
|
5
5
|
class Spec
|
6
6
|
extend ::KubeDSL::ValueFields
|
7
7
|
|
8
|
-
attr_reader :definition, :plugins
|
8
|
+
attr_reader :definition, :plugins, :tag
|
9
9
|
|
10
10
|
def initialize(definition)
|
11
11
|
@definition = definition
|
@@ -56,6 +56,24 @@ module Kuby
|
|
56
56
|
provider.after_configuration
|
57
57
|
end
|
58
58
|
|
59
|
+
def before_deploy
|
60
|
+
@tag ||= docker.metadata.tag
|
61
|
+
|
62
|
+
provider.before_deploy(resources)
|
63
|
+
@plugins.each { |_, plg| plg.before_deploy(resources) }
|
64
|
+
ensure
|
65
|
+
@tag = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def after_deploy
|
69
|
+
@tag ||= docker.metadata.tag
|
70
|
+
|
71
|
+
@plugins.each { |_, plg| plg.after_deploy(resources) }
|
72
|
+
provider.after_deploy(resources)
|
73
|
+
ensure
|
74
|
+
@tag = nil
|
75
|
+
end
|
76
|
+
|
59
77
|
def setup
|
60
78
|
provider.before_setup
|
61
79
|
provider.setup
|
@@ -68,26 +86,19 @@ module Kuby
|
|
68
86
|
end
|
69
87
|
|
70
88
|
def deploy(tag = nil)
|
71
|
-
tag
|
72
|
-
|
73
|
-
unless tag
|
74
|
-
raise Kuby::Docker::MissingTagError, 'could not find latest timestamped tag'
|
75
|
-
end
|
76
|
-
|
77
|
-
set_tag(tag)
|
78
|
-
|
79
|
-
provider.before_deploy(resources)
|
80
|
-
@plugins.each { |_, plg| plg.before_deploy(resources) }
|
89
|
+
@tag = tag
|
81
90
|
|
91
|
+
before_deploy
|
82
92
|
provider.deploy
|
83
|
-
|
84
|
-
@plugins.each { |_, plg| plg.after_deploy(resources) }
|
85
|
-
provider.after_deploy(resources)
|
93
|
+
after_deploy
|
86
94
|
end
|
87
95
|
|
88
96
|
def rollback
|
97
|
+
# it sucks that we have to reach into the rails app for this...
|
89
98
|
depl = provider.kubernetes_cli.get_object(
|
90
|
-
'deployment',
|
99
|
+
'deployment',
|
100
|
+
namespace.metadata.name,
|
101
|
+
plugin(:rails_app).deployment.metadata.name
|
91
102
|
)
|
92
103
|
|
93
104
|
image_url = depl.dig('spec', 'template', 'spec', 'containers', 0, 'image')
|
@@ -96,16 +107,10 @@ module Kuby
|
|
96
107
|
raise MissingDeploymentError, "couldn't find an existing deployment"
|
97
108
|
end
|
98
109
|
|
99
|
-
deployed_tag =
|
100
|
-
|
101
|
-
tag_idx = all_tags.index { |tag| tag.time == deployed_tag.time } || 0
|
110
|
+
deployed_tag = image_url.split(':').last
|
111
|
+
previous_tag = docker.metadata.previous_tag(deployed_tag)
|
102
112
|
|
103
|
-
|
104
|
-
raise Kuby::Docker::MissingTagError, 'could not find previous tag'
|
105
|
-
end
|
106
|
-
|
107
|
-
previous_tag = all_tags[tag_idx - 1]
|
108
|
-
deploy(previous_tag.to_s)
|
113
|
+
deploy(previous_tag)
|
109
114
|
end
|
110
115
|
|
111
116
|
def namespace(&block)
|
@@ -113,7 +118,7 @@ module Kuby
|
|
113
118
|
|
114
119
|
@namespace ||= KubeDSL.namespace do
|
115
120
|
metadata do
|
116
|
-
name "#{spec.selector_app}-#{spec.definition.environment}"
|
121
|
+
name "#{spec.selector_app}-#{spec.definition.environment.name}"
|
117
122
|
end
|
118
123
|
end
|
119
124
|
|
@@ -121,17 +126,35 @@ module Kuby
|
|
121
126
|
@namespace
|
122
127
|
end
|
123
128
|
|
129
|
+
def registry_secret(&block)
|
130
|
+
spec = self
|
131
|
+
|
132
|
+
@registry_secret ||= RegistrySecret.new do
|
133
|
+
metadata do
|
134
|
+
name "#{spec.selector_app}-registry-secret"
|
135
|
+
namespace spec.namespace.metadata.name
|
136
|
+
end
|
137
|
+
|
138
|
+
docker_config do
|
139
|
+
registry_host spec.docker.metadata.image_host
|
140
|
+
username spec.docker.credentials.username
|
141
|
+
password spec.docker.credentials.password
|
142
|
+
email spec.docker.credentials.email
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
@registry_secret.instance_eval(&block) if block
|
147
|
+
@registry_secret
|
148
|
+
end
|
149
|
+
|
124
150
|
def resources
|
125
151
|
@resources ||= Manifest.new([
|
126
152
|
namespace,
|
153
|
+
registry_secret,
|
127
154
|
*@plugins.flat_map { |_, plugin| plugin.resources }
|
128
155
|
])
|
129
156
|
end
|
130
157
|
|
131
|
-
def set_tag(tag)
|
132
|
-
plugin(:rails_app).set_image("#{docker.metadata.image_url}:#{tag}")
|
133
|
-
end
|
134
|
-
|
135
158
|
def selector_app
|
136
159
|
@selector_app ||= definition.app_name.downcase
|
137
160
|
end
|
@@ -139,14 +162,6 @@ module Kuby
|
|
139
162
|
def docker
|
140
163
|
definition.docker
|
141
164
|
end
|
142
|
-
|
143
|
-
private
|
144
|
-
|
145
|
-
def latest_tag
|
146
|
-
@latest_tag ||= docker.tags.local.latest_tags.find do |tag|
|
147
|
-
tag != ::Kuby::Docker::Tags::LATEST
|
148
|
-
end
|
149
|
-
end
|
150
165
|
end
|
151
166
|
end
|
152
167
|
end
|
data/lib/kuby/railtie.rb
CHANGED
@@ -7,10 +7,6 @@ module Kuby
|
|
7
7
|
load File.expand_path(File.join('tasks', 'kuby.rake'), __dir__)
|
8
8
|
end
|
9
9
|
|
10
|
-
initializer 'kuby.startup' do |_app|
|
11
|
-
Kuby.logger = Kuby::BasicLogger.new(STDERR)
|
12
|
-
end
|
13
|
-
|
14
10
|
initializer 'kuby.health_check_middleware' do |app|
|
15
11
|
app.middleware.use Kuby::Middleware::HealthCheck
|
16
12
|
end
|
data/lib/kuby/tasks.rb
CHANGED
@@ -16,6 +16,10 @@ module Kuby
|
|
16
16
|
puts formatter.format(tokens)
|
17
17
|
end
|
18
18
|
|
19
|
+
def setup
|
20
|
+
definition.kubernetes.setup
|
21
|
+
end
|
22
|
+
|
19
23
|
def build
|
20
24
|
docker.cli.build(
|
21
25
|
dockerfile: docker.to_dockerfile,
|
@@ -49,7 +53,17 @@ module Kuby
|
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
56
|
+
def deploy
|
57
|
+
definition.kubernetes.deploy
|
58
|
+
end
|
59
|
+
|
60
|
+
def rollback
|
61
|
+
definition.kubernetes.rollback
|
62
|
+
end
|
63
|
+
|
52
64
|
def print_resources
|
65
|
+
kubernetes.before_deploy
|
66
|
+
|
53
67
|
kubernetes.resources.each do |res|
|
54
68
|
puts res.to_resource.serialize.to_yaml
|
55
69
|
end
|
@@ -61,6 +75,10 @@ module Kuby
|
|
61
75
|
puts File.read(path)
|
62
76
|
end
|
63
77
|
|
78
|
+
def kubectl(*cmd)
|
79
|
+
kubernetes_cli.run_cmd(cmd)
|
80
|
+
end
|
81
|
+
|
64
82
|
def remote_logs
|
65
83
|
kubernetes_cli.logtail(namespace, match_labels.serialize)
|
66
84
|
end
|
data/lib/kuby/tasks/kuby.rake
CHANGED
@@ -1,62 +1,69 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
1
3
|
namespace :kuby do
|
2
4
|
def tasks
|
5
|
+
Kuby.load!
|
3
6
|
@tasks ||= Kuby::Tasks.new(Kuby.definition)
|
4
7
|
end
|
5
8
|
|
6
|
-
task dockerfile
|
9
|
+
task :dockerfile do
|
7
10
|
tasks.print_dockerfile
|
8
11
|
end
|
9
12
|
|
10
|
-
task build
|
13
|
+
task :build do
|
11
14
|
tasks.build
|
12
15
|
end
|
13
16
|
|
14
|
-
task run
|
17
|
+
task :run do
|
15
18
|
tasks.run
|
16
19
|
end
|
17
20
|
|
18
|
-
task push
|
21
|
+
task :push do
|
19
22
|
tasks.push
|
20
23
|
end
|
21
24
|
|
22
|
-
task resources
|
25
|
+
task :resources do
|
23
26
|
tasks.print_resources
|
24
27
|
end
|
25
28
|
|
26
|
-
task
|
27
|
-
|
29
|
+
task :kubectl, [:cmd] do |_, args|
|
30
|
+
tasks.kubectl(Shellwords.shellsplit(args[:cmd]))
|
31
|
+
end
|
32
|
+
|
33
|
+
task :deploy do
|
34
|
+
tasks.deploy
|
28
35
|
end
|
29
36
|
|
30
|
-
task rollback
|
31
|
-
|
37
|
+
task :rollback do
|
38
|
+
tasks.rollback
|
32
39
|
end
|
33
40
|
|
34
|
-
task kubeconfig
|
41
|
+
task :kubeconfig do
|
35
42
|
tasks.print_kubeconfig
|
36
43
|
end
|
37
44
|
|
38
|
-
task setup
|
39
|
-
|
45
|
+
task :setup do
|
46
|
+
tasks.setup
|
40
47
|
end
|
41
48
|
|
42
49
|
namespace :remote do
|
43
|
-
task logs
|
50
|
+
task :logs do
|
44
51
|
tasks.remote_logs
|
45
52
|
end
|
46
53
|
|
47
|
-
task status
|
54
|
+
task :status do
|
48
55
|
tasks.remote_status
|
49
56
|
end
|
50
57
|
|
51
|
-
task shell
|
58
|
+
task :shell do
|
52
59
|
tasks.remote_shell
|
53
60
|
end
|
54
61
|
|
55
|
-
task console
|
62
|
+
task :console do
|
56
63
|
tasks.remote_console
|
57
64
|
end
|
58
65
|
|
59
|
-
task dbconsole
|
66
|
+
task :dbconsole do
|
60
67
|
tasks.remote_dbconsole
|
61
68
|
end
|
62
69
|
end
|
data/lib/kuby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuby-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -58,56 +58,56 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.2'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: kube-dsl
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.3'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: kuby-kube-db
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.4'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.4'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: kubernetes-cli
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
103
|
+
version: '0.2'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
110
|
+
version: '0.2'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: railties
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- README.md
|
150
150
|
- Rakefile
|
151
151
|
- kuby-core.gemspec
|
152
|
+
- lib/ext/krane/kubernetes_resource.rb
|
152
153
|
- lib/kuby.rb
|
153
154
|
- lib/kuby/basic_logger.rb
|
154
155
|
- lib/kuby/cli_base.rb
|
@@ -163,6 +164,8 @@ files:
|
|
163
164
|
- lib/kuby/docker/debian.rb
|
164
165
|
- lib/kuby/docker/dockerfile.rb
|
165
166
|
- lib/kuby/docker/errors.rb
|
167
|
+
- lib/kuby/docker/inline_layer.rb
|
168
|
+
- lib/kuby/docker/layer.rb
|
166
169
|
- lib/kuby/docker/layer_stack.rb
|
167
170
|
- lib/kuby/docker/local_tags.rb
|
168
171
|
- lib/kuby/docker/metadata.rb
|
@@ -172,8 +175,8 @@ files:
|
|
172
175
|
- lib/kuby/docker/packages/managed_package.rb
|
173
176
|
- lib/kuby/docker/packages/nodejs.rb
|
174
177
|
- lib/kuby/docker/packages/package.rb
|
178
|
+
- lib/kuby/docker/packages/simple_managed_package.rb
|
175
179
|
- lib/kuby/docker/packages/yarn.rb
|
176
|
-
- lib/kuby/docker/phase.rb
|
177
180
|
- lib/kuby/docker/remote_tags.rb
|
178
181
|
- lib/kuby/docker/setup_phase.rb
|
179
182
|
- lib/kuby/docker/spec.rb
|
@@ -181,7 +184,9 @@ files:
|
|
181
184
|
- lib/kuby/docker/timestamp_tag.rb
|
182
185
|
- lib/kuby/docker/webserver_phase.rb
|
183
186
|
- lib/kuby/docker/yarn_phase.rb
|
187
|
+
- lib/kuby/environment.rb
|
184
188
|
- lib/kuby/kubernetes.rb
|
189
|
+
- lib/kuby/kubernetes/deploy_task.rb
|
185
190
|
- lib/kuby/kubernetes/deployer.rb
|
186
191
|
- lib/kuby/kubernetes/docker_config.rb
|
187
192
|
- lib/kuby/kubernetes/errors.rb
|
@@ -192,6 +197,7 @@ files:
|
|
192
197
|
- lib/kuby/kubernetes/plugins/nginx_ingress.rb
|
193
198
|
- lib/kuby/kubernetes/plugins/rails_app.rb
|
194
199
|
- lib/kuby/kubernetes/plugins/rails_app/database.rb
|
200
|
+
- lib/kuby/kubernetes/plugins/rails_app/generators/kuby.rb
|
195
201
|
- lib/kuby/kubernetes/plugins/rails_app/mysql.rb
|
196
202
|
- lib/kuby/kubernetes/plugins/rails_app/plugin.rb
|
197
203
|
- lib/kuby/kubernetes/plugins/rails_app/postgres.rb
|
@@ -211,7 +217,7 @@ files:
|
|
211
217
|
homepage: http://github.com/getkuby/kuby-core
|
212
218
|
licenses: []
|
213
219
|
metadata: {}
|
214
|
-
post_install_message:
|
220
|
+
post_install_message:
|
215
221
|
rdoc_options: []
|
216
222
|
require_paths:
|
217
223
|
- lib
|
@@ -226,8 +232,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
232
|
- !ruby/object:Gem::Version
|
227
233
|
version: '0'
|
228
234
|
requirements: []
|
229
|
-
rubygems_version: 3.
|
230
|
-
signing_key:
|
235
|
+
rubygems_version: 3.1.4
|
236
|
+
signing_key:
|
231
237
|
specification_version: 4
|
232
238
|
summary: Deploy your Rails app onto Kubernetes the easy way.
|
233
239
|
test_files: []
|