Sha256: 107bb6d1b1d547ab7334842df603506cd377a2e6b6c13cbafe0ea942b291cd20

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

module Gitlab
  module QA
    module Component
      class Elasticsearch
        include Scenario::Actable

        ELASTIC_IMAGE = 'docker.elastic.co/elasticsearch/elasticsearch'.freeze
        ELASTIC_IMAGE_TAG = '5.6.12'.freeze

        attr_reader :docker
        attr_accessor :environment, :network
        attr_writer :name

        def initialize
          @docker = Docker::Engine.new
          @environment = {}
        end

        def name
          @name ||= "elastic56"
        end

        def instance
          prepare
          start
          yield self
        ensure
          teardown
        end

        def prepare
          @docker.pull(ELASTIC_IMAGE, ELASTIC_IMAGE_TAG)
          return if @docker.network_exists?(network)

          @docker.network_create(network)
        end

        def start
          @docker.run(ELASTIC_IMAGE, ELASTIC_IMAGE_TAG) do |command|
            command << "-d"
            command << "--name #{name}"
            command << "--net #{network}"
            command << "--publish 9200:9200"
            command << "--publish 9300:9300"

            command.env("discovery.type", "single-node")
          end
        end

        def teardown
          @docker.stop(name)
          @docker.remove(name)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gitlab-qa-4.1.0 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-4.0.5 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-4.0.4 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-4.0.3 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-4.0.2 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-4.0.1 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-4.0.0 lib/gitlab/qa/component/elasticsearch.rb