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

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gitlab/qa/component/gitlab.rb

Defined Under Namespace

Classes: Availability

Constant Summary collapse

AUTHORITY_CERTIFICATES_PATH =
File.expand_path('../../../../tls_certificates/authority', __dir__)
GITLAB_CERTIFICATES_PATH =
File.expand_path('../../../../tls_certificates/gitlab', __dir__)
GITALY_CERTIFICATES_PATH =
File.expand_path('../../../../tls_certificates/gitaly', __dir__)
SSL_PATH =
'/etc/gitlab/ssl'
TRUSTED_PATH =
'/etc/gitlab/trusted-certs'

Instance Attribute Summary collapse

Attributes inherited from Base

#docker, #environment, #network, #volumes

Instance Method Summary collapse

Methods inherited from Base

#add_network_alias, #hostname, #image, #instance, #prepare_docker_container, #prepare_docker_image, #prepare_network, #process_exec_commands, #restart, #tag, #teardown, #teardown!

Methods included from Scenario::Actable

#act, included

Constructor Details

#initializeGitlab

Returns a new instance of Gitlab.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/qa/component/gitlab.rb', line 28

def initialize
  super

  @skip_availability_check = false

  @volumes[GITLAB_CERTIFICATES_PATH] = SSL_PATH
  @volumes[AUTHORITY_CERTIFICATES_PATH] = TRUSTED_PATH

  @omnibus_configuration ||= Runtime::OmnibusConfiguration.new(Runtime::Scenario.omnibus_configuration)

  self.release = 'CE'
end

Instance Attribute Details

#nameObject



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

def name
  @name ||= "gitlab-#{edition}-#{SecureRandom.hex(4)}"
end

#omnibus_configurationObject (readonly)

Returns the value of attribute omnibus_configuration.



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

def omnibus_configuration
  @omnibus_configuration
end

#relative_pathObject



76
77
78
# File 'lib/gitlab/qa/component/gitlab.rb', line 76

def relative_path
  @relative_path ||= ''
end

#releaseObject

Returns the value of attribute release.



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

def release
  @release
end

#runner_networkObject

Returns the value of attribute runner_network.



16
17
18
# File 'lib/gitlab/qa/component/gitlab.rb', line 16

def runner_network
  @runner_network
end

#skip_availability_checkObject

Returns the value of attribute skip_availability_check.



16
17
18
# File 'lib/gitlab/qa/component/gitlab.rb', line 16

def skip_availability_check
  @skip_availability_check
end

#tlsObject

Returns the value of attribute tls.



16
17
18
# File 'lib/gitlab/qa/component/gitlab.rb', line 16

def tls
  @tls
end

Instance Method Details

#addressObject



59
60
61
# File 'lib/gitlab/qa/component/gitlab.rb', line 59

def address
  "#{scheme}://#{hostname}#{relative_path}"
end

#elastic_url=(url) ⇒ Object



47
48
49
# File 'lib/gitlab/qa/component/gitlab.rb', line 47

def elastic_url=(url)
  @environment['ELASTIC_URL'] = url
end

#gitaly_tlsObject



71
72
73
74
# File 'lib/gitlab/qa/component/gitlab.rb', line 71

def gitaly_tls
  @volumes.delete(GITLAB_CERTIFICATES_PATH)
  @volumes[GITALY_CERTIFICATES_PATH] = SSL_PATH
end

#portObject



67
68
69
# File 'lib/gitlab/qa/component/gitlab.rb', line 67

def port
  tls ? '443:443' : '80'
end

#prepareObject



84
85
86
87
88
# File 'lib/gitlab/qa/component/gitlab.rb', line 84

def prepare
  prepare_gitlab_omnibus_config

  super
end

#prepare_gitlab_omnibus_configObject



96
97
98
# File 'lib/gitlab/qa/component/gitlab.rb', line 96

def prepare_gitlab_omnibus_config
  
end

#pullObject



90
91
92
93
94
# File 'lib/gitlab/qa/component/gitlab.rb', line 90

def pull
  docker.(**release.) if release.

  super
end

#reconfigureObject



126
127
128
129
130
131
132
133
134
135
# File 'lib/gitlab/qa/component/gitlab.rb', line 126

def reconfigure
  setup_omnibus

  @docker.attach(name) do |line, wait|
    puts line
    # TODO, workaround which allows to detach from the container
    #
    break if line =~ /gitlab Reconfigured!/
  end
end

#schemeObject



63
64
65
# File 'lib/gitlab/qa/component/gitlab.rb', line 63

def scheme
  tls ? 'https' : 'http'
end

#set_accept_insecure_certsObject



80
81
82
# File 'lib/gitlab/qa/component/gitlab.rb', line 80

def set_accept_insecure_certs
  Runtime::Env.accept_insecure_certs = 'true'
end

#set_formless_login_tokenObject



41
42
43
44
45
# File 'lib/gitlab/qa/component/gitlab.rb', line 41

def 
  return if Runtime::Env..to_s.strip.empty?

  @omnibus_configuration << "gitlab_rails['env'] = { 'GITLAB_QA_FORMLESS_LOGIN_TOKEN' => '#{Runtime::Env.}' }"
end

#sha_versionObject



148
149
150
151
152
153
154
155
156
# File 'lib/gitlab/qa/component/gitlab.rb', line 148

def sha_version
  json = @docker.read_file(
    @release.image, @release.tag,
    '/opt/gitlab/version-manifest.json'
  )

  manifest = JSON.parse(json)
  manifest['software']['gitlab-rails']['locked_version']
end

#startObject

rubocop:disable Metrics/AbcSize



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gitlab/qa/component/gitlab.rb', line 100

def start # rubocop:disable Metrics/AbcSize
  ensure_configured!

  docker.run(image: image, tag: tag) do |command|
    command << "-d -p #{port}"
    command << "--name #{name}"
    command << "--net #{network}"
    command << "--hostname #{hostname}"

    @volumes.to_h.each do |to, from|
      command.volume(to, from, 'Z')
    end

    command.volume(File.join(Runtime::Env.host_artifacts_dir, name, 'logs'), '/var/log/gitlab', 'Z')

    @environment.to_h.each do |key, value|
      command.env(key, value)
    end

    @network_aliases.to_a.each do |network_alias|
      command << "--network-alias #{network_alias}"
    end
  end
  Docker::Command.execute("network connect --alias #{name}.#{network} --alias #{name}.#{runner_network} #{runner_network} #{name}") if runner_network
end

#wait_until_readyObject



137
138
139
140
141
142
143
144
145
146
# File 'lib/gitlab/qa/component/gitlab.rb', line 137

def wait_until_ready
  return if skip_availability_check

  if Availability.new(name, relative_path: relative_path, scheme: scheme, protocol_port: port.to_i).check(Runtime::Env.gitlab_availability_timeout)
    sleep 12 # TODO, handle that better
    puts ' -> GitLab is available.'
  else
    abort ' -> GitLab unavailable!'
  end
end