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

CERTIFICATES_PATH =
File.expand_path('../../../../tls_certificates/gitlab'.freeze, __dir__)
SSL_PATH =
'/etc/gitlab/ssl'.freeze

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_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.



22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/qa/component/gitlab.rb', line 22

def initialize
  super

  @disable_animations = true
  @skip_availability_check = false

  @volumes[CERTIFICATES_PATH] = SSL_PATH

  self.release = 'CE'
end

Instance Attribute Details

#disable_animationsObject

Returns the value of attribute disable_animations.



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

def disable_animations
  @disable_animations
end

#nameObject



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

def name
  @name ||= "gitlab-#{edition}-#{SecureRandom.hex(4)}"
end

#relative_pathObject



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

def relative_path
  @relative_path ||= ''
end

#releaseObject

Returns the value of attribute release.



13
14
15
# File 'lib/gitlab/qa/component/gitlab.rb', line 13

def release
  @release
end

#runner_networkObject

Returns the value of attribute runner_network.



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

def runner_network
  @runner_network
end

#skip_availability_checkObject

Returns the value of attribute skip_availability_check.



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

def skip_availability_check
  @skip_availability_check
end

#tlsObject

Returns the value of attribute tls.



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

def tls
  @tls
end

Instance Method Details

#addressObject



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

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

#elastic_url=(url) ⇒ Object



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

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

#omnibus_config=(config) ⇒ Object



33
34
35
# File 'lib/gitlab/qa/component/gitlab.rb', line 33

def omnibus_config=(config)
  @environment['GITLAB_OMNIBUS_CONFIG'] = config.tr("\n", ' ')
end

#portObject



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

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

#prepareObject



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

def prepare
  prepare_gitlab_omnibus_config

  super
end

#prepare_gitlab_omnibus_configObject



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

def prepare_gitlab_omnibus_config
  setup_disable_animations if disable_animations
  
end

#pullObject



81
82
83
84
85
# File 'lib/gitlab/qa/component/gitlab.rb', line 81

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

  super
end

#reconfigureObject



122
123
124
125
126
127
128
129
# File 'lib/gitlab/qa/component/gitlab.rb', line 122

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

#schemeObject



59
60
61
# File 'lib/gitlab/qa/component/gitlab.rb', line 59

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

#set_accept_insecure_certsObject



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

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

#set_formless_login_tokenObject



37
38
39
40
41
# File 'lib/gitlab/qa/component/gitlab.rb', line 37

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

  @environment['GITLAB_OMNIBUS_CONFIG'] = "gitlab_rails['env'] = { 'GITLAB_QA_FORMLESS_LOGIN_TOKEN' => '#{Runtime::Env.gitlab_qa_formless_login_token}' }; #{@environment['GITLAB_OMNIBUS_CONFIG'] || ''}"
end

#setup_disable_animationsObject



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

def setup_disable_animations
  @environment['GITLAB_OMNIBUS_CONFIG'] = "gitlab_rails['gitlab_disable_animations'] = true; #{@environment['GITLAB_OMNIBUS_CONFIG'] || ''}"
end

#sha_versionObject



142
143
144
145
146
147
148
149
150
# File 'lib/gitlab/qa/component/gitlab.rb', line 142

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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/gitlab/qa/component/gitlab.rb', line 96

def start # rubocop:disable Metrics/AbcSize
  ensure_configured!

  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
  Docker::Command.execute("network connect --alias #{name}.#{network} --alias #{name}.#{runner_network} #{runner_network} #{name}") if runner_network
end

#waitObject



131
132
133
134
135
136
137
138
139
140
# File 'lib/gitlab/qa/component/gitlab.rb', line 131

def wait
  return if skip_availability_check

  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