kuby-core 0.7.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/Gemfile +1 -0
  4. data/README.md +11 -1
  5. data/bin/kuby +4 -0
  6. data/kuby-core.gemspec +9 -4
  7. data/lib/kuby.rb +58 -19
  8. data/lib/kuby/basic_logger.rb +13 -0
  9. data/lib/kuby/cli_base.rb +81 -8
  10. data/lib/kuby/commands.rb +244 -0
  11. data/lib/kuby/definition.rb +1 -11
  12. data/lib/kuby/dev_setup.rb +255 -0
  13. data/lib/kuby/docker.rb +1 -0
  14. data/lib/kuby/docker/bundler_phase.rb +3 -3
  15. data/lib/kuby/docker/cli.rb +13 -1
  16. data/lib/kuby/docker/dev_spec.rb +131 -0
  17. data/lib/kuby/docker/dockerfile.rb +16 -1
  18. data/lib/kuby/docker/layer.rb +4 -4
  19. data/lib/kuby/docker/layer_stack.rb +4 -0
  20. data/lib/kuby/docker/local_tags.rb +4 -0
  21. data/lib/kuby/docker/metadata.rb +18 -38
  22. data/lib/kuby/docker/package_phase.rb +2 -2
  23. data/lib/kuby/docker/setup_phase.rb +3 -2
  24. data/lib/kuby/docker/spec.rb +42 -16
  25. data/lib/kuby/docker/timestamp_tag.rb +6 -0
  26. data/lib/kuby/environment.rb +15 -2
  27. data/lib/kuby/kubernetes.rb +9 -11
  28. data/lib/kuby/kubernetes/deploy_task.rb +4 -1
  29. data/lib/kuby/kubernetes/deployer.rb +70 -15
  30. data/lib/kuby/kubernetes/{minikube_provider.rb → docker_desktop_provider.rb} +8 -4
  31. data/lib/kuby/kubernetes/provider.rb +12 -8
  32. data/lib/kuby/kubernetes/spec.rb +30 -29
  33. data/lib/kuby/plugin.rb +59 -0
  34. data/lib/kuby/plugin_registry.rb +27 -0
  35. data/lib/kuby/plugins.rb +6 -0
  36. data/lib/kuby/plugins/nginx_ingress.rb +71 -0
  37. data/lib/kuby/plugins/rails_app.rb +18 -0
  38. data/lib/kuby/plugins/rails_app/asset_copy_task.rb +117 -0
  39. data/lib/kuby/plugins/rails_app/assets.rb +347 -0
  40. data/lib/kuby/plugins/rails_app/database.rb +74 -0
  41. data/lib/kuby/{kubernetes/plugins → plugins}/rails_app/generators/kuby.rb +14 -16
  42. data/lib/kuby/plugins/rails_app/mysql.rb +152 -0
  43. data/lib/kuby/plugins/rails_app/plugin.rb +593 -0
  44. data/lib/kuby/plugins/rails_app/postgres.rb +143 -0
  45. data/lib/kuby/plugins/rails_app/rewrite_db_config.rb +11 -0
  46. data/lib/kuby/plugins/rails_app/sqlite.rb +32 -0
  47. data/lib/kuby/plugins/rails_app/tasks.rake +36 -0
  48. data/lib/kuby/rails_commands.rb +89 -0
  49. data/lib/kuby/railtie.rb +0 -4
  50. data/lib/kuby/tasks.rb +85 -31
  51. data/lib/kuby/version.rb +1 -1
  52. data/spec/docker/metadata_spec.rb +84 -0
  53. data/spec/docker/spec_spec.rb +266 -0
  54. data/spec/docker/timestamp_tag_spec.rb +54 -4
  55. data/spec/dummy/Gemfile +54 -0
  56. data/spec/dummy/Gemfile.lock +223 -0
  57. data/spec/dummy/README.md +24 -0
  58. data/spec/dummy/Rakefile +6 -0
  59. data/spec/dummy/app/assets/config/manifest.js +2 -0
  60. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  61. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  62. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  63. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  64. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  65. data/spec/dummy/app/javascript/channels/consumer.js +6 -0
  66. data/spec/dummy/app/javascript/channels/index.js +5 -0
  67. data/spec/dummy/app/javascript/packs/application.js +17 -0
  68. data/spec/dummy/app/jobs/application_job.rb +7 -0
  69. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  70. data/spec/dummy/app/models/application_record.rb +3 -0
  71. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  72. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  73. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  74. data/spec/dummy/bin/bundle +114 -0
  75. data/spec/dummy/bin/rails +9 -0
  76. data/spec/dummy/bin/rake +9 -0
  77. data/spec/dummy/bin/setup +36 -0
  78. data/spec/dummy/bin/spring +17 -0
  79. data/spec/dummy/bin/yarn +11 -0
  80. data/spec/dummy/config.ru +5 -0
  81. data/spec/dummy/config/application.rb +19 -0
  82. data/spec/dummy/config/boot.rb +4 -0
  83. data/spec/dummy/config/cable.yml +10 -0
  84. data/spec/dummy/config/credentials.yml.enc +1 -0
  85. data/spec/dummy/config/database.yml +25 -0
  86. data/spec/dummy/config/environment.rb +5 -0
  87. data/spec/dummy/config/environments/development.rb +62 -0
  88. data/spec/dummy/config/environments/production.rb +112 -0
  89. data/spec/dummy/config/environments/test.rb +49 -0
  90. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  91. data/spec/dummy/config/initializers/assets.rb +14 -0
  92. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  93. data/spec/dummy/config/initializers/content_security_policy.rb +30 -0
  94. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  95. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  96. data/spec/dummy/config/initializers/inflections.rb +16 -0
  97. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +33 -0
  100. data/spec/dummy/config/master.key +1 -0
  101. data/spec/dummy/config/puma.rb +38 -0
  102. data/spec/dummy/config/routes.rb +3 -0
  103. data/spec/dummy/config/spring.rb +6 -0
  104. data/spec/dummy/config/storage.yml +34 -0
  105. data/spec/dummy/db/seeds.rb +7 -0
  106. data/spec/dummy/package.json +11 -0
  107. data/spec/dummy/public/404.html +67 -0
  108. data/spec/dummy/public/422.html +67 -0
  109. data/spec/dummy/public/500.html +66 -0
  110. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/spec/dummy/public/apple-touch-icon.png +0 -0
  112. data/spec/dummy/public/favicon.ico +0 -0
  113. data/spec/dummy/public/robots.txt +1 -0
  114. data/spec/dummy/test/application_system_test_case.rb +5 -0
  115. data/spec/dummy/test/channels/application_cable/connection_test.rb +11 -0
  116. data/spec/dummy/test/test_helper.rb +13 -0
  117. data/spec/dummy/tmp/cache/bootsnap-load-path-cache +0 -0
  118. data/spec/spec_helper.rb +77 -2
  119. data/spec/support/docker/fake_cli.rb +54 -0
  120. data/spec/support/docker/remote/fake_client.rb +16 -0
  121. data/spec/trailing_hash_spec.rb +23 -0
  122. metadata +139 -30
  123. data/lib/ext/krane/kubernetes_resource.rb +0 -16
  124. data/lib/kuby/kubernetes/plugin.rb +0 -55
  125. data/lib/kuby/kubernetes/plugins.rb +0 -8
  126. data/lib/kuby/kubernetes/plugins/nginx_ingress.rb +0 -73
  127. data/lib/kuby/kubernetes/plugins/rails_app.rb +0 -16
  128. data/lib/kuby/kubernetes/plugins/rails_app/database.rb +0 -79
  129. data/lib/kuby/kubernetes/plugins/rails_app/mysql.rb +0 -154
  130. data/lib/kuby/kubernetes/plugins/rails_app/plugin.rb +0 -379
  131. data/lib/kuby/kubernetes/plugins/rails_app/postgres.rb +0 -142
  132. data/lib/kuby/kubernetes/plugins/rails_app/rewrite_db_config.rb +0 -13
  133. data/lib/kuby/kubernetes/plugins/rails_app/sqlite.rb +0 -30
  134. data/lib/kuby/kubernetes/plugins/rails_app/tasks.rake +0 -28
  135. data/lib/kuby/tasks/kuby.rake +0 -70
