class Gitlab::QA::Component::Gitlab

Constants

AUTHORITY_CERTIFICATES_PATH
GITALY_CERTIFICATES_PATH
GITLAB_CERTIFICATES_PATH
SSL_PATH
TRUSTED_PATH

Attributes

name[W]
omnibus_configuration[R]
relative_path[W]
release[R]
runner_network[RW]
skip_availability_check[RW]
tls[RW]

Public Class Methods

new() click to toggle source
Calls superclass method Gitlab::QA::Component::Base::new
# File lib/gitlab/qa/component/gitlab.rb, line 28
def initialize
  super

  @skip_availability_check = false

  @volumes[GITLAB_CERTIFICATES_PATH] = SSL_PATH
  @volumes[AUTHORITY_CERTIFICATES_PATH] = TRUSTED_PATH

  @omnibus_configuration ||= Runtime::OmnibusConfiguration.new(Runtime::Scenario.omnibus_configuration)

  self.release = 'CE'
end

Public Instance Methods

address() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 59
def address
  "#{scheme}://#{hostname}#{relative_path}"
end
elastic_url=(url) click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 47
def elastic_url=(url)
  @environment['ELASTIC_URL'] = url
end
gitaly_tls() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 71
def gitaly_tls
  @volumes.delete(GITLAB_CERTIFICATES_PATH)
  @volumes[GITALY_CERTIFICATES_PATH] = SSL_PATH
end
name() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 55
def name
  @name ||= "gitlab-#{edition}-#{SecureRandom.hex(4)}"
end
port() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 67
def port
  tls ? '443:443' : '80'
end
prepare() click to toggle source
Calls superclass method Gitlab::QA::Component::Base#prepare
# File lib/gitlab/qa/component/gitlab.rb, line 84
def prepare
  prepare_gitlab_omnibus_config

  super
end
prepare_gitlab_omnibus_config() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 96
def prepare_gitlab_omnibus_config
  set_formless_login_token
end
pull() click to toggle source
Calls superclass method Gitlab::QA::Component::Base#pull
# File lib/gitlab/qa/component/gitlab.rb, line 90
def pull
  docker.login(**release.login_params) if release.login_params

  super
end
reconfigure() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 126
def reconfigure
  setup_omnibus

  @docker.attach(name) do |line, wait|
    puts line
    # TODO, workaround which allows to detach from the container
    #
    break if line =~ /gitlab Reconfigured!/
  end
end
relative_path() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 76
def relative_path
  @relative_path ||= ''
end
release=(release) click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 51
def release=(release)
  @release = QA::Release.new(release)
end
scheme() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 63
def scheme
  tls ? 'https' : 'http'
end
set_accept_insecure_certs() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 80
def set_accept_insecure_certs
  Runtime::Env.accept_insecure_certs = 'true'
end
set_formless_login_token() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 41
def set_formless_login_token
  return if Runtime::Env.gitlab_qa_formless_login_token.to_s.strip.empty?

  @omnibus_configuration << "gitlab_rails['env'] = { 'GITLAB_QA_FORMLESS_LOGIN_TOKEN' => '#{Runtime::Env.gitlab_qa_formless_login_token}' }"
end
sha_version() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 148
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() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 100
def start # rubocop:disable Metrics/AbcSize
  ensure_configured!

  docker.run(image: image, tag: 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
wait_until_ready() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 137
def wait_until_ready
  return if skip_availability_check

  if Availability.new(name, relative_path: relative_path, scheme: scheme, protocol_port: port.to_i).check(Runtime::Env.gitlab_availability_timeout)
    sleep 12 # TODO, handle that better
    puts ' -> GitLab is available.'
  else
    abort ' -> GitLab unavailable!'
  end
end

Private Instance Methods

ensure_configured!() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 160
def ensure_configured!
  raise 'Please configure an instance first!' unless [name, release, network].all?
end
setup_omnibus() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 164
def setup_omnibus
  @docker.write_files(name) do |f|
    f.write('/etc/gitlab/gitlab.rb', @omnibus_configuration.to_s)
  end
end