class Algo::Runner::Apply

Attributes

configuration[R]
options[R]

Public Class Methods

call(configuration, options) click to toggle source
# File lib/algo/runner/apply.rb, line 118
def self.call configuration, options
  new(configuration, options).call
end
new(configuration, options) click to toggle source
# File lib/algo/runner/apply.rb, line 71
def initialize configuration, options
  @configuration = configuration
  @options = options
end

Public Instance Methods

call() click to toggle source
# 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.message
end

Private Instance Methods

dryrun?() click to toggle source
# File lib/algo/runner/apply.rb, line 124
def dryrun?
  options[:'dry-run']
end