<NME> qa.rake
<BEF> require 'docker'
require_relative '../docker_operations'
require_relative '../build/qa'
require_relative '../build/check'
require_relative '../build/info'
require_relative '../build/gitlab_image'
require_relative '../build/qa_image'
require_relative '../build/rat'
require_relative "../util.rb"
require 'json'

namespace :qa do
  desc "Build QA Docker image"
  task :build do
    DockerOperations.build(
      Build::QA.get_gitlab_repo,
      Build::QAImage.gitlab_registry_image_address,
      'latest'
    )
  end

      )
    end
  end

  namespace :push do
    # Only runs on dev.gitlab.org
    desc "Push unstable version of gitlab-{ce,ee}-qa to the GitLab registry"
    task :staging do
      Gitlab::Util.section('qa:push:staging') do
        Build::QAImage.tag_and_push_to_gitlab_registry(Build::Info.gitlab_version)
        Build::QAImage.tag_and_push_to_gitlab_registry(Build::Info.commit_sha)
      end
    end

    desc "Push stable version of gitlab-{ce,ee}-qa to the GitLab registry and Docker Hub"
    task :stable do
      Gitlab::Util.section('qa:push:stable') do
        # Allows to have gitlab/gitlab-{ce,ee}-qa:10.2.0-ee without the build number
        Build::QAImage.tag_and_push_to_gitlab_registry(Build::Info.gitlab_version)
        Build::QAImage.tag_and_push_to_dockerhub(Build::Info.gitlab_version, initial_tag: 'latest')
      end
    end

    desc "Push rc version of gitlab-{ce,ee}-qa to Docker Hub"
    task :rc do
      Gitlab::Util.section('qa:push:rc') do
        Build::QAImage.tag_and_push_to_dockerhub('rc', initial_tag: 'latest') if Build::Check.is_latest_tag?
      end
    end

    desc "Push nightly version of gitlab-{ce,ee}-qa to Docker Hub"
    task :nightly do
      Gitlab::Util.section('qa:push:nightly') do
        Build::QAImage.tag_and_push_to_dockerhub('nightly', initial_tag: 'latest') if Build::Check.is_nightly?
      end
    end

    desc "Push latest version of gitlab-{ce,ee}-qa to Docker Hub"
    task :latest do
      Gitlab::Util.section('qa:push:latest') do
        Build::QAImage.tag_and_push_to_dockerhub('latest', initial_tag: 'latest') if Build::Check.is_latest_stable_tag?
      end
    end
  end

  desc "Run QA letsencrypt tests"
  task :test_letsencrypt do
    Gitlab::Util.section('qa:test_letsencrypt') do
      Gitlab::Util.set_env_if_missing('CI_REGISTRY_IMAGE', 'registry.gitlab.com/gitlab-org/build/omnibus-gitlab-mirror')
      image_address = Build::GitlabImage.gitlab_registry_image_address(tag: Build::Info.docker_tag)
      Dir.chdir('letsencrypt-test') do
        system({ 'IMAGE' => image_address }, './test.sh')
      end
    end
  end

  namespace :rat do
    desc "Trigger a RAT pipeline"
    task :trigger do
      Gitlab::Util.section('qa:rat:validate') do
        Build::RAT::TriggerPipeline.invoke!.wait!(timeout: 3600 * 4)
      end
    end

    desc "Trigger a RAT pipeline using nightly package"
    task :nightly do
      Gitlab::Util.section('qa:rat:validate') do
        Build::RAT::NightlyPipeline.invoke!.wait!(timeout: 3600 * 4)
      end
    end

    desc "Trigger a RAT pipeline using tag package"
    task :tag do
      Gitlab::Util.section('qa:rat:validate') do
        Build::RAT::TagPipeline.invoke!.wait!(timeout: 3600 * 4)
      end
    end
  end
end

<MSG> Merge branch 'support-qa-backport-fix-remaining-prepend-lines' into 'master'

Update the qa:build task to be able to build from GitLab root context

See merge request gitlab-org/omnibus-gitlab!3496
<DFF> @@ -15,7 +15,8 @@ namespace :qa do
     DockerOperations.build(
       Build::QA.get_gitlab_repo,
       Build::QAImage.gitlab_registry_image_address,
-      'latest'
+      'latest',
+      dockerfile: 'qa/Dockerfile'
     )
   end
 

