Class: Gitlab::QA::Component::Gitlab
- Extended by:
- Forwardable
- Defined in:
- lib/gitlab/qa/component/gitlab.rb
Defined Under Namespace
Classes: Availability
Constant Summary collapse
- DATA_SEED_PATH =
File.('../../../../support/data', __dir__)
- TRUSTED_PATH =
'/etc/gitlab/trusted-certs'
- SSL_PATH =
'/etc/gitlab/ssl'
- DATA_PATH =
'/tmp/data-seeds'
Constants inherited from Base
Instance Attribute Summary collapse
-
#authority_volume ⇒ Object
readonly
Returns the value of attribute authority_volume.
-
#gitaly_tls ⇒ Object
Returns the value of attribute gitaly_tls.
- #name ⇒ Object
-
#omnibus_configuration ⇒ Object
readonly
Returns the value of attribute omnibus_configuration.
-
#omnibus_gitlab_rails_env ⇒ Object
readonly
Returns the value of attribute omnibus_gitlab_rails_env.
- #relative_path ⇒ Object
-
#release ⇒ Object
Returns the value of attribute release.
-
#runner_network ⇒ Object
Returns the value of attribute runner_network.
-
#secrets ⇒ Object
Returns the value of attribute secrets.
-
#seed_admin_token ⇒ Object
Returns the value of attribute seed_admin_token.
-
#seed_db ⇒ Object
Returns the value of attribute seed_db.
-
#skip_availability_check ⇒ Object
Returns the value of attribute skip_availability_check.
-
#skip_server_hooks ⇒ Object
Returns the value of attribute skip_server_hooks.
-
#ssl_volume ⇒ Object
readonly
Returns the value of attribute ssl_volume.
-
#tls ⇒ Object
Returns the value of attribute tls.
Attributes inherited from Base
#additional_hosts, #airgapped_network, #docker, #environment, #network, #network_aliases, #ports, #volumes
Instance Method Summary collapse
- #address ⇒ Object
- #copy_key_file(env_key) ⇒ Object
- #elastic_url=(url) ⇒ Object
- #exist?(image, tag) ⇒ Boolean
- #gitlab_port ⇒ Object
-
#initialize ⇒ Gitlab
constructor
A new instance of Gitlab.
- #package_version ⇒ Object
- #prepare ⇒ Object
- #prepare_gitlab_omnibus_config ⇒ Object
- #process_exec_commands ⇒ Object
- #pull ⇒ Object
- #rails_version ⇒ Object
- #reconfigure ⇒ Object
- #scheme ⇒ Object
- #set_accept_insecure_certs ⇒ Object
- #set_formless_login_token ⇒ Object
- #set_license_mode ⇒ Object
-
#set_qa_user_agent ⇒ Object
Sets GITLAB_QA_USER_AGENT as a Rail environment variable so that it can be used by GitLab to bypass features that can’t be automated.
-
#start ⇒ Object
rubocop:disable Metrics/AbcSize.
- #wait_until_ready ⇒ Object
Methods inherited from Base
#add_network_alias, #hostname, #image, #instance, #ip_address, #prepare_airgapped_network, #prepare_docker_container, #prepare_docker_image, #prepare_network, #prepare_runner_network, #restart, #start_instance, #tag, #teardown, #teardown!
Methods included from Scenario::Actable
Constructor Details
#initialize ⇒ Gitlab
Returns a new instance of Gitlab.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 44 def initialize super @skip_availability_check = false @omnibus_gitlab_rails_env = {} @omnibus_configuration = Runtime::OmnibusConfiguration.new(Runtime::Scenario.omnibus_configuration) @cert_volumes = { "authority" => TRUSTED_PATH, "gitlab-ssl" => SSL_PATH } @seed_admin_token = Runtime::Scenario.seed_admin_token @seed_db = Runtime::Scenario.seed_db @skip_server_hooks = Runtime::Scenario.skip_server_hooks @secrets = [] self.release = 'CE' end |
Instance Attribute Details
#authority_volume ⇒ Object (readonly)
Returns the value of attribute authority_volume.
19 20 21 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 19 def @authority_volume end |
#gitaly_tls ⇒ Object
Returns the value of attribute gitaly_tls.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def gitaly_tls @gitaly_tls end |
#name ⇒ Object
89 90 91 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 89 def name @name ||= "gitlab-#{edition}-#{SecureRandom.hex(4)}" end |
#omnibus_configuration ⇒ Object (readonly)
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 (readonly)
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
105 106 107 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 105 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.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def runner_network @runner_network end |
#secrets ⇒ Object
Returns the value of attribute secrets.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def secrets @secrets end |
#seed_admin_token ⇒ Object
Returns the value of attribute seed_admin_token.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def seed_admin_token @seed_admin_token end |
#seed_db ⇒ Object
Returns the value of attribute seed_db.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def seed_db @seed_db end |
#skip_availability_check ⇒ Object
Returns the value of attribute skip_availability_check.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def skip_availability_check @skip_availability_check end |
#skip_server_hooks ⇒ Object
Returns the value of attribute skip_server_hooks.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def skip_server_hooks @skip_server_hooks end |
#ssl_volume ⇒ Object (readonly)
Returns the value of attribute ssl_volume.
19 20 21 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 19 def ssl_volume @ssl_volume end |
#tls ⇒ Object
Returns the value of attribute tls.
25 26 27 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 25 def tls @tls end |
Instance Method Details
#address ⇒ Object
93 94 95 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 93 def address "#{scheme}://#{hostname}#{relative_path}" end |
#copy_key_file(env_key) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 238 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
81 82 83 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 81 def elastic_url=(url) @environment['ELASTIC_URL'] = url end |
#exist?(image, tag) ⇒ Boolean
126 127 128 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 126 def exist?(image, tag) docker.manifest_exists?("#{image}:#{tag}") end |
#gitlab_port ⇒ Object
101 102 103 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 101 def gitlab_port tls ? ["443:443"] : ["80"] end |
#package_version ⇒ Object
233 234 235 236 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 233 def package_version manifest = JSON.parse(read_package_manifest) manifest['software']['package-scripts']['locked_version'] end |
#prepare ⇒ Object
113 114 115 116 117 118 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 113 def prepare prepare_gitlab_omnibus_config copy_certificates super end |
#prepare_gitlab_omnibus_config ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 130 def prepare_gitlab_omnibus_config set_formless_login_token set_license_mode set_qa_user_agent env = @omnibus_gitlab_rails_env.merge( { 'GITLAB_ALLOW_SEPARATE_CI_DATABASE' => Runtime::Env.allow_separate_ci_database.to_s } ) @omnibus_configuration << "gitlab_rails['env'] = #{env}" end |
#process_exec_commands ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 210 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 << Support::ConfigScripts.add_git_server_hooks(docker, name) 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, mask_secrets: secrets) } end |
#pull ⇒ Object
120 121 122 123 124 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 120 def pull docker.login(**release.login_params) if release.login_params super end |
#rails_version ⇒ Object
225 226 227 228 229 230 231 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 225 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 |
#reconfigure ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 182 def reconfigure setup_omnibus @docker.attach(name) do |line, wait| # TODO, workaround which allows to detach from the container break if /gitlab Reconfigured!/.match?(line) end end |
#scheme ⇒ Object
97 98 99 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 97 def scheme tls ? 'https' : 'http' end |
#set_accept_insecure_certs ⇒ Object
109 110 111 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 109 def set_accept_insecure_certs Runtime::Env.accept_insecure_certs = 'true' end |
#set_formless_login_token ⇒ Object
59 60 61 62 63 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 59 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
65 66 67 68 69 70 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 65 def set_license_mode return unless Runtime::Env.gitlab_license_mode == 'test' @omnibus_gitlab_rails_env['GITLAB_LICENSE_MODE'] = 'test' @omnibus_gitlab_rails_env['CUSTOMER_PORTAL_URL'] = Runtime::Env.customer_portal_url end |
#set_qa_user_agent ⇒ Object
Sets GITLAB_QA_USER_AGENT as a Rail environment variable so that it can be used by GitLab to bypass features that can’t be automated.
74 75 76 77 78 79 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 74 def set_qa_user_agent return if Runtime::Env.gitlab_qa_user_agent.to_s.strip.empty? @omnibus_gitlab_rails_env['GITLAB_QA_USER_AGENT'] = Runtime::Env.gitlab_qa_user_agent secrets << Runtime::Env.gitlab_qa_user_agent end |
#start ⇒ Object
rubocop:disable Metrics/AbcSize
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 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 143 def start # rubocop:disable Metrics/AbcSize 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.merge(cert_volumes).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 @additional_hosts.each do |host| command << "--add-host=#{host}" end end return unless runner_network Docker::Command.execute( "network connect --alias #{name}.#{network} --alias #{name}.#{runner_network} #{runner_network} #{name}" ) end |
#wait_until_ready ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 191 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 |