Class: Gitlab::QA::Component::Specs

Inherits:
Scenario::Template show all
Defined in:
lib/gitlab/qa/component/specs.rb

Overview

This class represents GitLab QA specs image that is implemented in the ‘qa/` directory located in GitLab CE / EE repositories.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Scenario::Template

perform

Constructor Details

#initializeSpecs

Returns a new instance of Specs.



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

def initialize
  @docker = Docker::Engine.new
  @volumes = {}
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



11
12
13
# File 'lib/gitlab/qa/component/specs.rb', line 11

def args
  @args
end

#networkObject

Returns the value of attribute network.



11
12
13
# File 'lib/gitlab/qa/component/specs.rb', line 11

def network
  @network
end

#releaseObject

Returns the value of attribute release.



11
12
13
# File 'lib/gitlab/qa/component/specs.rb', line 11

def release
  @release
end

#suiteObject

Returns the value of attribute suite.



11
12
13
# File 'lib/gitlab/qa/component/specs.rb', line 11

def suite
  @suite
end

#volumesObject

Returns the value of attribute volumes.



11
12
13
# File 'lib/gitlab/qa/component/specs.rb', line 11

def volumes
  @volumes
end

Instance Method Details

#performObject

rubocop:disable Metrics/AbcSize

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gitlab/qa/component/specs.rb', line 18

def perform # rubocop:disable Metrics/AbcSize
  raise ArgumentError unless [suite, release].all?

  if release.dev_gitlab_org?
    Docker::Command.execute(
      [
        'login',
        '--username gitlab-qa-bot',
        %(--password "#{Runtime::Env.dev_access_token_variable}"),
        Release::DEV_REGISTRY
      ]
    )
  end

  puts "Running test suite `#{suite}` for #{release.project_name}"

  name = "#{release.project_name}-qa-#{SecureRandom.hex(4)}"

  @docker.run(release.qa_image, release.qa_tag, suite, *args) do |command|
    command << "-t --rm --net=#{network || 'bridge'}"

    Runtime::Env.variables.each do |key, value|
      command.env(key, value)
    end

    command.volume('/var/run/docker.sock', '/var/run/docker.sock')
    command.volume(File.join(Runtime::Env.host_artifacts_dir, name), File.join(Docker::Volumes::QA_CONTAINER_WORKDIR, 'tmp'))

    @volumes.to_h.each do |to, from|
      command.volume(to, from)
    end

    command.name(name)
  end
end