Added mock deployment and monitoring service with environments fixtures
This commit is contained in:
parent
dd18faff91
commit
7f8e0bce5a
10 changed files with 124 additions and 2 deletions
|
@ -114,6 +114,8 @@ class Project < ActiveRecord::Base
|
||||||
has_one :kubernetes_service, dependent: :destroy, inverse_of: :project
|
has_one :kubernetes_service, dependent: :destroy, inverse_of: :project
|
||||||
has_one :prometheus_service, dependent: :destroy, inverse_of: :project
|
has_one :prometheus_service, dependent: :destroy, inverse_of: :project
|
||||||
has_one :mock_ci_service, dependent: :destroy
|
has_one :mock_ci_service, dependent: :destroy
|
||||||
|
has_one :mock_deployment_service, dependent: :destroy
|
||||||
|
has_one :mock_monitoring_service, dependent: :destroy
|
||||||
|
|
||||||
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
|
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
|
||||||
has_one :forked_from_project, through: :forked_project_link
|
has_one :forked_from_project, through: :forked_project_link
|
||||||
|
|
18
app/models/project_services/mock_deployment_service.rb
Normal file
18
app/models/project_services/mock_deployment_service.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
class MockDeploymentService < DeploymentService
|
||||||
|
def title
|
||||||
|
'Mock deployment'
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
'Mock deployment service'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.to_param
|
||||||
|
'mock_deployment'
|
||||||
|
end
|
||||||
|
|
||||||
|
# No terminals support
|
||||||
|
def terminals(environment)
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
17
app/models/project_services/mock_monitoring_service.rb
Normal file
17
app/models/project_services/mock_monitoring_service.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
class MockMonitoringService < MonitoringService
|
||||||
|
def title
|
||||||
|
'Mock monitoring'
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
'Mock monitoring service'
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.to_param
|
||||||
|
'mock_monitoring'
|
||||||
|
end
|
||||||
|
|
||||||
|
def metrics(environment)
|
||||||
|
JSON.parse(File.read(Rails.root + 'spec/fixtures/metrics.json'))
|
||||||
|
end
|
||||||
|
end
|
|
@ -238,7 +238,9 @@ class Service < ActiveRecord::Base
|
||||||
slack
|
slack
|
||||||
teamcity
|
teamcity
|
||||||
]
|
]
|
||||||
service_names << 'mock_ci' if Rails.env.development?
|
if Rails.env.development?
|
||||||
|
service_names += %w[mock_ci mock_deployment mock_monitoring]
|
||||||
|
end
|
||||||
|
|
||||||
service_names.sort_by(&:downcase)
|
service_names.sort_by(&:downcase)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: Added mock deployment and monitoring service with environments fixtures
|
||||||
|
merge_request:
|
||||||
|
author:
|
70
db/fixtures/development/19_environments.rb
Normal file
70
db/fixtures/development/19_environments.rb
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
require './spec/support/sidekiq'
|
||||||
|
|
||||||
|
class Gitlab::Seeder::Environments
|
||||||
|
def initialize(project)
|
||||||
|
@project = project
|
||||||
|
end
|
||||||
|
|
||||||
|
def seed!
|
||||||
|
@project.create_mock_deployment_service!(active: true)
|
||||||
|
@project.create_mock_monitoring_service!(active: true)
|
||||||
|
|
||||||
|
create_master_deployments!('production')
|
||||||
|
create_master_deployments!('staging')
|
||||||
|
create_merge_request_review_deployments!
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_master_deployments!(name)
|
||||||
|
@project.repository.commits('master', limit: 4).map do |commit|
|
||||||
|
create_deployment!(
|
||||||
|
@project,
|
||||||
|
name,
|
||||||
|
'master',
|
||||||
|
commit.id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_merge_request_review_deployments!
|
||||||
|
@project.merge_requests.sample(4).map do |merge_request|
|
||||||
|
next unless merge_request.diff_head_sha
|
||||||
|
|
||||||
|
create_deployment!(
|
||||||
|
merge_request.source_project,
|
||||||
|
"review/#{merge_request.source_branch}",
|
||||||
|
merge_request.source_branch,
|
||||||
|
merge_request.diff_head_sha
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_deployment!(project, name, ref, sha)
|
||||||
|
environment = find_or_create_environment!(project, name)
|
||||||
|
environment.deployments.create!(
|
||||||
|
project: project,
|
||||||
|
ref: ref,
|
||||||
|
sha: sha,
|
||||||
|
tag: false,
|
||||||
|
deployable: find_deployable(project, name)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_or_create_environment!(project, name)
|
||||||
|
project.environments.find_or_create_by!(name: name).tap do |environment|
|
||||||
|
environment.update(external_url: "https://google.com/#{name}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_deployable(project, environment)
|
||||||
|
project.builds.where(environment: environment).sample
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Gitlab::Seeder.quiet do
|
||||||
|
Project.all.sample(5).each do |project|
|
||||||
|
project_environments = Gitlab::Seeder::Environments.new(project)
|
||||||
|
project_environments.seed!
|
||||||
|
end
|
||||||
|
end
|
|
@ -562,8 +562,14 @@ module API
|
||||||
desc: 'URL to the mock service'
|
desc: 'URL to the mock service'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
services['mock-deployment'] = []
|
||||||
|
services['mock-monitoring'] = []
|
||||||
|
|
||||||
service_classes << MockCiService
|
service_classes += [
|
||||||
|
MockCiService,
|
||||||
|
MockDeploymentService,
|
||||||
|
MockMonitoringService,
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
trigger_services = {
|
trigger_services = {
|
||||||
|
|
1
spec/fixtures/metrics.json
vendored
Normal file
1
spec/fixtures/metrics.json
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -156,6 +156,8 @@ project:
|
||||||
- external_wiki_service
|
- external_wiki_service
|
||||||
- kubernetes_service
|
- kubernetes_service
|
||||||
- mock_ci_service
|
- mock_ci_service
|
||||||
|
- mock_deployment_service
|
||||||
|
- mock_monitoring_service
|
||||||
- forked_project_link
|
- forked_project_link
|
||||||
- forked_from_project
|
- forked_from_project
|
||||||
- forked_project_links
|
- forked_project_links
|
||||||
|
|
Loading…
Reference in a new issue