Class: Gitlab::QA::Component::Gitlab
- Inherits:
-
Base
- Object
- Base
- Gitlab::QA::Component::Gitlab
show all
- Extended by:
- Forwardable
- Defined in:
- lib/gitlab/qa/component/gitlab.rb
Defined Under Namespace
Classes: Availability
Constant Summary
collapse
- CERTIFICATES_PATH =
File.expand_path('../../../../tls_certificates', __dir__)
- DATA_SEED_PATH =
File.expand_path('../../../../support/data', __dir__)
- SSL_PATH =
'/etc/gitlab/ssl'
- TRUSTED_PATH =
'/etc/gitlab/trusted-certs'
- DATA_PATH =
'/tmp/data-seeds'
Instance Attribute Summary collapse
Attributes inherited from Base
#docker, #environment, #network, #ports, #volumes
Instance Method Summary
collapse
Methods inherited from Base
#add_network_alias, #hostname, #image, #instance, #prepare_docker_container, #prepare_docker_image, #prepare_network, #restart, #tag, #teardown
#act, included
Constructor Details
#initialize ⇒ Gitlab
Returns a new instance of Gitlab.
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 32
def initialize
super
@skip_availability_check = false
@omnibus_gitlab_rails_env = {}
@omnibus_configuration = Runtime::OmnibusConfiguration.new(Runtime::Scenario.omnibus_configuration)
@working_dir_tmp_cert_path = Dir.mktmpdir('certs', FileUtils.mkdir_p("#{Dir.pwd}/tmp"))
@authority_cert_path = "#{@working_dir_tmp_cert_path}/authority"
@gitlab_cert_path = "#{@working_dir_tmp_cert_path}/gitlab"
@gitaly_cert_path = "#{@working_dir_tmp_cert_path}/gitaly"
@volumes[@gitlab_cert_path] = SSL_PATH
@volumes[@authority_cert_path] = TRUSTED_PATH
@seed_admin_token = Runtime::Scenario.seed_admin_token
@seed_db = Runtime::Scenario.seed_db
@skip_server_hooks = Runtime::Scenario.skip_server_hooks
self.release = 'CE'
end
|
Instance Attribute Details
#name ⇒ Object
76
77
78
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 76
def name
@name ||= "gitlab-#{edition}-#{SecureRandom.hex(4)}"
end
|
#omnibus_configuration ⇒ Object
Returns the value of attribute omnibus_configuration.
19
20
21
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 19
def omnibus_configuration
@omnibus_configuration
end
|
#omnibus_gitlab_rails_env ⇒ Object
Returns the value of attribute omnibus_gitlab_rails_env.
19
20
21
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 19
def omnibus_gitlab_rails_env
@omnibus_gitlab_rails_env
end
|
#relative_path ⇒ Object
97
98
99
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 97
def relative_path
@relative_path ||= ''
end
|
#release ⇒ Object
Returns the value of attribute release.
19
20
21
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 19
def release
@release
end
|
#runner_network ⇒ Object
Returns the value of attribute runner_network.
20
21
22
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 20
def runner_network
@runner_network
end
|
#seed_admin_token ⇒ Object
Returns the value of attribute seed_admin_token.
20
21
22
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 20
def seed_admin_token
@seed_admin_token
end
|
#seed_db ⇒ Object
Returns the value of attribute seed_db.
20
21
22
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 20
def seed_db
@seed_db
end
|
#skip_availability_check ⇒ Object
Returns the value of attribute skip_availability_check.
20
21
22
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 20
def skip_availability_check
@skip_availability_check
end
|
#skip_server_hooks ⇒ Object
Returns the value of attribute skip_server_hooks.
20
21
22
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 20
def skip_server_hooks
@skip_server_hooks
end
|
#tls ⇒ Object
Returns the value of attribute tls.
20
21
22
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 20
def tls
@tls
end
|
Instance Method Details
#address ⇒ Object
80
81
82
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 80
def address
"#{scheme}://#{hostname}#{relative_path}"
end
|
#copy_key_file(env_key) ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 227
def copy_key_file(env_key)
key_dir = ENV['CI_PROJECT_DIR'] || Dir.tmpdir
key_file = Tempfile.new(env_key.downcase, key_dir)
key_file.write(ENV.fetch(env_key))
key_file.close
File.chmod(0o744, key_file.path)
@volumes[key_file.path] = key_file.path
key_file.path
end
|
#elastic_url=(url) ⇒ Object
68
69
70
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 68
def elastic_url=(url)
@environment['ELASTIC_URL'] = url
end
|
#exist?(image, tag) ⇒ Boolean
124
125
126
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 124
def exist?(image, tag)
docker.manifest_exists?("#{image}:#{tag}")
end
|
#gitaly_tls ⇒ Object
92
93
94
95
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 92
def gitaly_tls
@volumes.delete(@gitlab_cert_path)
@volumes[@gitaly_cert_path] = SSL_PATH
end
|
#gitlab_port ⇒ Object
88
89
90
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 88
def gitlab_port
tls ? ["443:443"] : ["80"]
end
|
#package_version ⇒ Object
222
223
224
225
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 222
def package_version
manifest = JSON.parse(read_package_manifest)
manifest['software']['package-scripts']['locked_version']
end
|
#prepare ⇒ Object
105
106
107
108
109
110
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 105
def prepare
prepare_gitlab_omnibus_config
copy_certificates
super
end
|
#prepare_gitlab_omnibus_config ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 128
def prepare_gitlab_omnibus_config
set_formless_login_token
set_license_mode
return if omnibus_gitlab_rails_env.empty?
@omnibus_configuration << "gitlab_rails['env'] = #{@omnibus_gitlab_rails_env}"
end
|
#process_exec_commands ⇒ Object
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 199
def process_exec_commands
@docker.copy(name, DATA_SEED_PATH, DATA_PATH) if seed_admin_token || seed_db
exec_commands << seed_admin_token_command if seed_admin_token
exec_commands << seed_test_data_command if seed_db
exec_commands << Runtime::Scenario.omnibus_exec_commands
exec_commands << add_git_server_hooks unless skip_server_hooks
commands = exec_commands.flatten.uniq
return if commands.empty?
Runtime::Logger.info("Running exec_commands...")
commands.each { |command| @docker.exec(name, command) }
end
|
#pull ⇒ Object
118
119
120
121
122
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 118
def pull
docker.login(**release.login_params) if release.login_params
super
end
|
#rails_version ⇒ Object
214
215
216
217
218
219
220
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 214
def rails_version
manifest = JSON.parse(read_package_manifest)
{
sha: manifest['software']['gitlab-rails']['locked_version'],
source: manifest['software']['gitlab-rails']['locked_source']['git']
}
end
|
171
172
173
174
175
176
177
178
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 171
def reconfigure
setup_omnibus
@docker.attach(name) do |line, wait|
break if /gitlab Reconfigured!/.match?(line)
end
end
|
#scheme ⇒ Object
84
85
86
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 84
def scheme
tls ? 'https' : 'http'
end
|
#set_accept_insecure_certs ⇒ Object
101
102
103
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 101
def set_accept_insecure_certs
Runtime::Env.accept_insecure_certs = 'true'
end
|
55
56
57
58
59
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 55
def set_formless_login_token
return if Runtime::Env.gitlab_qa_formless_login_token.to_s.strip.empty?
@omnibus_gitlab_rails_env['GITLAB_QA_FORMLESS_LOGIN_TOKEN'] = Runtime::Env.gitlab_qa_formless_login_token
end
|
#set_license_mode ⇒ Object
61
62
63
64
65
66
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 61
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
|
#start ⇒ Object
rubocop:disable Metrics/AbcSize
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 136
def start ensure_configured!
docker.run(image: image, tag: tag) do |command|
command << "-d"
command << "--name #{name}"
command << "--net #{network}"
command << "--hostname #{hostname}"
[*@ports, *gitlab_port].each do |mapping|
command.port(mapping)
end
@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
return unless runner_network
Docker::Command.execute(
"network connect --alias #{name}.#{network} --alias #{name}.#{runner_network} #{runner_network} #{name}"
)
end
|
#teardown! ⇒ Object
112
113
114
115
116
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 112
def teardown!
FileUtils.rm_rf(@working_dir_tmp_cert_path)
super
end
|
#wait_until_ready ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/gitlab/qa/component/gitlab.rb', line 180
def wait_until_ready
return if skip_availability_check
availability = Availability.new(
name,
relative_path: relative_path,
scheme: scheme,
protocol_port: gitlab_port.first.to_i
)
Runtime::Logger.info("Waiting for GitLab to become healthy ...")
if availability.check(Runtime::Env.gitlab_availability_timeout)
Runtime::Logger.info("-> GitLab is available at `#{availability.uri}`!".bright)
else
abort '-> GitLab unavailable!'.red
end
end
|