diff --git a/.gitlab/ci/test-on-cng/main.gitlab-ci.yml b/.gitlab/ci/test-on-cng/main.gitlab-ci.yml index ea7004b73ff226c4a042ebc3add06817ced12bfa..cea2bd3fef6551016ccb1181d67078ed26eede8b 100644 --- a/.gitlab/ci/test-on-cng/main.gitlab-ci.yml +++ b/.gitlab/ci/test-on-cng/main.gitlab-ci.yml @@ -46,13 +46,15 @@ workflow: QA_DISABLE_RSPEC_RETRY: "true" before_script: - echo "SUITE_RAN=true" > "$QA_SUITE_STATUS_ENV_FILE" + # save extra values to be available for after_script if created dynamically + - echo "${EXTRA_DEPLOY_VALUES}" > $CI_PROJECT_DIR/EXTRA_DEPLOY_VALUES - export GITLAB_DOMAIN="$(getent hosts docker | awk '{ print $1 }' | head -n1).nip.io" - export QA_GITLAB_URL="http://gitlab.${GITLAB_DOMAIN}" - source scripts/utils.sh - source scripts/rspec_helpers.sh - cd qa && bundle install - | - bundle exec cng create deployment kind \ + bundle exec cng create deployment "${DEPLOYMENT_TYPE}" \ --gitlab-domain "${GITLAB_DOMAIN}" \ --timeout 5m \ --admin-password "${GITLAB_ADMIN_PASSWORD}" \ @@ -73,6 +75,13 @@ workflow: - cd qa - bundle exec cng log events --save - bundle exec cng log pods --save --containers all + # This command prints all the necessary arguments to be able to recreate the same deployment as on CI + - | + bundle exec cng create deployment "${DEPLOYMENT_TYPE}" \ + --chart-sha "${GITLAB_HELM_CHART_REF}" \ + --ci \ + --print-deploy-args \ + $(cat $CI_PROJECT_DIR/EXTRA_DEPLOY_VALUES) artifacts: expire_in: 1 day when: always @@ -115,6 +124,7 @@ cng-instance: extends: .cng-base variables: QA_SCENARIO: Test::Instance::All + DEPLOYMENT_TYPE: kind parallel: 5 allow_failure: true @@ -123,6 +133,7 @@ cng-qa-min-redis-version: extends: .cng-base variables: QA_SCENARIO: Test::Instance::Smoke + DEPLOYMENT_TYPE: kind before_script: - | redis_version=$(awk -F "=" "/MIN_REDIS_VERSION =/ {print \$2}" $CI_PROJECT_DIR/lib/system_check/app/redis_version_check.rb | sed "s/['\" ]//g") diff --git a/gems/gitlab-cng/lib/gitlab/cng/commands/subcommands/deployment.rb b/gems/gitlab-cng/lib/gitlab/cng/commands/subcommands/deployment.rb index 6f268a1d5439e40936376a2860a85aba5676a6f4..ec141c2a0c6a2ef237fc541ed23bbf599585ce05 100644 --- a/gems/gitlab-cng/lib/gitlab/cng/commands/subcommands/deployment.rb +++ b/gems/gitlab-cng/lib/gitlab/cng/commands/subcommands/deployment.rb @@ -74,7 +74,14 @@ def method_added(name) desc: "Host ssh port for gitlab", type: :numeric, default: 22 + option :print_deploy_args, + desc: "Print all CI specific component helm values and deployment arguments." \ + "Useful for reproducing CI deployments. Only valid with --ci flag.", + type: :boolean, + default: false def kind(name = "gitlab") + return print_deploy_args("kind") if options[:print_deploy_args] && options[:ci] + if options[:create_cluster] invoke(Commands::Create, :cluster, [], **symbolized_options.slice( :docker_hostname, :ci, :host_http_port, :host_ssh_port @@ -108,6 +115,23 @@ def installation(name, configuration) ) end + # Print example of deployment arguments and all CI component arguments + # + # @param [String] configuration deployment configuration name + # @return [void] + def print_deploy_args(configuration) + ci_components = Cng::Deployment::DefaultValues.component_ci_versions.flat_map do |component, version| + ["--set", "#{component}=#{version}"] + end + cmd = ["cng", "create", "deployment", configuration, *ci_components] + cmd.push(*options[:set].flat_map { |opt| ["--set", opt] }) if options[:set] + cmd.push("--chart-sha", options[:chart_sha]) if options[:chart_sha] + + log("Received --print-deploy-args option, printing example of all deployment arguments!", :warn) + log("To reproduce CI deployment, run cng with following arguments:") + log(" #{cmd.join(' ')}") + end + # Populate options with default gitlab domain if missing # # @return [Hash] diff --git a/gems/gitlab-cng/spec/unit/gitlab/cng/commands/subcommands/deployment_spec.rb b/gems/gitlab-cng/spec/unit/gitlab/cng/commands/subcommands/deployment_spec.rb index ee38785f279c83bdc3bf11b1b705113a81bdb781..ceaef43005e7ef75274def9bc450dfb97d34c8e0 100644 --- a/gems/gitlab-cng/spec/unit/gitlab/cng/commands/subcommands/deployment_spec.rb +++ b/gems/gitlab-cng/spec/unit/gitlab/cng/commands/subcommands/deployment_spec.rb @@ -10,11 +10,18 @@ let(:configuration_instance) { instance_double(Gitlab::Cng::Deployment::Configurations::Kind) } let(:cluster_instance) { instance_double(Gitlab::Cng::Kind::Cluster, create: nil) } let(:ip) { instance_double(Addrinfo, ipv4_private?: true, ip_address: "127.0.0.1") } + let(:ci_components) do + { + "gitlab.gitaly.image.repository" => "cng-mirror/gitaly", + "gitlab.gitaly.image.tag" => "1fb4c252c713f33db2102315870c1936769319ac" + } + end before do allow(Gitlab::Cng::Deployment::Installation).to receive(:new).and_return(installation_instance) allow(Gitlab::Cng::Deployment::Configurations::Kind).to receive(:new).and_return(configuration_instance) allow(Gitlab::Cng::Kind::Cluster).to receive(:new).and_return(cluster_instance) + allow(Gitlab::Cng::Deployment::DefaultValues).to receive(:component_ci_versions).and_return(ci_components) allow(Socket).to receive(:ip_address_list).and_return([ip]) end @@ -62,5 +69,31 @@ .with(name: "gitlab", ci: true, host_http_port: 80, host_ssh_port: 22) expect(cluster_instance).to have_received(:create) end + + it "only print arguments with --print-deploy-args option" do + chart_sha = "356a1ab41be2" + extra_opt = "opt=val" + args = [ + *ci_components.map { |c, v| "--set #{c}=#{v}" }.join(' '), + "--set", extra_opt, + "--chart-sha", chart_sha + ] + + expect do + invoke_command(command_name, [], { + ci: true, + print_deploy_args: true, + chart_sha: chart_sha, + set: [extra_opt] + }) + end.to output( + match(/Received --print-deploy-args option, printing example of all deployment arguments!/).and( + match(/cng create deployment kind #{args.join(' ')}/) + ) + ).to_stdout + + expect(cluster_instance).not_to have_received(:create) + expect(installation_instance).not_to have_received(:create) + end end end