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
Instance Attribute Summary collapse
-
#docker ⇒ Object
readonly
Returns the value of attribute docker.
-
#environment ⇒ Object
Returns the value of attribute environment.
- #name ⇒ Object
-
#network ⇒ Object
Returns the value of attribute network.
- #relative_path ⇒ Object
-
#release ⇒ Object
Returns the value of attribute release.
-
#volumes ⇒ Object
Returns the value of attribute volumes.
Instance Method Summary collapse
- #add_network_alias(name) ⇒ Object
- #address ⇒ Object
- #hostname ⇒ Object
-
#initialize ⇒ Gitlab
constructor
A new instance of Gitlab.
- #instance {|_self| ... } ⇒ Object
- #omnibus_config=(config) ⇒ Object
- #prepare ⇒ Object
- #pull ⇒ Object
- #reconfigure ⇒ Object
- #restart ⇒ Object
- #sha_version ⇒ Object
-
#start ⇒ Object
rubocop:disable Metrics/AbcSize.
- #teardown ⇒ Object
- #wait ⇒ Object
Methods included from Scenario::Actable
Constructor Details
Instance Attribute Details
#docker ⇒ Object (readonly)
Returns the value of attribute docker.
13 14 15 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 13 def docker @docker end |
#environment ⇒ Object
Returns the value of attribute environment.
14 15 16 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 14 def environment @environment end |
#name ⇒ Object
40 41 42 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 40 def name @name ||= "gitlab-#{edition}-#{SecureRandom.hex(4)}" end |
#network ⇒ Object
Returns the value of attribute network.
14 15 16 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 14 def network @network end |
#relative_path ⇒ Object
52 53 54 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 52 def relative_path @relative_path ||= '' end |
#release ⇒ Object
Returns the value of attribute release.
13 14 15 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 13 def release @release end |
#volumes ⇒ Object
Returns the value of attribute volumes.
14 15 16 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 14 def volumes @volumes end |
Instance Method Details
#add_network_alias(name) ⇒ Object
32 33 34 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 32 def add_network_alias(name) @network_aliases.push(name) end |
#address ⇒ Object
44 45 46 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 44 def address "http://#{hostname}#{relative_path}" end |
#hostname ⇒ Object
48 49 50 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 48 def hostname "#{name}.#{network}" end |
#instance {|_self| ... } ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 56 def instance raise 'Please provide a block!' unless block_given? prepare start reconfigure wait yield self teardown end |
#omnibus_config=(config) ⇒ Object
28 29 30 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 28 def omnibus_config=(config) @environment['GITLAB_OMNIBUS_CONFIG'] = config.tr("\n", ' ') end |
#prepare ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 69 def prepare @docker.pull(image, tag) return if @docker.network_exists?(network) @docker.network_create(network) end |
#pull ⇒ Object
131 132 133 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 131 def pull @docker.pull(@release.image, @release.tag) end |
#reconfigure ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 102 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
111 112 113 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 111 def restart @docker.restart(name) end |
#sha_version ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 135 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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 77 def start # rubocop:disable Metrics/AbcSize ensure_configured! docker.run(image, tag) do |command| command << '-d -p 80' 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
115 116 117 118 119 120 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 115 def teardown raise 'Invalid instance name!' unless name @docker.stop(name) @docker.remove(name) end |
#wait ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/gitlab/qa/component/gitlab.rb', line 122 def wait if Availability.new(name, relative_path: relative_path).check(180) sleep 12 # TODO, handle that better puts ' -> GitLab is available.' else abort ' -> GitLab unavailable!' end end |