diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /app/controllers/projects/google_cloud/deployments_controller.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'app/controllers/projects/google_cloud/deployments_controller.rb')
-rw-r--r-- | app/controllers/projects/google_cloud/deployments_controller.rb | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/app/controllers/projects/google_cloud/deployments_controller.rb b/app/controllers/projects/google_cloud/deployments_controller.rb index 4e7fd73e378..1941eb8a5f9 100644 --- a/app/controllers/projects/google_cloud/deployments_controller.rb +++ b/app/controllers/projects/google_cloud/deployments_controller.rb @@ -4,10 +4,63 @@ class Projects::GoogleCloud::DeploymentsController < Projects::GoogleCloud::Base before_action :validate_gcp_token! def cloud_run - render json: "Placeholder" + params = { token_in_session: token_in_session } + enable_cloud_run_response = GoogleCloud::EnableCloudRunService + .new(project, current_user, params).execute + + if enable_cloud_run_response[:status] == :error + flash[:error] = enable_cloud_run_response[:message] + redirect_to project_google_cloud_index_path(project) + else + params = { action: GoogleCloud::GeneratePipelineService::ACTION_DEPLOY_TO_CLOUD_RUN } + generate_pipeline_response = GoogleCloud::GeneratePipelineService + .new(project, current_user, params).execute + + if generate_pipeline_response[:status] == :error + flash[:error] = 'Failed to generate pipeline' + redirect_to project_google_cloud_index_path(project) + else + cloud_run_mr_params = cloud_run_mr_params(generate_pipeline_response[:branch_name]) + redirect_to project_new_merge_request_path(project, merge_request: cloud_run_mr_params) + end + end + rescue Google::Apis::ClientError => error + handle_gcp_error(error, project) end def cloud_storage render json: "Placeholder" end + + private + + def cloud_run_mr_params(branch_name) + { + title: cloud_run_mr_title, + description: cloud_run_mr_description(branch_name), + source_project_id: project.id, + target_project_id: project.id, + source_branch: branch_name, + target_branch: project.default_branch + } + end + + def cloud_run_mr_title + 'Enable deployments to Cloud Run' + end + + def cloud_run_mr_description(branch_name) + <<-TEXT +This merge request includes a Cloud Run deployment job in the pipeline definition (.gitlab-ci.yml). + +The `deploy-to-cloud-run` job: +* Requires the following environment variables + * `GCP_PROJECT_ID` + * `GCP_SERVICE_ACCOUNT_KEY` +* Job definition can be found at: https://gitlab.com/gitlab-org/incubation-engineering/five-minute-production/library + +This pipeline definition has been committed to the branch `#{branch_name}`. +You may modify the pipeline definition further or accept the changes as-is if suitable. + TEXT + end end |