Class: Algo::Dsl::Service::Context
- Inherits:
-
Object
- Object
- Algo::Dsl::Service::Context
- Defined in:
- lib/algo/dsl/service.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #args(*items) ⇒ Object
- #command(*item) ⇒ Object
- #env(key, val) ⇒ Object
-
#image(image_name) ⇒ Object
ContainerSpec.
-
#initialize(name, cluster) ⇒ Context
constructor
A new instance of Context.
-
#label(key, val) ⇒ Object
Label.
-
#network(name) ⇒ Object
Networks.
-
#replicas(replica_size) ⇒ Object
Mode.
- #stop_grace_period(period) ⇒ Object
- #update_delay(n) ⇒ Object
-
#update_parallelism(n) ⇒ Object
UpdateConfig.
Constructor Details
#initialize(name, cluster) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/algo/dsl/service.rb', line 8 def initialize name, cluster @cluster = cluster @context = { 'Name' => "#{cluster_prefix}#{name}", 'TaskTemplate' => { 'ContainerSpec' => { 'Image' => nil } }, 'Mode' => { 'Replicated' => { 'Replicas' => 1 } }, 'Labels' => @cluster['labels'] } @context['TaskTemplate']['ContainerSpec']['Env'] = @cluster['env'] if @cluster['env'].present? end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/algo/dsl/service.rb', line 6 def context @context end |
Instance Method Details
#args(*items) ⇒ Object
37 38 39 |
# File 'lib/algo/dsl/service.rb', line 37 def args *items @context['TaskTemplate']['ContainerSpec']['Args'] = items end |
#command(*item) ⇒ Object
33 34 35 |
# File 'lib/algo/dsl/service.rb', line 33 def command *item @context['TaskTemplate']['ContainerSpec']['Command'] = item end |
#env(key, val) ⇒ Object
41 42 43 44 |
# File 'lib/algo/dsl/service.rb', line 41 def env key, val @context['TaskTemplate']['ContainerSpec']['Env'] ||= [] @context['TaskTemplate']['ContainerSpec']['Env'] << "#{key}=#{val}" end |
#image(image_name) ⇒ Object
ContainerSpec
29 30 31 |
# File 'lib/algo/dsl/service.rb', line 29 def image image_name @context['TaskTemplate']['ContainerSpec']['Image'] = image_name end |
#label(key, val) ⇒ Object
Label
62 63 64 65 |
# File 'lib/algo/dsl/service.rb', line 62 def label key, val @context['Labels'] ||= {} @context['Labels'][key] = val end |
#network(name) ⇒ Object
Networks
87 88 89 90 |
# File 'lib/algo/dsl/service.rb', line 87 def network name @context['Networks'] ||= [] @context['Networks'] << { 'Target' => "#{cluster_prefix}#{name}" } end |
#replicas(replica_size) ⇒ Object
Mode
69 70 71 |
# File 'lib/algo/dsl/service.rb', line 69 def replicas replica_size @context['Mode']['Replicated']['Replicas']= replica_size end |
#stop_grace_period(period) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/algo/dsl/service.rb', line 47 def stop_grace_period period if period.end_with?('s') period = period.chomp('s').to_i elsif period.end_with?('m') period = period.chomp('m').to_i * 60 elsif period.end_with?('h') period = period.chomp('m').to_i * 60 * 60 else raise end @context['TaskTemplate']['ContainerSpec']['StopGracePeriod'] = period * 1000000000 end |
#update_delay(n) ⇒ Object
80 81 82 83 |
# File 'lib/algo/dsl/service.rb', line 80 def update_delay n @context['UpdateConfig'] ||= {} @context['UpdateConfig']['Delay']= n end |
#update_parallelism(n) ⇒ Object
UpdateConfig
75 76 77 78 |
# File 'lib/algo/dsl/service.rb', line 75 def update_parallelism n @context['UpdateConfig'] ||= {} @context['UpdateConfig']['Parallelism']= n end |