Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
901302fc89ab
Commit
901302fc
authored
Apr 05, 2017
by
Kamil Trzciński
Browse files
Added mock deployment and monitoring service with environments fixtures
parent
3cd9158b09ad
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
901302fc
...
...
@@ -114,6 +114,8 @@
has_one
:kubernetes_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_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
...
...
app/models/project_services/mock_deployment_service.rb
0 → 100644
View file @
901302fc
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
app/models/project_services/mock_monitoring_service.rb
0 → 100644
View file @
901302fc
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
app/models/service.rb
View file @
901302fc
...
...
@@ -238,7 +238,9 @@
slack
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
)
end
...
...
changelogs/unreleased/add-mock-deployment-and-monitoring-service-for-development.yaml
0 → 100644
View file @
901302fc
---
title
:
Added mock deployment and monitoring service with environments fixtures
merge_request
:
author
:
db/fixtures/development/19_environments.rb
0 → 100644
View file @
901302fc
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
db/fixtures/development/19_nested_groups.rb
deleted
100644 → 0
View file @
3cd9158b
require
'./spec/support/sidekiq'
def
create_group_with_parents
(
user
,
full_path
)
parent_path
=
nil
group
=
nil
until
full_path
.
blank?
path
,
_
,
full_path
=
full_path
.
partition
(
'/'
)
if
parent_path
parent
=
Group
.
find_by_full_path
(
parent_path
)
parent_path
+=
'/'
parent_path
+=
path
group
=
Groups
::
CreateService
.
new
(
user
,
path:
path
,
parent_id:
parent
.
id
).
execute
else
parent_path
=
path
group
=
Group
.
find_by_full_path
(
parent_path
)
||
Groups
::
CreateService
.
new
(
user
,
path:
path
).
execute
end
end
group
end
Sidekiq
::
Testing
.
inline!
do
Gitlab
::
Seeder
.
quiet
do
project_urls
=
[
'https://android.googlesource.com/platform/hardware/broadcom/libbt.git'
,
'https://android.googlesource.com/platform/hardware/broadcom/wlan.git'
,
'https://android.googlesource.com/platform/hardware/bsp/bootloader/intel/edison-u-boot.git'
,
'https://android.googlesource.com/platform/hardware/bsp/broadcom.git'
,
'https://android.googlesource.com/platform/hardware/bsp/freescale.git'
,
'https://android.googlesource.com/platform/hardware/bsp/imagination.git'
,
'https://android.googlesource.com/platform/hardware/bsp/intel.git'
,
'https://android.googlesource.com/platform/hardware/bsp/kernel/common/v4.1.git'
,
'https://android.googlesource.com/platform/hardware/bsp/kernel/common/v4.4.git'
]
user
=
User
.
admins
.
first
project_urls
.
each_with_index
do
|
url
,
i
|
full_path
=
url
.
sub
(
'https://android.googlesource.com/'
,
''
)
full_path
=
full_path
.
sub
(
/\.git\z/
,
''
)
full_path
,
_
,
project_path
=
full_path
.
rpartition
(
'/'
)
group
=
Group
.
find_by_full_path
(
full_path
)
||
create_group_with_parents
(
user
,
full_path
)
params
=
{
import_url:
url
,
namespace_id:
group
.
id
,
path:
project_path
,
name:
project_path
,
description:
FFaker
::
Lorem
.
sentence
,
visibility_level:
Gitlab
::
VisibilityLevel
.
values
.
sample
}
project
=
Projects
::
CreateService
.
new
(
user
,
params
).
execute
project
.
send
(
:_run_after_commit_queue
)
if
project
.
valid?
print
'.'
else
print
'F'
end
end
end
end
db/fixtures/development/20_nested_groups.rb
0 → 100644
View file @
901302fc
require
'./spec/support/sidekiq'
def
create_group_with_parents
(
user
,
full_path
)
parent_path
=
nil
group
=
nil
until
full_path
.
blank?
path
,
_
,
full_path
=
full_path
.
partition
(
'/'
)
if
parent_path
parent
=
Group
.
find_by_full_path
(
parent_path
)
parent_path
+=
'/'
parent_path
+=
path
group
=
Groups
::
CreateService
.
new
(
user
,
path:
path
,
parent_id:
parent
.
id
).
execute
else
parent_path
=
path
group
=
Group
.
find_by_full_path
(
parent_path
)
||
Groups
::
CreateService
.
new
(
user
,
path:
path
).
execute
end
end
group
end
Sidekiq
::
Testing
.
inline!
do
Gitlab
::
Seeder
.
quiet
do
project_urls
=
[
'https://android.googlesource.com/platform/hardware/broadcom/libbt.git'
,
'https://android.googlesource.com/platform/hardware/broadcom/wlan.git'
,
'https://android.googlesource.com/platform/hardware/bsp/bootloader/intel/edison-u-boot.git'
,
'https://android.googlesource.com/platform/hardware/bsp/broadcom.git'
,
'https://android.googlesource.com/platform/hardware/bsp/freescale.git'
,
'https://android.googlesource.com/platform/hardware/bsp/imagination.git'
,
'https://android.googlesource.com/platform/hardware/bsp/intel.git'
,
'https://android.googlesource.com/platform/hardware/bsp/kernel/common/v4.1.git'
,
'https://android.googlesource.com/platform/hardware/bsp/kernel/common/v4.4.git'
]
user
=
User
.
admins
.
first
project_urls
.
each_with_index
do
|
url
,
i
|
full_path
=
url
.
sub
(
'https://android.googlesource.com/'
,
''
)
full_path
=
full_path
.
sub
(
/\.git\z/
,
''
)
full_path
,
_
,
project_path
=
full_path
.
rpartition
(
'/'
)
group
=
Group
.
find_by_full_path
(
full_path
)
||
create_group_with_parents
(
user
,
full_path
)
params
=
{
import_url:
url
,
namespace_id:
group
.
id
,
path:
project_path
,
name:
project_path
,
description:
FFaker
::
Lorem
.
sentence
,
visibility_level:
Gitlab
::
VisibilityLevel
.
values
.
sample
}
project
=
Projects
::
CreateService
.
new
(
user
,
params
).
execute
project
.
send
(
:_run_after_commit_queue
)
if
project
.
valid?
print
'.'
else
print
'F'
end
end
end
end
lib/api/services.rb
View file @
901302fc
...
...
@@ -562,4 +562,6 @@
desc:
'URL to the mock service'
}
]
services
[
'mock-deployment'
]
=
[]
services
[
'mock-monitoring'
]
=
[]
...
...
@@ -565,5 +567,9 @@
service_classes
<<
MockCiService
service_classes
+=
[
MockCiService
,
MockDeploymentService
,
MockMonitoringService
,
]
end
trigger_services
=
{
...
...
spec/fixtures/metrics.json
0 → 100644
View file @
901302fc
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/import_export/all_models.yml
View file @
901302fc
...
...
@@ -156,6 +156,8 @@
-
external_wiki_service
-
kubernetes_service
-
mock_ci_service
-
mock_deployment_service
-
mock_monitoring_service
-
forked_project_link
-
forked_from_project
-
forked_project_links
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment