Sha256: f97bc15ebe917ee145472ae13e4c4a761bba72ed79e7f281329ead9091384935

Contents?: true

Size: 1.73 KB

Versions: 21

Compression:

Stored size: 1.73 KB

Contents

module Minke
  module Docker
    class Consul
      def initialize args
        @health_check = args[:health_check]
        @service_discovery = args[:service_discovery]
        @consul_loader = args[:consul_loader]
        @docker_runner = args[:docker_runner]
        @network = args[:network]
        @project_name = args[:project_name]
        @logger = args[:logger_helper]
      end

      ##
      # start_and_load_data config
      def start_and_load_data consul_config
        @logger.info "Starting Consul"
        start
        wait_for_startup consul_config.url
        load_data consul_config.url, consul_config.config_file
      end

      ##
      # stop consul
      def stop
        @logger.info "Stopping Consul"
        @docker_runner.stop_container @container unless @container == nil
        @docker_runner.delete_container @container unless @container == nil
      end

      private
      def start
        @docker_runner.pull_image 'progrium/consul:latest' unless @docker_runner.find_image 'progrium/consul:latest'
        @container, success = @docker_runner.create_and_run_container(
          {
            :image   => 'progrium/consul',
            :network => @network,
            :command => '-server -bootstrap -ui-dir /ui',
            :name    => "/#{@project_name}_consul_1",
            :deamon  => true
          }
        )
      end

      def wait_for_startup url
        server = @service_discovery.build_address(url)
        @health_check.wait_for_HTTPOK "#{server}/v1/status/leader"
      end

      ##
      # Loads consul data into the given server
      def load_data url, config_file
        server = @service_discovery.build_address(url)
        @consul_loader.load_config config_file, server
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
minke-1.15.0 lib/minke/docker/consul.rb
minke-1.14.5 lib/minke/docker/consul.rb
minke-1.14.4 lib/minke/docker/consul.rb
minke-1.14.3 lib/minke/docker/consul.rb
minke-1.14.2 lib/minke/docker/consul.rb
minke-1.14.1 lib/minke/docker/consul.rb
minke-1.14.0 lib/minke/docker/consul.rb
minke-1.13.20 lib/minke/docker/consul.rb
minke-1.13.19 lib/minke/docker/consul.rb
minke-1.13.18 lib/minke/docker/consul.rb
minke-1.13.16 lib/minke/docker/consul.rb
minke-1.13.15 lib/minke/docker/consul.rb
minke-1.13.14 lib/minke/docker/consul.rb
minke-1.13.13 lib/minke/docker/consul.rb
minke-1.13.12 lib/minke/docker/consul.rb
minke-1.13.11 lib/minke/docker/consul.rb
minke-1.13.10 lib/minke/docker/consul.rb
minke-1.13.9 lib/minke/docker/consul.rb
minke-1.13.8 lib/minke/docker/consul.rb
minke-1.13.7 lib/minke/docker/consul.rb