Class: Gitlab::QA::Component::Gitlab
- Inherits:
-
Object
- Object
- Gitlab::QA::Component::Gitlab
- Extended by:
- Forwardable
- Includes:
- Scenario::Actable
- Defined in:
- lib/gitlab/qa/component/gitlab.rb
Defined Under Namespace
Classes: Availability
Constant Summary collapse
- CERTIFICATES_PATH =
File.('../../../../tls_certificates/gitlab'.freeze, __dir__)
- SSL_PATH =
'/etc/gitlab/ssl'.freeze
Instance Attribute Summary collapse
-
#docker ⇒ Object
readonly
Returns the value of attribute docker.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#exec_commands ⇒ Object
writeonly
Sets the attribute exec_commands.
- #name ⇒ Object
-
#network ⇒ Object
Returns the value of attribute network.
- #relative_path ⇒ Object
-
#release ⇒ Object
Returns the value of attribute release.
-
#tls ⇒ Object
Returns the value of attribute tls.
-
#volumes ⇒ Object
Returns the value of attribute volumes.
Instance Method Summary collapse
- #add_network_alias(name) ⇒ Object
- #address ⇒ Object
- #elastic_url=(url) ⇒ Object
- #hostname ⇒ Object
-
#initialize ⇒ Gitlab
constructor
A new instance of Gitlab.
- #instance ⇒ Object (also: #launch_and_teardown_instance)
- #omnibus_config=(config) ⇒ Object
- #port ⇒ Object
- #prepare ⇒ Object
- #process_exec_commands ⇒ Object
- #pull ⇒ Object
- #reconfigure ⇒ Object
- #restart ⇒ Object
- #scheme ⇒ Object
- #sha_version ⇒ Object
-
#start ⇒ Object
rubocop:disable Metrics/AbcSize.
- #teardown ⇒ Object
- #wait ⇒ Object
Methods included from Scenario::Actable
Constructor Details
#initialize ⇒ Gitlab
Returns a new instance of Gitlab.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 23 def initialize @docker = Docker::Engine.new @environment = {} @volumes = {} @network_aliases = [] @volumes[CERTIFICATES_PATH] = SSL_PATH self.release = 'CE' self.exec_commands = [] end |
Instance Attribute Details
#docker ⇒ Object (readonly)
Returns the value of attribute docker.
14 15 16 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 14 def docker @docker end |
#environment ⇒ Object
Returns the value of attribute environment.
15 16 17 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 15 def environment @environment end |
#exec_commands=(value) ⇒ Object
Sets the attribute exec_commands
16 17 18 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 16 def exec_commands=(value) @exec_commands = value end |
#name ⇒ Object
51 52 53 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 51 def name @name ||= "gitlab-#{edition}-#{SecureRandom.hex(4)}" end |
#network ⇒ Object
Returns the value of attribute network.
15 16 17 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 15 def network @network end |
#relative_path ⇒ Object
71 72 73 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 71 def relative_path @relative_path ||= '' end |
#release ⇒ Object
Returns the value of attribute release.
14 15 16 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 14 def release @release end |
#tls ⇒ Object
Returns the value of attribute tls.
15 16 17 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 15 def tls @tls end |
#volumes ⇒ Object
Returns the value of attribute volumes.
15 16 17 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 15 def volumes @volumes end |
Instance Method Details
#add_network_alias(name) ⇒ Object
43 44 45 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 43 def add_network_alias(name) @network_aliases.push(name) end |
#address ⇒ Object
55 56 57 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 55 def address "#{scheme}://#{hostname}#{relative_path}" end |
#elastic_url=(url) ⇒ Object
39 40 41 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 39 def elastic_url=(url) @environment['ELASTIC_URL'] = url end |
#hostname ⇒ Object
67 68 69 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 67 def hostname "#{name}.#{network}" end |
#instance ⇒ Object Also known as: launch_and_teardown_instance
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 75 def instance prepare start reconfigure wait process_exec_commands yield self if block_given? ensure teardown end |
#omnibus_config=(config) ⇒ Object
35 36 37 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 35 def omnibus_config=(config) @environment['GITLAB_OMNIBUS_CONFIG'] = config.tr("\n", ' ') end |
#port ⇒ Object
63 64 65 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 63 def port tls ? '443' : '80' end |
#prepare ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 89 def prepare @docker.pull(image, tag) unless Runtime::Env.skip_pull? return if @docker.network_exists?(network) @docker.network_create(network) end |
#process_exec_commands ⇒ Object
176 177 178 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 176 def process_exec_commands exec_commands.each { |command| @docker.exec(name, command) } end |
#pull ⇒ Object
162 163 164 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 162 def pull @docker.pull(@release.image, @release.tag) end |
#reconfigure ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 133 def reconfigure @docker.attach(name) do |line, wait| puts line # TODO, workaround which allows to detach from the container # Process.kill('INT', wait.pid) if line =~ /gitlab Reconfigured!/ end end |
#restart ⇒ Object
142 143 144 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 142 def restart @docker.restart(name) end |
#scheme ⇒ Object
59 60 61 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 59 def scheme tls ? 'https' : 'http' end |
#sha_version ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 166 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 |
#start ⇒ Object
rubocop:disable Metrics/AbcSize
97 98 99 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 125 126 127 128 129 130 131 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 97 def start # rubocop:disable Metrics/AbcSize ensure_configured! if release.dev_gitlab_org? Docker::Command.execute( [ 'login', '--username gitlab-qa-bot', %(--password "#{Runtime::Env.dev_access_token_variable}"), Release::DEV_REGISTRY ] ) end docker.run(image, 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 end |
#teardown ⇒ Object
146 147 148 149 150 151 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 146 def teardown raise 'Invalid instance name!' unless name @docker.stop(name) @docker.remove(name) end |
#wait ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 153 def wait if Availability.new(name, relative_path: relative_path, scheme: scheme, protocol_port: port.to_i).check(180) sleep 12 # TODO, handle that better puts ' -> GitLab is available.' else abort ' -> GitLab unavailable!' end end |