Commit 10a77824 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'mock-deployments' into 'master'

Added mock deployment and monitoring service with environments fixtures

See merge request !10379
parents dd18faff 7f8e0bce
...@@ -114,6 +114,8 @@ class Project < ActiveRecord::Base ...@@ -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
......
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
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 ...@@ -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
......
---
title: Added mock deployment and monitoring service with environments fixtures
merge_request:
author:
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 ...@@ -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 = {
......
This diff is collapsed.
...@@ -156,6 +156,8 @@ project: ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment