Class: Gitlab::QA::Component::PostgreSQL

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

Constant Summary collapse

POSTGRES_IMAGE =
'postgres'.freeze
POSTGRES_IMAGE_TAG =
'11'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializePostgreSQL

Returns a new instance of PostgreSQL.



14
15
16
17
# File 'lib/gitlab/qa/component/postgresql.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/postgresql.rb', line 10

def docker
  @docker
end

#environmentObject

Returns the value of attribute environment.



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

def environment
  @environment
end

#nameObject



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

def name
  @name ||= "postgres"
end

#networkObject

Returns the value of attribute network.



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

def network
  @network
end

Instance Method Details

#instanceObject



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

def instance
  prepare
  start
  wait_until_ready
  yield self
ensure
  teardown
end

#prepareObject



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

def prepare
  @docker.pull(POSTGRES_IMAGE, POSTGRES_IMAGE_TAG)
  return if @docker.network_exists?(network)

  @docker.network_create(network)
end

#run_psql(command) ⇒ Object



54
55
56
# File 'lib/gitlab/qa/component/postgresql.rb', line 54

def run_psql(command)
  @docker.exec(name, %(psql -U postgres #{command}))
end

#startObject



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

def start
  @docker.run(POSTGRES_IMAGE, POSTGRES_IMAGE_TAG) do |command|
    command << "-d"
    command << "--name #{name}"
    command << "--net #{network}"

    command.env("POSTGRES_PASSWORD", "SQL_PASSWORD")
  end
end

#teardownObject



49
50
51
52
# File 'lib/gitlab/qa/component/postgresql.rb', line 49

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