Class: Gitlab::QA::Component::Elasticsearch

Inherits:
Object
  • Object
show all
Includes:
Scenario::Actable
Defined in:
lib/gitlab/qa/component/elasticsearch.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializeElasticsearch

Returns a new instance of Elasticsearch.



14
15
16
17
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 14

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

Instance Attribute Details

#dockerObject (readonly)

Returns the value of attribute docker.



10
11
12
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 10

def docker
  @docker
end

#environmentObject

Returns the value of attribute environment.



11
12
13
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 11

def environment
  @environment
end

#nameObject



19
20
21
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 19

def name
  @name ||= "elastic68"
end

#networkObject

Returns the value of attribute network.



11
12
13
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 11

def network
  @network
end

Instance Method Details

#instanceObject



23
24
25
26
27
28
29
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 23

def instance
  prepare
  start
  yield self
ensure
  teardown
end

#prepareObject



31
32
33
34
35
36
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 31

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

  @docker.network_create(network)
end

#startObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 38

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

#teardownObject



50
51
52
53
# File 'lib/gitlab/qa/component/elasticsearch.rb', line 50

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