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
40
# File 'lib/gitlab/qa/component/gitlab.rb', line 28

def initialize
  super

  @skip_availability_check = false
  @omnibus_gitlab_rails_env = {}

  @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



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

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

#omnibus_gitlab_rails_envObject (readonly)

Returns the value of attribute omnibus_gitlab_rails_env.



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

def omnibus_gitlab_rails_env
  @omnibus_gitlab_rails_env
end

#relative_pathObject



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

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



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

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

#elastic_url=(url) ⇒ Object



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

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

#gitaly_tlsObject



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

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

#portObject



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

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

#prepareObject



92
93
94
95
96
# File 'lib/gitlab/qa/component/gitlab.rb', line 92

def prepare
  prepare_gitlab_omnibus_config

  super
end

#prepare_gitlab_omnibus_configObject



104
105
106
107
108
109
# File 'lib/gitlab/qa/component/gitlab.rb', line 104

def prepare_gitlab_omnibus_config
  
  set_license_mode

  @omnibus_configuration << "gitlab_rails['env'] = #{@omnibus_gitlab_rails_env}" unless omnibus_gitlab_rails_env.empty?
end

#pullObject



98
99
100
101
102
# File 'lib/gitlab/qa/component/gitlab.rb', line 98

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

  super
end

#reconfigureObject



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

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



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

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

#set_accept_insecure_certsObject



88
89
90
# File 'lib/gitlab/qa/component/gitlab.rb', line 88

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

#set_formless_login_tokenObject



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

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

  @omnibus_gitlab_rails_env['GITLAB_QA_FORMLESS_LOGIN_TOKEN'] = Runtime::Env.
end

#set_license_modeObject



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

def set_license_mode
  return unless Runtime::Env.test_license_mode?

  @omnibus_gitlab_rails_env['GITLAB_LICENSE_MODE'] = 'test'
  @omnibus_gitlab_rails_env['CUSTOMER_PORTAL_URL'] = 'https://customers.staging.gitlab.com'
end

#sha_versionObject



159
160
161
162
163
164
165
166
167
# File 'lib/gitlab/qa/component/gitlab.rb', line 159

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gitlab/qa/component/gitlab.rb', line 111

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



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

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