diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 90dee4499a11f8db0034f041563ec963a662f45e..51e663e84ccc790d5b42bc6e75df0aa8f9dcb00a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -244,7 +244,6 @@ variables: DECOMPOSED_DB: "true" SEC_DECOMPOSED_DB: "true" - DOCS_REVIEW_APPS_DOMAIN: "docs.gitlab-review.app" DOCS_GITLAB_REPO_SUFFIX: "ee" REVIEW_APPS_IMAGE: "${REGISTRY_HOST}/${REGISTRY_GROUP}/gitlab-build-images/${BUILD_OS}-${OS_VERSION}-ruby-${RUBY_VERSION}:gcloud-${GCLOUD_VERSION}-kubectl-1.30-helm-${HELM_VERSION}" diff --git a/.gitlab/ci/docs.gitlab-ci.yml b/.gitlab/ci/docs.gitlab-ci.yml index ece0cf468f29f4fc64caddc4cebed15f6f4730bb..7aae03bb145c488d1befeb14b393a5e701233db7 100644 --- a/.gitlab/ci/docs.gitlab-ci.yml +++ b/.gitlab/ci/docs.gitlab-ci.yml @@ -22,7 +22,7 @@ review-docs-deploy: extends: .review-docs script: - - ./scripts/trigger-build.rb docs-hugo deploy + - ./scripts/trigger-build.rb docs deploy # Cleanup remote environment of gitlab-org/technical-writing/docs-gitlab-com review-docs-cleanup: @@ -31,7 +31,7 @@ review-docs-cleanup: name: review-docs/mr-${CI_MERGE_REQUEST_IID} action: stop script: - - ./scripts/trigger-build.rb docs-hugo cleanup + - ./scripts/trigger-build.rb docs cleanup .docs-markdown-lint-image: # When updating the image version here, update it in /scripts/lint-doc.sh too. diff --git a/doc/ci/runners/long_polling.md b/doc/ci/runners/long_polling.md index 06cbccde412cd4759eb3e54b839b5c91ee325528..ce663f15778de673fe34b36a11db6dfefc07b5f5 100644 --- a/doc/ci/runners/long_polling.md +++ b/doc/ci/runners/long_polling.md @@ -15,7 +15,7 @@ title: Long polling By default, a GitLab Runner polls a GitLab instance for new CI/CD jobs periodically. The actual polling interval [depends on the `check_interval` and number of runners configured in the runner configuration file](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#how-check_interval-works). -On a server that handles many runners, this polling can lead to a number of performance issues: +On a server that handles many runners, this polling can lead to these performance issues: - Longer queuing times. - Higher CPU usage on the GitLab instance. diff --git a/scripts/trigger-build.rb b/scripts/trigger-build.rb index 38edfe8185c69910c497fc2f681ce87a345dcd89..669272f94797ea33d7bac7d0c9937c1299de0ac8 100755 --- a/scripts/trigger-build.rb +++ b/scripts/trigger-build.rb @@ -240,11 +240,7 @@ def version_param_value(_version_file) end end - # This is used in: - # - https://gitlab.com/gitlab-org/gitlab-runner/-/blob/ddaf90761c917a42ed4aab60541b6bc33871fe68/.gitlab/ci/docs.gitlab-ci.yml#L1-47 - # - https://gitlab.com/gitlab-org/charts/gitlab/-/blob/fa348e709e901196803051669b4874b657b4ea91/.gitlab-ci.yml#L497-543 - # - https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/b44483f05c5e22628ba3b49ec4c7f8761c688af0/gitlab-ci-config/gitlab-com.yml#L199-224 - # - https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/b44483f05c5e22628ba3b49ec4c7f8761c688af0/gitlab-ci-config/gitlab-com.yml#L356-380 + # For GitLab documentation review apps class Docs < Base def access_token ENV['DOCS_PROJECT_API_TOKEN'] || super @@ -284,26 +280,23 @@ def cleanup! private def downstream_environment - "review/#{ref}#{review_slug}" + "upstream-review/mr-${CI_MERGE_REQUEST_IID}" end - # We prepend the `-` here because we cannot use variable substitution in `environment.name`/`environment.url` - # Some projects (e.g. `omnibus-gitlab`) use this script for branch pipelines, so we fallback to using `CI_COMMIT_REF_SLUG` for those cases. def review_slug identifier = ENV['CI_MERGE_REQUEST_IID'] || ENV['CI_COMMIT_REF_SLUG'] - "-#{project_slug}-#{identifier}" + "#{project_slug}-#{identifier}" end def downstream_project_path - ENV.fetch('DOCS_PROJECT_PATH', 'gitlab-org/gitlab-docs') + ENV.fetch('DOCS_PROJECT_PATH', 'gitlab-org/technical-writing/docs-gitlab-com') end def ref_param_name 'DOCS_BRANCH' end - # `gitlab-org/gitlab-docs` pipeline trigger "Triggered from gitlab-org/gitlab 'review-docs-deploy' job" def trigger_token ENV['DOCS_TRIGGER_TOKEN'] end @@ -333,10 +326,8 @@ def project_slug end end - # app_url is the URL of the `gitlab-docs` Review App URL defined in - # https://gitlab.com/gitlab-org/gitlab-docs/-/blob/b38038132cf82a24271bbb294dead7c2f529e275/.gitlab-ci.yml#L383 def app_url - "http://#{ref}#{review_slug}.#{ENV['DOCS_REVIEW_APPS_DOMAIN']}/#{project_slug}" + "https://docs.gitlab.com/upstream-review-mr-#{review_slug}/" end def display_success_message @@ -344,35 +335,12 @@ def display_success_message end end - class DocsHugo < Docs - def access_token - ENV['DOCS_HUGO_PROJECT_API_TOKEN'] || super - end - - private - - def downstream_environment - "upstream-review/mr-${CI_MERGE_REQUEST_IID}" - end - - def review_slug - identifier = ENV['CI_MERGE_REQUEST_IID'] || ENV['CI_COMMIT_REF_SLUG'] - - "#{project_slug}-#{identifier}" - end - - def downstream_project_path - ENV.fetch('DOCS_PROJECT_PATH', 'gitlab-org/technical-writing/docs-gitlab-com') - end - - def trigger_token - ENV['DOCS_HUGO_TRIGGER_TOKEN'] - end - - def app_url - "https://new.docs.gitlab.com/upstream-review-mr-#{review_slug}/" - end - end + # Alias DocsHugo to Docs until callers to DocsHugo are updated: + # - https://gitlab.com/gitlab-org/gitlab-runner/-/blob/d1bee4412f473208d5c96a6a40103e7198a04e69/.gitlab/ci/docs.gitlab-ci.yml + # - https://gitlab.com/gitlab-org/charts/gitlab/-/blob/7eeea87621ed4661b66d4fd1c561bab3a53baecf/.gitlab-ci.yml + # - https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/4732915e79f16465ff5a669540b36d29dca22028/gitlab-ci-config/gitlab-com.yml + # - https://gitlab.com/gitlab-org/cloud-native/gitlab-operator/-/blob/b254c9982dd2c26cdf70e038a033600a28007c68/.gitlab-ci.yml + DocsHugo = Docs class DatabaseTesting < Base IDENTIFIABLE_NOTE_TAG = 'gitlab-org/database-team/gitlab-com-database-testing:identifiable-note' diff --git a/spec/scripts/trigger-build_spec.rb b/spec/scripts/trigger-build_spec.rb index b763512dbae9d09d35ac560058e0e0f76b8f8995..76276fd41dda5a3b87e3801a454ba58d7f15e6b3 100644 --- a/spec/scripts/trigger-build_spec.rb +++ b/spec/scripts/trigger-build_spec.rb @@ -21,8 +21,7 @@ 'GITLAB_USER_NAME' => 'gitlab_user_name', 'GITLAB_USER_LOGIN' => 'gitlab_user_login', 'QA_IMAGE' => 'qa_image', - 'DOCS_PROJECT_API_TOKEN' => nil, - 'DOCS_HUGO_PROJECT_API_TOKEN' => nil + 'DOCS_PROJECT_API_TOKEN' => nil } end @@ -463,210 +462,6 @@ def ref_param_name end describe Trigger::Docs do - let(:downstream_project_path) { 'gitlab-org/gitlab-docs' } - - describe '#variables' do - describe "BRANCH_CE" do - before do - stub_env('CI_PROJECT_PATH', 'gitlab-org/gitlab-foss') - end - - context 'when CI_PROJECT_PATH is gitlab-org/gitlab-foss' do - it 'sets BRANCH_CE to CI_COMMIT_REF_NAME' do - expect(subject.variables['BRANCH_CE']).to eq(env['CI_COMMIT_REF_NAME']) - end - end - end - - describe "BRANCH_EE" do - before do - stub_env('CI_PROJECT_PATH', 'gitlab-org/gitlab') - end - - context 'when CI_PROJECT_PATH is gitlab-org/gitlab' do - it 'sets BRANCH_EE to CI_COMMIT_REF_NAME' do - expect(subject.variables['BRANCH_EE']).to eq(env['CI_COMMIT_REF_NAME']) - end - end - end - - describe "BRANCH_RUNNER" do - before do - stub_env('CI_PROJECT_PATH', 'gitlab-org/gitlab-runner') - end - - context 'when CI_PROJECT_PATH is gitlab-org/gitlab-runner' do - it 'sets BRANCH_RUNNER to CI_COMMIT_REF_NAME' do - expect(subject.variables['BRANCH_RUNNER']).to eq(env['CI_COMMIT_REF_NAME']) - end - end - end - - describe "BRANCH_OMNIBUS" do - before do - stub_env('CI_PROJECT_PATH', 'gitlab-org/omnibus-gitlab') - end - - context 'when CI_PROJECT_PATH is gitlab-org/omnibus-gitlab' do - it 'sets BRANCH_OMNIBUS to CI_COMMIT_REF_NAME' do - expect(subject.variables['BRANCH_OMNIBUS']).to eq(env['CI_COMMIT_REF_NAME']) - end - end - end - - describe "BRANCH_CHARTS" do - before do - stub_env('CI_PROJECT_PATH', 'gitlab-org/charts/gitlab') - end - - context 'when CI_PROJECT_PATH is gitlab-org/charts/gitlab' do - it 'sets BRANCH_CHARTS to CI_COMMIT_REF_NAME' do - expect(subject.variables['BRANCH_CHARTS']).to eq(env['CI_COMMIT_REF_NAME']) - end - end - end - - describe "BRANCH_OPERATOR" do - before do - stub_env('CI_PROJECT_PATH', 'gitlab-org/cloud-native/gitlab-operator') - end - - context 'when CI_PROJECT_PATH is gitlab-org/cloud-native/gitlab-operator' do - it 'sets BRANCH_OPERATOR to CI_COMMIT_REF_NAME' do - expect(subject.variables['BRANCH_OPERATOR']).to eq(env['CI_COMMIT_REF_NAME']) - end - end - end - - describe "REVIEW_SLUG" do - before do - stub_env('CI_PROJECT_PATH', 'gitlab-org/gitlab-foss') - end - - context 'when CI_MERGE_REQUEST_IID is set' do - it 'sets REVIEW_SLUG' do - expect(subject.variables['REVIEW_SLUG']).to eq("-ce-#{env['CI_MERGE_REQUEST_IID']}") - end - end - - context 'when CI_MERGE_REQUEST_IID is not set' do - before do - stub_env('CI_MERGE_REQUEST_IID', nil) - end - - it 'sets REVIEW_SLUG' do - expect(subject.variables['REVIEW_SLUG']).to eq("-ce-#{env['CI_COMMIT_REF_SLUG']}") - end - end - end - end - - describe '.access_token' do - context 'when DOCS_PROJECT_API_TOKEN is set' do - let(:docs_project_api_token) { 'docs_project_api_token' } - - before do - stub_env('DOCS_PROJECT_API_TOKEN', docs_project_api_token) - end - - it 'returns the docs-specific access token' do - expect(subject.access_token).to eq(docs_project_api_token) - end - end - - context 'when DOCS_PROJECT_API_TOKEN is not set' do - before do - stub_env('DOCS_PROJECT_API_TOKEN', nil) - end - - it 'returns the default access token' do - expect(subject.access_token).to eq(Trigger::Base.new.access_token) - end - end - end - - describe '#invoke!' do - let(:trigger_token) { 'docs_trigger_token' } - let(:ref) { 'main' } - - let(:env) do - super().merge( - 'CI_PROJECT_PATH' => 'gitlab-org/gitlab-foss', - 'DOCS_TRIGGER_TOKEN' => trigger_token - ) - end - - describe '#downstream_project_path' do - context 'when DOCS_PROJECT_PATH is set' do - let(:downstream_project_path) { 'docs_project_path' } - - before do - stub_env('DOCS_PROJECT_PATH', downstream_project_path) - end - - it 'triggers the pipeline on the correct project' do - expect_run_trigger_with_params - - subject.invoke! - end - end - end - - describe '#ref' do - context 'when DOCS_BRANCH is set' do - let(:ref) { 'docs_branch' } - - before do - stub_env('DOCS_BRANCH', ref) - end - - it 'triggers the pipeline on the correct ref' do - expect_run_trigger_with_params - - subject.invoke! - end - end - end - end - - describe '#cleanup!' do - let(:downstream_environment_response) { double('downstream_environment', id: 42) } - let(:downstream_environments_response) { [downstream_environment_response] } - - before do - expect(com_gitlab_client).to receive(:environments) - .with(downstream_project_path, name: subject.__send__(:downstream_environment)) - .and_return(downstream_environments_response) - expect(com_gitlab_client).to receive(:stop_environment) - .with(downstream_project_path, downstream_environment_response.id) - .and_return(downstream_environment_stopping_response) - end - - context "when stopping the environment succeeds" do - let(:downstream_environment_stopping_response) { double('downstream_environment', state: 'stopped') } - - it 'displays a success message' do - expect(subject).to receive(:puts) - .with("=> Downstream environment '#{subject.__send__(:downstream_environment)}' stopped.") - - subject.cleanup! - end - end - - context "when stopping the environment fails" do - let(:downstream_environment_stopping_response) { double('downstream_environment', state: 'running') } - - it 'displays a failure message' do - expect(subject).to receive(:puts) - .with("=> Downstream environment '#{subject.__send__(:downstream_environment)}' failed to stop.") - - subject.cleanup! - end - end - end - end - - describe Trigger::DocsHugo do let(:downstream_project_path) { 'gitlab-org/technical-writing/docs-gitlab-com' } describe '#variables' do @@ -766,11 +561,11 @@ def ref_param_name end describe '.access_token' do - context 'when DOCS_HUGO_PROJECT_API_TOKEN is set' do + context 'when DOCS_PROJECT_API_TOKEN is set' do let(:docs_hugo_project_api_token) { 'docs_hugo_project_api_token' } before do - stub_env('DOCS_HUGO_PROJECT_API_TOKEN', docs_hugo_project_api_token) + stub_env('DOCS_PROJECT_API_TOKEN', docs_hugo_project_api_token) end it 'returns the docs-specific access token' do @@ -778,9 +573,9 @@ def ref_param_name end end - context 'when DOCS_HUGO_PROJECT_API_TOKEN is not set' do + context 'when DOCS_PROJECT_API_TOKEN is not set' do before do - stub_env('DOCS_HUGO_PROJECT_API_TOKEN', nil) + stub_env('DOCS_PROJECT_API_TOKEN', nil) end it 'returns the default access token' do @@ -796,7 +591,7 @@ def ref_param_name let(:env) do super().merge( 'CI_PROJECT_PATH' => 'gitlab-org/gitlab-foss', - 'DOCS_HUGO_TRIGGER_TOKEN' => trigger_token + 'DOCS_TRIGGER_TOKEN' => trigger_token ) end @@ -877,7 +672,7 @@ def ref_param_name end it 'returns the correct app URL' do - expected_url = "https://new.docs.gitlab.com/upstream-review-mr-#{review_slug}/" + expected_url = "https://docs.gitlab.com/upstream-review-mr-#{review_slug}/" expect(subject.send(:app_url)).to eq(expected_url) end end