Class: Algo::Runner::Apply
- Inherits:
-
Object
- Object
- Algo::Runner::Apply
- Defined in:
- lib/algo/runner/apply.rb
Defined Under Namespace
Classes: ServiceUpdator, ServiceValidator
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(configuration, options) ⇒ Apply
constructor
A new instance of Apply.
Constructor Details
#initialize(configuration, options) ⇒ Apply
Returns a new instance of Apply.
71 72 73 74 |
# File 'lib/algo/runner/apply.rb', line 71 def initialize configuration, @configuration = configuration = end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
69 70 71 |
# File 'lib/algo/runner/apply.rb', line 69 def configuration @configuration end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
69 70 71 |
# File 'lib/algo/runner/apply.rb', line 69 def end |
Class Method Details
.call(configuration, options) ⇒ Object
118 119 120 |
# File 'lib/algo/runner/apply.rb', line 118 def self.call configuration, new(configuration, ).call end |
Instance Method Details
#call ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/algo/runner/apply.rb', line 76 def call puts 'Running with dry-run mode...' if dryrun? configuration.each do |cluster| puts "Applying to cluster #{cluster['name']}..." cluster['networks'].each do |net_spec| begin net = Algo::Docker::Network.find net_spec['Name'] puts "network: #{net_spec['Name']}, status: ok" rescue Algo::Docker::Error::NotFoundError Algo::Docker::Network.create net_spec unless dryrun? puts "network: #{net_spec['Name']}, status: created" end end cluster['services'].each do |srv_spec| ServiceValidator.validate srv_spec end cluster['services'].each do |srv_spec| ServiceUpdator.update srv_spec, dryrun? end Algo::Docker::Service.all .select { |srv| srv.spec.name.start_with?("#{cluster['prefix']}-") } .select { |srv| ! srv.spec.name.in? cluster['services'].map { |spec| spec['Name'] } } .map { |srv| srv_name = srv.spec.name srv.remove unless dryrun? puts "service: #{srv_name}, status: removed" } Algo::Docker::Network.all(skip_default=true) .select { |net| net.name.start_with?("#{cluster['prefix']}-") } .select { |net| ! net.name.in? cluster['networks'].map { |net_spec| net_spec['Name'] } } .map { |net| net_name = net.name net.remove unless dryrun? puts "network: #{net_name}, status: removed" } puts "Complete applying for cluster #{cluster['name']}!" end rescue Algo::ValidationError => e puts 'configuration validation failed because ' + e. end |