Class: Dapp::Deployment::App
- Inherits:
-
Object
- Object
- Dapp::Deployment::App
- Includes:
- Mod::Jobs, Mod::Namespace, Mod::SystemEnvironments
- Defined in:
- lib/dapp/deployment/app.rb
Instance Attribute Summary collapse
-
#app_config ⇒ Object
(also: #config)
readonly
Returns the value of attribute app_config.
-
#deployment ⇒ Object
readonly
Returns the value of attribute deployment.
Instance Method Summary collapse
-
#initialize(app_config:, deployment:) ⇒ App
constructor
A new instance of App.
- #kube ⇒ Object
- #name(*args) ⇒ Object
- #to_kube_deployments(repo, image_version) ⇒ Object
- #to_kube_services ⇒ Object
Methods included from Mod::Jobs
Methods included from Mod::Namespace
#environment, #environments, #namespace_config, #namespace_config_directive, #scale, #secret_environment
Constructor Details
#initialize(app_config:, deployment:) ⇒ App
Returns a new instance of App.
12 13 14 15 |
# File 'lib/dapp/deployment/app.rb', line 12 def initialize(app_config:, deployment:) @app_config = app_config @deployment = deployment end |
Instance Attribute Details
#app_config ⇒ Object (readonly) Also known as: config
Returns the value of attribute app_config.
9 10 11 |
# File 'lib/dapp/deployment/app.rb', line 9 def app_config @app_config end |
#deployment ⇒ Object (readonly)
Returns the value of attribute deployment.
8 9 10 |
# File 'lib/dapp/deployment/app.rb', line 8 def deployment @deployment end |
Instance Method Details
#kube ⇒ Object
21 22 23 |
# File 'lib/dapp/deployment/app.rb', line 21 def kube @kube ||= KubeApp.new(self) end |
#name(*args) ⇒ Object
17 18 19 |
# File 'lib/dapp/deployment/app.rb', line 17 def name(*args) deployment.name(app_config._name, *args) end |
#to_kube_deployments(repo, image_version) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dapp/deployment/app.rb', line 31 def to_kube_deployments(repo, image_version) {}.tap do |hash| hash[name] = {}.tap do |deployment| deployment['metadata'] = {}.tap do || ['name'] = name ['labels'] = kube.labels end deployment['spec'] = {}.tap do |spec| spec['replicas'] = scale spec['template'] = {} spec['template']['metadata'] = deployment['metadata'] spec['template']['spec'] = {}.tap do |template_spec| template_spec['containers'] = [].tap do |containers| containers << {}.tap do |container| ports = expose._port.map do |port| { 'containerPort' => port._number, 'name' => ['app', port._number].join('-'), 'protocol' => port._protocol } end volume_mounts = [{'mountPath' => '/.data', 'name' => "volume-#{self.name}"}] container['imagePullPolicy'] = 'Always' container['image'] = [repo, [dimg, image_version].compact.join('-')].join(':') container['name'] = dimg_name container['env'] = environments unless environments.empty? container['ports'] = ports unless expose._port.empty? container['volumeMounts'] = volume_mounts end end template_spec['volumes'] = [ { 'name' => "volume-#{name}", 'hostPath' => {'path' => "/var/lib/dapp/deployment/volumes/#{self.deployment.name}/#{self.name}"} } ] end end end end end |
#to_kube_services ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dapp/deployment/app.rb', line 75 def to_kube_services return {} if expose._port.empty? {}.tap do |hash| hash[service_name] = {}.tap do |service| service['metadata'] = {}.tap do || ['name'] = service_name ['labels'] = kube.labels end service['spec'] = {}.tap do |spec| spec['selector'] = kube.labels spec['ports'] = expose._port.map do |port| { 'port' => port._number, 'name' => ['service', port._number].join('-'), 'protocol' => port._protocol }.tap do |h| h['targetPort'] = port._target unless port._target.nil? end end spec['type'] = expose._type end end end end |