Sha256: b23b1172ba109185f81354e7d42773db9bf23be041183588327e032ed601d152

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

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

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

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

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

        def name
          @name ||= "elastic68"
        end

        def instance
          prepare
          start
          yield self
        ensure
          teardown
        end

        def prepare
          @docker.pull(ELASTIC_IMAGE, Runtime::Env.elastic_version)
          return if @docker.network_exists?(network)

          @docker.network_create(network)
        end

        def start
          @docker.run(ELASTIC_IMAGE, Runtime::Env.elastic_version) 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

5 entries across 5 versions & 1 rubygems

Version Path
gitlab-qa-5.13.6 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-5.13.3 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-5.13.2 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-5.13.1 lib/gitlab/qa/component/elasticsearch.rb
gitlab-qa-5.13.0 lib/gitlab/qa/component/elasticsearch.rb