@@ -0,0 +1,152 @@
1
+ require 'kube-dsl'
2
+ require 'kuby/kube-db'
3
+
4
+ module Kuby
5
+ module Plugins
6
+ module RailsApp
7
+ class MySQL < ::Kuby::Plugin
8
+ ROLE = 'web'.freeze
9
+
10
+ attr_reader :environment, :configs
11
+
12
+ def initialize(environment, configs)
13
+ @environment = environment
14
+ @configs = configs
15
+ end
16
+
17
+ def name
18
+ :mysql
19
+ end
20
+
21
+ def resources
22
+ @resources ||= [secret, database]
23
+ end
24
+
25
+ def after_configuration
26
+ environment.docker.package_phase.add(:mysql_dev)
27
+ environment.docker.package_phase.add(:mysql_client)
28
+ end
29
+
30
+ def host
31
+ # host is the same as the name thanks to k8s DNS
32
+ @host ||= database.metadata.name
33
+ end
34
+
35
+ def rewritten_configs
36
+ # deep dup
37
+ @rewritten_configs ||= Marshal.load(Marshal.dump(configs)).tap do |new_configs|
38
+ new_configs[environment.name]['host'] = host
39
+ end
40
+ end
41
+
42
+ def user(user)
43
+ secret do
44
+ data do
45
+ set :user, user
46
+ end
47
+ end
48
+ end
49
+
50
+ def password(password)
51
+ secret do
52
+ data do
53
+ set :password, password
54
+ end
55
+ end
56
+ end
57
+
58
+ def storage(amount)
59
+ database do
60
+ spec do
61
+ storage do
62
+ resources do
63
+ requests do
64
+ set :storage, amount
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def secret(&block)
73
+ context = self
74
+
75
+ @secret ||= KubeDSL.secret do
76
+ metadata do
77
+ name "#{context.base_name}-mysql-secret"
78
+ namespace context.kubernetes.namespace.metadata.name
79
+ end
80
+
81
+ type 'Opaque'
82
+ end
83
+
84
+ @secret.instance_eval(&block) if block
85
+ @secret
86
+ end
87
+
88
+ def database(&block)
89
+ context = self
90
+
91
+ @database ||= Kuby::KubeDB.my_sql do
92
+ api_version 'kubedb.com/v1alpha1'
93
+
94
+ metadata do
95
+ name "#{context.base_name}-mysql"
96
+ namespace context.kubernetes.namespace.metadata.name
97
+ end
98
+
99
+ spec do
100
+ database_secret do
101
+ secret_name context.secret.metadata.name
102
+ end
103
+
104
+ version '5.7-v2'
105
+ storage_type 'Durable'
106
+
107
+ storage do
108
+ storage_class_name context.kubernetes.provider.storage_class_name
109
+ access_modes ['ReadWriteOnce']
110
+
111
+ resources do
112
+ requests do
113
+ add :storage, '10Gi'
114
+ end
115
+ end
116
+ end
117
+
118
+ termination_policy 'DoNotTerminate'
119
+ end
120
+ end
121
+
122
+ @database.instance_eval(&block) if block
123
+ @database
124
+ end
125
+
126
+ def base_name
127
+ @base_name ||= "#{kubernetes.selector_app}-#{ROLE}"
128
+ end
129
+
130
+ def kubernetes
131
+ environment.kubernetes
132
+ end
133
+
134
+ private
135
+
136
+ def config
137
+ configs[environment.name]
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ Kuby.register_package(:mysql_client,
145
+ debian: 'default-mysql-client',
146
+ alpine: 'mariadb-client'
147
+ )
148
+
149
+ Kuby.register_package(:mysql_dev,
150
+ debian: 'default-libmysqlclient-dev',
151
+ alpine: 'mariadb-dev'
152
+ )
@@ -0,0 +1,593 @@
1
+ require 'kube-dsl'
2
+ require 'kuby/cert-manager'
3
+
4
+ module Kuby
5
+ module Plugins
6
+ module RailsApp
7
+ class Plugin < ::Kuby::Plugin
8
+ extend ::KubeDSL::ValueFields
9
+
10
+ WEB_ROLE = 'web'.freeze
11
+ DEFAULT_HOSTNAME = 'localhost'.freeze
12
+ MASTER_KEY_VAR = 'RAILS_MASTER_KEY'.freeze
13
+ ENV_SECRETS = [MASTER_KEY_VAR].freeze
14
+ ENV_EXCLUDE = ['RAILS_ENV'].freeze
15
+ DEFAULT_ASSET_URL = '/assets'.freeze
16
+ DEFAULT_PACKS_URL = '/packs'.freeze
17
+ DEFAULT_ASSET_PATH = './public'.freeze
18
+
19
+ value_field :root, default: '.'
20
+ value_fields :hostname, :tls_enabled
21
+ value_fields :manage_database, :database, :replicas
22
+ value_fields :asset_url, :packs_url, :asset_path
23
+
24
+ alias_method :manage_database?, :manage_database
25
+
26
+ def initialize(environment)
27
+ @environment = environment
28
+ @tls_enabled = true
29
+ @replicas = 1
30
+ @manage_database = true
31
+ @hostname = DEFAULT_HOSTNAME
32
+ @asset_url = DEFAULT_ASSET_URL
33
+ @packs_url = DEFAULT_PACKS_URL
34
+ @asset_path = DEFAULT_ASSET_PATH
35
+ @database = Database.get(self)
36
+ end
37
+
38
+ def configure(&block)
39
+ instance_eval(&block) if block
40
+ end
41
+
42
+ def after_configuration
43
+ context = self
44
+
45
+ if database
46
+ environment.kubernetes.plugins[database.plugin_name] = @database.plugin
47
+ environment.kubernetes.add_plugin(:kube_db)
48
+
49
+ unless environment.development?
50
+ environment.docker do
51
+ insert :rewrite_db_config, RewriteDbConfig.new, after: :copy_phase
52
+ end
53
+ end
54
+ end
55
+
56
+ unless environment.development?
57
+ environment.kubernetes.add_plugin(:nginx_ingress)
58
+ environment.kubernetes.add_plugin(:rails_assets) do
59
+ asset_url context.asset_url
60
+ packs_url context.packs_url
61
+ asset_path context.asset_path
62
+ end
63
+
64
+ if @tls_enabled
65
+ context = self
66
+
67
+ environment.kubernetes.add_plugin(:cert_manager) do
68
+ email context.environment.docker.credentials.email
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def database_host
75
+ database.plugin.host
76
+ end
77
+
78
+ def before_deploy(manifest)
79
+ # Make sure plugin has been configured. If not, do nothing.
80
+ if cert_manager = environment.kubernetes.plugin(:cert_manager)
81
+ cert_manager.annotate_ingress(ingress)
82
+ end
83
+
84
+ image_with_tag = "#{docker.metadata.image_url}:#{kubernetes.tag}"
85
+
86
+ if assets = environment.kubernetes.plugin(:rails_assets)
87
+ assets.configure_ingress(ingress, hostname)
88
+ assets.configure_deployment(deployment, image_with_tag)
89
+ end
90
+
91
+ spec = self
92
+
93
+ deployment do
94
+ spec do
95
+ template do
96
+ spec do
97
+ container(:web) do
98
+ image image_with_tag
99
+ end
100
+
101
+ unless spec.environment.development?
102
+ init_container(:create_db) do
103
+ image image_with_tag
104
+ end
105
+
106
+ init_container(:migrate_db) do
107
+ image image_with_tag
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ def database(&block)
117
+ @database.plugin.instance_eval(&block) if block
118
+ @database
119
+ end
120
+
121
+ def service(&block)
122
+ spec = self
123
+
124
+ @service ||= KubeDSL.service do
125
+ metadata do
126
+ name "#{spec.selector_app}-svc"
127
+ namespace spec.namespace.metadata.name
128
+
129
+ labels do
130
+ add :app, spec.selector_app
131
+ add :role, spec.role
132
+ end
133
+ end
134
+
135
+ spec do
136
+ type 'NodePort'
137
+
138
+ selector do
139
+ add :app, spec.selector_app
140
+ add :role, spec.role
141
+ end
142
+
143
+ port do
144
+ name 'http'
145
+ port spec.docker.webserver_phase.port
146
+ protocol 'TCP'
147
+ target_port 'http'
148
+ end
149
+ end
150
+ end
151
+
152
+ @service.instance_eval(&block) if block
153
+ @service
154
+ end
155
+
156
+ def service_account(&block)
157
+ spec = self
158
+
159
+ @service_account ||= KubeDSL.service_account do
160
+ metadata do
161
+ name "#{spec.selector_app}-sa"
162
+ namespace spec.namespace.metadata.name
163
+
164
+ labels do
165
+ add :app, spec.selector_app
166
+ add :role, spec.role
167
+ end
168
+ end
169
+ end
170
+
171
+ @service_account.instance_eval(&block) if block
172
+ @service_account
173
+ end
174
+
175
+ def config_map(&block)
176
+ spec = self
177
+
178
+ @config_map ||= KubeDSL.config_map do
179
+ metadata do
180
+ name "#{spec.selector_app}-config"
181
+ namespace spec.namespace.metadata.name
182
+ end
183
+
184
+ data do
185
+ ENV.each_pair do |key, val|
186
+ include_key = key.start_with?('RAILS_') &&
187
+ !ENV_SECRETS.include?(key) &&
188
+ !ENV_EXCLUDE.include?(key)
189
+
190
+ if include_key
191
+ add key.to_sym, val
192
+ end
193
+ end
194
+ end
195
+ end
196
+
197
+ @config_map.instance_eval(&block) if block
198
+ @config_map
199
+ end
200
+
201
+ def app_secrets(&block)
202
+ spec = self
203
+
204
+ @app_secrets ||= KubeDSL.secret do
205
+ metadata do
206
+ name "#{spec.selector_app}-secrets"
207
+ namespace spec.namespace.metadata.name
208
+ end
209
+
210
+ type 'Opaque'
211
+
212
+ data do
213
+ if master_key = ENV[MASTER_KEY_VAR]
214
+ add MASTER_KEY_VAR.to_sym, master_key
215
+ else
216
+ master_key_path = File.join(spec.root, 'config', 'master.key')
217
+
218
+ if File.exist?(master_key_path)
219
+ add MASTER_KEY_VAR.to_sym, File.read(master_key_path).strip
220
+ end
221
+ end
222
+ end
223
+ end
224
+
225
+ @app_secrets.instance_eval(&block) if block
226
+ @app_secrets
227
+ end
228
+
229
+ def deployment(&block)
230
+ kube_spec = self
231
+
232
+ @deployment ||= KubeDSL.deployment do
233
+ metadata do
234
+ name "#{kube_spec.selector_app}-#{kube_spec.role}"
235
+ namespace kube_spec.namespace.metadata.name
236
+
237
+ labels do
238
+ add :app, kube_spec.selector_app
239
+ add :role, kube_spec.role
240
+ end
241
+
242
+ annotations do
243
+ add(
244
+ 'getkuby.io/dockerfile-checksum',
245
+ kube_spec.environment.docker.to_dockerfile.checksum
246
+ )
247
+ end
248
+ end
249
+
250
+ spec do
251
+ replicas kube_spec.replicas
252
+
253
+ selector do
254
+ match_labels do
255
+ add :app, kube_spec.selector_app
256
+ add :role, kube_spec.role
257
+ end
258
+ end
259
+
260
+ strategy do
261
+ type 'RollingUpdate'
262
+
263
+ rolling_update do
264
+ max_surge '25%'
265
+ max_unavailable 0
266
+ end
267
+ end
268
+
269
+ template do
270
+ metadata do
271
+ labels do
272
+ add :app, kube_spec.selector_app
273
+ add :role, kube_spec.role
274
+ end
275
+ end
276
+
277
+ spec do
278
+ container(:web) do
279
+ name "#{kube_spec.selector_app}-#{kube_spec.role}"
280
+ image_pull_policy 'IfNotPresent'
281
+
282
+ port do
283
+ container_port kube_spec.docker.webserver_phase.port
284
+ name 'http'
285
+ protocol 'TCP'
286
+ end
287
+
288
+ env_from do
289
+ config_map_ref do
290
+ name kube_spec.config_map.metadata.name
291
+ end
292
+ end
293
+
294
+ env_from do
295
+ secret_ref do
296
+ name kube_spec.app_secrets.metadata.name
297
+ end
298
+ end
299
+
300
+ unless kube_spec.environment.development?
301
+ readiness_probe do
302
+ success_threshold 1
303
+ failure_threshold 2
304
+ initial_delay_seconds 15
305
+ period_seconds 3
306
+ timeout_seconds 1
307
+
308
+ http_get do
309
+ path '/healthz'
310
+ port kube_spec.docker.webserver_phase.port
311
+ scheme 'HTTP'
312
+ end
313
+ end
314
+ end
315
+
316
+ if kube_spec.environment.development?
317
+ env do
318
+ name 'BUNDLE_PATH'
319
+ value '/bundle'
320
+ end
321
+
322
+ env do
323
+ name 'GEM_HOME'
324
+ value '/bundle'
325
+ end
326
+
327
+ env do
328
+ name 'BOOTSNAP_CACHE_DIR'
329
+ value '/usr/src/bootsnap'
330
+ end
331
+
332
+ volume_mount do
333
+ name "#{kube_spec.selector_app}-code"
334
+ mount_path '/usr/src/app'
335
+ end
336
+
337
+ volume_mount do
338
+ name "#{kube_spec.selector_app}-bundle"
339
+ mount_path '/bundle'
340
+ end
341
+
342
+ volume_mount do
343
+ name "#{kube_spec.selector_app}-bootsnap"
344
+ mount_path '/usr/src/bootsnap'
345
+ end
346
+ end
347
+ end
348
+
349
+ if kube_spec.environment.development?
350
+ volume do
351
+ name "#{kube_spec.selector_app}-code"
352
+
353
+ persistent_volume_claim do
354
+ claim_name kube_spec.code_volume_claim.metadata.name
355
+ end
356
+ end
357
+
358
+ volume do
359
+ name "#{kube_spec.selector_app}-bundle"
360
+
361
+ persistent_volume_claim do
362
+ claim_name kube_spec.bundle_volume_claim.metadata.name
363
+ end
364
+ end
365
+
366
+ volume do
367
+ name "#{kube_spec.selector_app}-bootsnap"
368
+
369
+ persistent_volume_claim do
370
+ claim_name kube_spec.bootsnap_volume_claim.metadata.name
371
+ end
372
+ end
373
+ else
374
+ init_container(:create_db) do
375
+ name "#{kube_spec.selector_app}-create-db"
376
+ command %w(bundle exec rake kuby:rails_app:db:create_unless_exists)
377
+ end
378
+
379
+ init_container(:migrate_db) do
380
+ name "#{kube_spec.selector_app}-migrate-db"
381
+ command %w(bundle exec rake db:migrate)
382
+ end
383
+
384
+ image_pull_secret do
385
+ name kube_spec.environment.kubernetes.registry_secret.metadata.name
386
+ end
387
+ end
388
+
389
+ restart_policy 'Always'
390
+ service_account_name kube_spec.service_account.metadata.name
391
+ end
392
+ end
393
+ end
394
+ end
395
+
396
+ @deployment.instance_eval(&block) if block
397
+ @deployment
398
+ end
399
+
400
+ def ingress(&block)
401
+ spec = self
402
+ tls_enabled = @tls_enabled
403
+
404
+ @ingress ||= KubeDSL::DSL::Extensions::V1beta1::Ingress.new do
405
+ metadata do
406
+ name "#{spec.selector_app}-ingress"
407
+ namespace spec.namespace.metadata.name
408
+
409
+ annotations do
410
+ add :'kubernetes.io/ingress.class', 'nginx'
411
+ end
412
+ end
413
+
414
+ spec do
415
+ rule do
416
+ host spec.hostname
417
+
418
+ http do
419
+ path do
420
+ path '/'
421
+
422
+ backend do
423
+ service_name spec.service.metadata.name
424
+ service_port spec.service.spec.ports.first.port
425
+ end
426
+ end
427
+ end
428
+ end
429
+
430
+ if tls_enabled
431
+ tls do
432
+ secret_name "#{spec.selector_app}-tls"
433
+ hosts [spec.hostname]
434
+ end
435
+ end
436
+ end
437
+ end
438
+
439
+ @ingress.instance_eval(&block) if block
440
+ @ingress
441
+ end
442
+
443
+ def code_volume(&block)
444
+ spec = self
445
+
446
+ if environment.development?
447
+ @code_volume ||= KubeDSL.persistent_volume do
448
+ metadata do
449
+ name "#{spec.selector_app}-code"
450
+ end
451
+
452
+ spec do
453
+ access_modes ['ReadWriteMany']
454
+
455
+ capacity do
456
+ add :storage, '1Mi'
457
+ end
458
+
459
+ host_path do
460
+ path File.expand_path(spec.root)
461
+ end
462
+
463
+ storage_class_name 'hostpath'
464
+ end
465
+ end
466
+
467
+ @code_volume.instance_eval(&block) if block
468
+ @code_volume
469
+ end
470
+ end
471
+
472
+ def code_volume_claim(&block)
473
+ spec = self
474
+
475
+ if environment.development?
476
+ @code_volume_claim ||= KubeDSL.persistent_volume_claim do
477
+ metadata do
478
+ name "#{spec.selector_app}-code"
479
+ namespace spec.namespace.metadata.name
480
+ end
481
+
482
+ spec do
483
+ access_modes ['ReadWriteMany']
484
+
485
+ resources do
486
+ requests do
487
+ add :storage, '1Mi'
488
+ end
489
+ end
490
+
491
+ storage_class_name 'hostpath'
492
+ volume_name spec.code_volume.metadata.name
493
+ end
494
+ end
495
+
496
+ @code_volume_claim.instance_eval(&block) if block
497
+ @code_volume_claim
498
+ end
499
+ end
500
+
501
+ def bundle_volume_claim(&block)
502
+ spec = self
503
+
504
+ if environment.development?
505
+ @bundle_volume_claim ||= KubeDSL.persistent_volume_claim do
506
+ metadata do
507
+ name "#{spec.selector_app}-bundle"
508
+ namespace spec.namespace.metadata.name
509
+ end
510
+
511
+ spec do
512
+ access_modes ['ReadWriteMany']
513
+ storage_class_name 'hostpath'
514
+
515
+ resources do
516
+ requests do
517
+ add :storage, '2Gi'
518
+ end
519
+ end
520
+ end
521
+ end
522
+
523
+ @bundle_volume_claim.instance_eval(&block) if block
524
+ @bundle_volume_claim
525
+ end
526
+ end
527
+
528
+ def bootsnap_volume_claim(&block)
529
+ spec = self
530
+
531
+ if environment.development?
532
+ @bootsnap_volume_claim ||= KubeDSL.persistent_volume_claim do
533
+ metadata do
534
+ name "#{spec.selector_app}-bootsnap"
535
+ namespace spec.namespace.metadata.name
536
+ end
537
+
538
+ spec do
539
+ access_modes ['ReadWriteMany']
540
+ storage_class_name 'hostpath'
541
+
542
+ resources do
543
+ requests do
544
+ add :storage, '2Gi'
545
+ end
546
+ end
547
+ end
548
+ end
549
+
550
+ @bootsnap_volume_claim.instance_eval(&block) if block
551
+ @bootsnap_volume_claim
552
+ end
553
+ end
554
+
555
+ def resources
556
+ @resources ||= [
557
+ service,
558
+ service_account,
559
+ config_map,
560
+ app_secrets,
561
+ deployment,
562
+ ingress,
563
+ code_volume,
564
+ code_volume_claim,
565
+ bundle_volume_claim,
566
+ bootsnap_volume_claim,
567
+ *database&.plugin&.resources
568
+ ]
569
+ end
570
+
571
+ def selector_app
572
+ environment.kubernetes.selector_app
573
+ end
574
+
575
+ def role
576
+ WEB_ROLE
577
+ end
578
+
579
+ def docker
580
+ environment.docker
581
+ end
582
+
583
+ def kubernetes
584
+ environment.kubernetes
585
+ end
586
+
587
+ def namespace
588
+ environment.kubernetes.namespace
589
+ end
590
+ end
591
+ end
592
+ end
593
+ end