{'commit': 'diff --git a/lib/gitlab/build/qa.rb b/lib/gitlab/build/qa.rb\nindex 56b5c7532..3eabaa05a 100644\n--- a/lib/gitlab/build/qa.rb\n+++ b/lib/gitlab/build/qa.rb\n@@ -8,13 +8,14 @@ require \'English\'\n module Build\n   class QA\n     def self.repo_path\n-      "/tmp/gitlab"\n+      File.absolute_path("/tmp/gitlab")\n     end\n \n     def self.get_gitlab_repo\n       clone_gitlab_rails\n       checkout_gitlab_rails\n-      File.absolute_path("#{repo_path}/qa")\n+\n+      repo_path\n     end\n \n     def self.clone_gitlab_rails\ndiff --git a/lib/gitlab/docker_operations.rb b/lib/gitlab/docker_operations.rb\nindex 404cbf4b3..0ac6c86e2 100644\n--- a/lib/gitlab/docker_operations.rb\n+++ b/lib/gitlab/docker_operations.rb\n@@ -8,9 +8,12 @@ class DockerOperations\n     Docker.options = { read_timeout: timeout, write_timeout: timeout }\n   end\n \n-  def self.build(location, image, tag)\n+  def self.build(location, image, tag, dockerfile: nil)\n     set_timeout\n-    Docker::Image.build_from_dir(location.to_s, { t: "#{image}:#{tag}", pull: true }) do |chunk|\n+    opts = { t: "#{image}:#{tag}", pull: true }\n+    opts[:dockerfile] = dockerfile if dockerfile\n+\n+    Docker::Image.build_from_dir(location.to_s, opts) do |chunk|\n       if (log = JSON.parse(chunk)) && log.key?("stream")\n         puts log["stream"]\n       end\ndiff --git a/lib/gitlab/tasks/qa.rake b/lib/gitlab/tasks/qa.rake\nindex 26b2fbfc6..765545798 100644\n--- a/lib/gitlab/tasks/qa.rake\n+++ b/lib/gitlab/tasks/qa.rake\n@@ -15,7 +15,8 @@ namespace :qa do\n     DockerOperations.build(\n       Build::QA.get_gitlab_repo,\n       Build::QAImage.gitlab_registry_image_address,\n-      \'latest\'\n+      \'latest\',\n+      dockerfile: \'qa/Dockerfile\'\n     )\n   end\n \ndiff --git a/spec/gitlab/build/qa_spec.rb b/spec/gitlab/build/qa_spec.rb\nindex 7a698d8d6..25f9d3e3a 100644\n--- a/spec/gitlab/build/qa_spec.rb\n+++ b/spec/gitlab/build/qa_spec.rb\n@@ -13,7 +13,7 @@ describe Build::QA do\n       allow(Build::QA).to receive(:clone_gitlab_rails).and_return(true)\n       allow(Build::QA).to receive(:checkout_gitlab_rails).and_return(true)\n \n-      expect(described_class.get_gitlab_repo).to eq("/tmp/gitlab/qa")\n+      expect(described_class.get_gitlab_repo).to eq("/tmp/gitlab")\n     end\n   end\n \ndiff --git a/spec/gitlab/tasks/qa_spec.rb b/spec/gitlab/tasks/qa_spec.rb\nindex 1163ef83a..eacfc6c68 100644\n--- a/spec/gitlab/tasks/qa_spec.rb\n+++ b/spec/gitlab/tasks/qa_spec.rb\n@@ -11,16 +11,18 @@ describe \'qa\', type: :rake do\n   end\n \n   describe \'qa:build\' do\n+    let(:repo_path) { "/tmp/gitlab" }\n     before do\n       Rake::Task[\'qa:build\'].reenable\n \n-      allow(Build::QA).to receive(:get_gitlab_repo).and_return("/tmp/gitlab.1234/qa")\n+      allow(Build::QA).to receive(:get_gitlab_repo).and_return(repo_path)\n+      allow(Build::QA).to receive(:gitlab_repo).and_return(repo_path)\n       allow(Build::QAImage).to receive(:gitlab_registry_image_address).and_return(gitlab_registry_image_address)\n       allow(JSON).to receive(:parse).and_return(version_manifest)\n     end\n \n     it \'calls build method with correct parameters\' do\n-      expect(DockerOperations).to receive(:build).with(\'/tmp/gitlab.1234/qa\', \'dev.gitlab.org:5005/gitlab/omnibus-gitlab/gitlab-ce-qa\', \'latest\')\n+      expect(DockerOperations).to receive(:build).with(repo_path, \'dev.gitlab.org:5005/gitlab/omnibus-gitlab/gitlab-ce-qa\', \'latest\', dockerfile: "qa/Dockerfile")\n \n       Rake::Task[\'qa:build\'].invoke\n     end\n', 'commit_subject': "Merge branch 'support-qa-backport-fix-remaining-prepend-lines' into 'master'", 'repo_name': 'gitlabhq/omnibus-gitlab', 'committer': {'name': 'Balasankar "Balu" C', 'email': '250a398eb3bfb9862062144cc742cc8f9bdd8d78@gitlab.com', 'time_sec': '1566222672', 'tz_offset': '0', 'date': {'seconds': '1566222672'}}, 'commit_tree': 'b8dce0dbfd6e7b6b89dbc6a8a93cd341af078184', 'commit_message': "Merge branch 'support-qa-backport-fix-remaining-prepend-lines' into 'master'\n\nUpdate the qa:build task to be able to build from GitLab root context\n\nSee merge request gitlab-org/omnibus-gitlab!3496", 'language_name': 'Ruby', 'license': 'apache-2.0', 'hunks': "@@ -15,7 +15,8 @@ namespace :qa do\n     DockerOperations.build(\n       Build::QA.get_gitlab_repo,\n       Build::QAImage.gitlab_registry_image_address,\n-      'latest'\n+      'latest',\n+      dockerfile: 'qa/Dockerfile'\n     )\n   end\n \n", 'addition_count': 2, 'deletion_count': 1, 'src_file': 'a/lib/gitlab/tasks/qa.rake', 'tgt_file': 'b/lib/gitlab/tasks/qa.rake', 'file_extension': '.rake', 'before_file': 'require \'docker\'\nrequire_relative \'../docker_operations\'\nrequire_relative \'../build/qa\'\nrequire_relative \'../build/check\'\nrequire_relative \'../build/info\'\nrequire_relative \'../build/gitlab_image\'\nrequire_relative \'../build/qa_image\'\nrequire_relative \'../build/rat\'\nrequire_relative "../util.rb"\nrequire \'json\'\n\nnamespace :qa do\n  desc "Build QA Docker image"\n  task :build do\n    DockerOperations.build(\n      Build::QA.get_gitlab_repo,\n      Build::QAImage.gitlab_registry_image_address,\n      \'latest\'\n    )\n  end\n\n      )\n    end\n  end\n\n  namespace :push do\n    # Only runs on dev.gitlab.org\n    desc "Push unstable version of gitlab-{ce,ee}-qa to the GitLab registry"\n    task :staging do\n      Gitlab::Util.section(\'qa:push:staging\') do\n        Build::QAImage.tag_and_push_to_gitlab_registry(Build::Info.gitlab_version)\n        Build::QAImage.tag_and_push_to_gitlab_registry(Build::Info.commit_sha)\n      end\n    end\n\n    desc "Push stable version of gitlab-{ce,ee}-qa to the GitLab registry and Docker Hub"\n    task :stable do\n      Gitlab::Util.section(\'qa:push:stable\') do\n        # Allows to have gitlab/gitlab-{ce,ee}-qa:10.2.0-ee without the build number\n        Build::QAImage.tag_and_push_to_gitlab_registry(Build::Info.gitlab_version)\n        Build::QAImage.tag_and_push_to_dockerhub(Build::Info.gitlab_version, initial_tag: \'latest\')\n      end\n    end\n\n    desc "Push rc version of gitlab-{ce,ee}-qa to Docker Hub"\n    task :rc do\n      Gitlab::Util.section(\'qa:push:rc\') do\n        Build::QAImage.tag_and_push_to_dockerhub(\'rc\', initial_tag: \'latest\') if Build::Check.is_latest_tag?\n      end\n    end\n\n    desc "Push nightly version of gitlab-{ce,ee}-qa to Docker Hub"\n    task :nightly do\n      Gitlab::Util.section(\'qa:push:nightly\') do\n        Build::QAImage.tag_and_push_to_dockerhub(\'nightly\', initial_tag: \'latest\') if Build::Check.is_nightly?\n      end\n    end\n\n    desc "Push latest version of gitlab-{ce,ee}-qa to Docker Hub"\n    task :latest do\n      Gitlab::Util.section(\'qa:push:latest\') do\n        Build::QAImage.tag_and_push_to_dockerhub(\'latest\', initial_tag: \'latest\') if Build::Check.is_latest_stable_tag?\n      end\n    end\n  end\n\n  desc "Run QA letsencrypt tests"\n  task :test_letsencrypt do\n    Gitlab::Util.section(\'qa:test_letsencrypt\') do\n      Gitlab::Util.set_env_if_missing(\'CI_REGISTRY_IMAGE\', \'registry.gitlab.com/gitlab-org/build/omnibus-gitlab-mirror\')\n      image_address = Build::GitlabImage.gitlab_registry_image_address(tag: Build::Info.docker_tag)\n      Dir.chdir(\'letsencrypt-test\') do\n        system({ \'IMAGE\' => image_address }, \'./test.sh\')\n      end\n    end\n  end\n\n  namespace :rat do\n    desc "Trigger a RAT pipeline"\n    task :trigger do\n      Gitlab::Util.section(\'qa:rat:validate\') do\n        Build::RAT::TriggerPipeline.invoke!.wait!(timeout: 3600 * 4)\n      end\n    end\n\n    desc "Trigger a RAT pipeline using nightly package"\n    task :nightly do\n      Gitlab::Util.section(\'qa:rat:validate\') do\n        Build::RAT::NightlyPipeline.invoke!.wait!(timeout: 3600 * 4)\n      end\n    end\n\n    desc "Trigger a RAT pipeline using tag package"\n    task :tag do\n      Gitlab::Util.section(\'qa:rat:validate\') do\n        Build::RAT::TagPipeline.invoke!.wait!(timeout: 3600 * 4)\n      end\n    end\n  end\nend\n', 'message': "Merge branch 'support-qa-backport-fix-remaining-prepend-lines' into 'master'\n\nUpdate the qa:build task to be able to build from GitLab root context\n\nSee merge request gitlab-org/omnibus-gitlab!3496", 'author_name': 'Balasankar "Balu" C', 'lang': 'rake'}