Commit 85d0663b authored by Kamil Trzcinski's avatar Kamil Trzcinski

Added mock deployment and monitoring service with environments fixtures

parent cf91b76a
......@@ -116,6 +116,8 @@ class Project < ActiveRecord::Base
has_one :prometheus_service, dependent: :destroy, inverse_of: :project
has_one :index_status, 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_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)
binding.pry
[]
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
......@@ -240,7 +240,9 @@ class Service < ActiveRecord::Base
slack
teamcity
]
service_names << 'mock_ci' if Rails.env.development?
if Rails.env.development?
service_names += ['mock_ci', 'mock_deployment', 'mock_monitoring']
end
service_names.sort_by(&:downcase)
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(2).map do |merge_request|
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
......@@ -610,8 +610,14 @@ module API
desc: 'URL to the mock service'
}
]
services['mock-deployment'] = []
services['mock-monitoring'] = []
service_classes << MockCiService
service_classes += [
MockCiService,
MockDeploymentService,
MockMonitoringService,
]
end
trigger_services = {
......
This diff is collapsed.
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