debian-mirror-gitlab/app/controllers/projects/google_cloud/deployments_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
3.3 KiB
Ruby
Raw Normal View History

2022-03-02 08:16:31 +05:30
# frozen_string_literal: true
class Projects::GoogleCloud::DeploymentsController < Projects::GoogleCloud::BaseController
before_action :validate_gcp_token!
2022-08-13 15:12:31 +05:30
def index
js_data = {
configurationUrl: project_google_cloud_configuration_path(project),
deploymentsUrl: project_google_cloud_deployments_path(project),
databasesUrl: project_google_cloud_databases_path(project),
enableCloudRunUrl: project_google_cloud_deployments_cloud_run_path(project),
enableCloudStorageUrl: project_google_cloud_deployments_cloud_storage_path(project)
}
2023-01-13 00:05:48 +05:30
@js_data = Gitlab::Json.dump(js_data)
2022-10-11 01:57:18 +05:30
track_event(:render_page)
2022-08-13 15:12:31 +05:30
end
2022-03-02 08:16:31 +05:30
def cloud_run
2022-08-13 15:12:31 +05:30
params = { google_oauth2_token: token_in_session }
2022-04-04 11:22:00 +05:30
enable_cloud_run_response = GoogleCloud::EnableCloudRunService
.new(project, current_user, params).execute
if enable_cloud_run_response[:status] == :error
2022-10-11 01:57:18 +05:30
track_event(:error_enable_services)
2023-04-23 21:23:45 +05:30
flash[:alert] = enable_cloud_run_response[:message]
2022-08-13 15:12:31 +05:30
redirect_to project_google_cloud_deployments_path(project)
2022-04-04 11:22:00 +05:30
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
2022-10-11 01:57:18 +05:30
track_event(:error_generate_cloudrun_pipeline)
2023-04-23 21:23:45 +05:30
flash[:alert] = 'Failed to generate pipeline'
2022-08-13 15:12:31 +05:30
redirect_to project_google_cloud_deployments_path(project)
2022-04-04 11:22:00 +05:30
else
cloud_run_mr_params = cloud_run_mr_params(generate_pipeline_response[:branch_name])
2022-10-11 01:57:18 +05:30
track_event(:generate_cloudrun_pipeline)
2022-04-04 11:22:00 +05:30
redirect_to project_new_merge_request_path(project, merge_request: cloud_run_mr_params)
end
end
2022-10-11 01:57:18 +05:30
rescue Google::Apis::Error => e
track_event(:error_google_api)
2022-08-27 11:52:29 +05:30
flash[:warning] = _('Google Cloud Error - %{error}') % { error: e }
2022-08-13 15:12:31 +05:30
redirect_to project_google_cloud_deployments_path(project)
2022-03-02 08:16:31 +05:30
end
def cloud_storage
render json: "Placeholder"
end
2022-04-04 11:22:00 +05:30
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
2023-03-17 16:20:25 +05:30
* Uses CI/CD variables to configure the deployment. You can override the default values by adding these variables:
* `GCP_CLOUD_RUN_MAX_INSTANCES`
* `GCP_CLOUD_RUN_MIN_INSTANCES`
* `GCP_CLOUD_RUN_CONCURRENCY`
* `GCP_CLOUD_RUN_CPU`
* `GCP_CLOUD_RUN_MEMORY`
* `GCP_CLOUD_RUN_TIMEOUT`
2022-04-04 11:22:00 +05:30
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
2022-03-02 08:16:31 +05:30
end