diff options
Diffstat (limited to 'qa/qa/service/docker_run/gitlab_runner.rb')
-rw-r--r-- | qa/qa/service/docker_run/gitlab_runner.rb | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/qa/qa/service/docker_run/gitlab_runner.rb b/qa/qa/service/docker_run/gitlab_runner.rb index 6856a5a8399..834f6b430ac 100644 --- a/qa/qa/service/docker_run/gitlab_runner.rb +++ b/qa/qa/service/docker_run/gitlab_runner.rb @@ -6,14 +6,21 @@ module QA module Service module DockerRun class GitlabRunner < Base - attr_accessor :token, :address, :tags, :image, :run_untagged - attr_writer :config + attr_reader :tags + attr_accessor :token, :address, :image, :run_untagged + attr_writer :config, :executor, :executor_image + + CONFLICTING_VARIABLES_MESSAGE = <<~MSG + There are conflicting options preventing the runner from starting. + %s cannot be specified if %s is %s + MSG def initialize(name) @image = 'gitlab/gitlab-runner:alpine' @name = name || "qa-runner-#{SecureRandom.hex(4)}" - @tags = %w[qa test] - @run_untagged = false + @run_untagged = true + @executor = :shell + @executor_image = 'registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-qa-alpine-ruby-2.6' super() end @@ -32,23 +39,49 @@ module QA shell <<~CMD.tr("\n", ' ') docker run -d --rm --entrypoint=/bin/sh --network #{network} --name #{@name} - -p 8093:8093 - -e CI_SERVER_URL=#{@address} - -e REGISTER_NON_INTERACTIVE=true - -e REGISTRATION_TOKEN=#{@token} - -e RUNNER_EXECUTOR=shell - -e RUNNER_TAG_LIST=#{@tags.join(',')} - -e RUNNER_NAME=#{@name} + #{'-v /var/run/docker.sock:/var/run/docker.sock' if @executor == :docker} + --privileged #{@image} -c "#{register_command}" CMD end + def tags=(tags) + @tags = tags + @run_untagged = false + end + private def register_command - <<~CMD + args = [] + args << '--non-interactive' + args << "--name #{@name}" + args << "--url #{@address}" + args << "--registration-token #{@token}" + + args << if run_untagged + raise CONFLICTING_VARIABLES_MESSAGE % [:tags=, :run_untagged, run_untagged] if @tags&.any? + + '--run-untagged=true' + else + raise 'You must specify tags to run!' unless @tags&.any? + + "--tag-list #{@tags.join(',')}" + end + + args << "--executor #{@executor}" + + if @executor == :docker + args << "--docker-image #{@executor_image}" + args << '--docker-tlsverify=false' + args << '--docker-privileged=true' + args << "--docker-network-mode=#{network}" + end + + <<~CMD.strip printf '#{config.chomp.gsub(/\n/, "\\n").gsub('"', '\"')}' > /etc/gitlab-runner/config.toml && - gitlab-runner register --run-untagged=#{@run_untagged} && + gitlab-runner register \ + #{args.join(' ')} && gitlab-runner run CMD end |