Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
db5b4b8b
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
db5b4b8b
编写于
2月 22, 2017
作者:
A
Andre Guedes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Creates specs for destroy service and improves namespace container image query performance
上级
8294756f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
45 addition
and
65 deletion
+45
-65
app/models/namespace.rb
app/models/namespace.rb
+1
-1
app/services/container_images/destroy_service.rb
app/services/container_images/destroy_service.rb
+2
-24
app/views/admin/container_registry/show.html.haml
app/views/admin/container_registry/show.html.haml
+1
-1
db/migrate/20161031013926_create_container_image.rb
db/migrate/20161031013926_create_container_image.rb
+0
-16
db/migrate/20161213212947_add_container_registry_access_token_to_application_settings.rb
...ontainer_registry_access_token_to_application_settings.rb
+0
-16
db/schema.rb
db/schema.rb
+5
-5
lib/api/registry_events.rb
lib/api/registry_events.rb
+2
-2
spec/services/container_images/destroy_service_spec.rb
spec/services/container_images/destroy_service_spec.rb
+34
-0
未找到文件。
app/models/namespace.rb
浏览文件 @
db5b4b8b
...
...
@@ -155,7 +155,7 @@ class Namespace < ActiveRecord::Base
end
def
any_project_has_container_registry_images?
projects
.
any?
{
|
project
|
project
.
container_images
.
present?
}
projects
.
joins
(
:container_images
).
any?
end
def
send_update_instructions
...
...
app/services/container_images/destroy_service.rb
浏览文件 @
db5b4b8b
module
ContainerImages
class
DestroyService
<
BaseService
class
DestroyError
<
StandardError
;
end
def
execute
(
container_image
)
@container_image
=
container_image
return
false
unless
can?
(
current_user
,
:remove_project
,
project
)
ContainerImage
.
transaction
do
container_image
.
destroy!
unless
remove_container_image_tags
raise_error
(
'Failed to remove container image tags. Please try again or contact administrator'
)
end
end
true
end
private
def
raise_error
(
message
)
raise
DestroyError
.
new
(
message
)
end
return
false
unless
can?
(
current_user
,
:update_container_image
,
project
)
def
remove_container_image_tags
container_image
.
delete_tags
container_image
.
destroy!
end
end
end
app/views/admin/container_registry/show.html.haml
浏览文件 @
db5b4b8b
...
...
@@ -17,7 +17,7 @@
X-Registry-Token: [
#{
@access_token
}
]
%br
Access token is
%code
{
id:
'registry-token'
}
#{
@access_token
}
%code
{
id:
'registry-token'
}
=
@access_token
.bs-callout.clearfix
.pull-left
...
...
db/migrate/20161031013926_create_container_image.rb
浏览文件 @
db5b4b8b
...
...
@@ -7,22 +7,6 @@ class CreateContainerImage < ActiveRecord::Migration
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method is the _only_ method called in the migration, any other changes
# should go in a separate migration. This ensures that upon failure _only_ the
# index creation fails and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def
change
create_table
:container_images
do
|
t
|
t
.
integer
:project_id
...
...
db/migrate/20161213212947_add_container_registry_access_token_to_application_settings.rb
浏览文件 @
db5b4b8b
...
...
@@ -7,22 +7,6 @@ class AddContainerRegistryAccessTokenToApplicationSettings < ActiveRecord::Migra
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
# When a migration requires downtime you **must** uncomment the following
# constant and define a short and easy to understand explanation as to why the
# migration requires downtime.
# DOWNTIME_REASON = ''
# When using the methods "add_concurrent_index" or "add_column_with_default"
# you must disable the use of transactions as these methods can not run in an
# existing transaction. When using "add_concurrent_index" make sure that this
# method is the _only_ method called in the migration, any other changes
# should go in a separate migration. This ensures that upon failure _only_ the
# index creation fails and can be retried or reverted easily.
#
# To disable transactions uncomment the following line and remove these
# comments:
# disable_ddl_transaction!
def
change
add_column
:application_settings
,
:container_registry_access_token
,
:string
end
...
...
db/schema.rb
浏览文件 @
db5b4b8b
...
...
@@ -61,6 +61,7 @@ ActiveRecord::Schema.define(version: 20170215200045) do
t
.
boolean
"shared_runners_enabled"
,
default:
true
,
null:
false
t
.
integer
"max_artifacts_size"
,
default:
100
,
null:
false
t
.
string
"runners_registration_token"
t
.
integer
"max_pages_size"
,
default:
100
,
null:
false
t
.
boolean
"require_two_factor_authentication"
,
default:
false
t
.
integer
"two_factor_grace_period"
,
default:
48
t
.
boolean
"metrics_enabled"
,
default:
false
...
...
@@ -107,10 +108,9 @@ ActiveRecord::Schema.define(version: 20170215200045) do
t
.
string
"sidekiq_throttling_queues"
t
.
decimal
"sidekiq_throttling_factor"
t
.
boolean
"html_emails_enabled"
,
default:
true
t
.
string
"container_registry_access_token"
t
.
string
"plantuml_url"
t
.
boolean
"plantuml_enabled"
t
.
string
"container_registry_access_token"
t
.
integer
"max_pages_size"
,
default:
100
,
null:
false
t
.
integer
"terminal_max_session_time"
,
default:
0
,
null:
false
end
...
...
@@ -586,9 +586,9 @@ ActiveRecord::Schema.define(version: 20170215200045) do
end
add_index
"labels"
,
[
"group_id"
,
"project_id"
,
"title"
],
name:
"index_labels_on_group_id_and_project_id_and_title"
,
unique:
true
,
using: :btree
add_index
"labels"
,
[
"type"
,
"project_id"
],
name:
"index_labels_on_type_and_project_id"
,
using: :btree
add_index
"labels"
,
[
"project_id"
],
name:
"index_labels_on_project_id"
,
using: :btree
add_index
"labels"
,
[
"title"
],
name:
"index_labels_on_title"
,
using: :btree
add_index
"labels"
,
[
"type"
,
"project_id"
],
name:
"index_labels_on_type_and_project_id"
,
using: :btree
create_table
"lfs_objects"
,
force: :cascade
do
|
t
|
t
.
string
"oid"
,
null:
false
...
...
@@ -761,8 +761,8 @@ ActiveRecord::Schema.define(version: 20170215200045) do
t
.
integer
"visibility_level"
,
default:
20
,
null:
false
t
.
boolean
"request_access_enabled"
,
default:
false
,
null:
false
t
.
datetime
"deleted_at"
t
.
boolean
"lfs_enabled"
t
.
text
"description_html"
t
.
boolean
"lfs_enabled"
t
.
integer
"parent_id"
end
...
...
@@ -1283,8 +1283,8 @@ ActiveRecord::Schema.define(version: 20170215200045) do
t
.
datetime
"otp_grace_period_started_at"
t
.
boolean
"ldap_email"
,
default:
false
,
null:
false
t
.
boolean
"external"
,
default:
false
t
.
string
"organization"
t
.
string
"incoming_email_token"
t
.
string
"organization"
t
.
boolean
"authorized_projects_populated"
t
.
boolean
"notified_of_own_activity"
,
default:
false
,
null:
false
end
...
...
lib/api/registry_events.rb
浏览文件 @
db5b4b8b
...
...
@@ -39,9 +39,9 @@ module API
params
[
'events'
].
each
do
|
event
|
repository
=
event
[
'target'
][
'repository'
]
if
event
[
'action'
]
==
'push'
and
!!
event
[
'target'
][
'tag'
]
if
event
[
'action'
]
==
'push'
&&
!!
event
[
'target'
][
'tag'
]
namespace
,
container_image_name
=
ContainerImage
::
split_namespace
(
repository
)
project
=
Project
::
find_
with_namespace
(
namespace
)
project
=
Project
::
find_
by_full_path
(
namespace
)
if
project
container_image
=
project
.
container_images
.
find_or_create_by
(
name:
container_image_name
)
...
...
spec/services/container_images/destroy_service_spec.rb
0 → 100644
浏览文件 @
db5b4b8b
require
'spec_helper'
describe
ContainerImages
::
DestroyService
,
services:
true
do
describe
'#execute'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:container_image
)
{
create
(
:container_image
,
name:
''
)
}
let
(
:project
)
{
create
(
:project
,
path:
'test'
,
namespace:
user
.
namespace
,
container_images:
[
container_image
])
}
let
(
:example_host
)
{
'example.com'
}
let
(
:registry_url
)
{
'http://'
+
example_host
}
it
{
expect
(
container_image
).
to
be_valid
}
it
{
expect
(
project
.
container_images
).
not_to
be_empty
}
context
'when container image has tags'
do
before
do
project
.
team
<<
[
user
,
:master
]
end
it
'removes all tags before destroy'
do
service
=
described_class
.
new
(
project
,
user
)
expect
(
container_image
).
to
receive
(
:delete_tags
).
and_return
(
true
)
expect
{
service
.
execute
(
container_image
)
}.
to
change
(
project
.
container_images
,
:count
).
by
(
-
1
)
end
it
'fails when tags are not removed'
do
service
=
described_class
.
new
(
project
,
user
)
expect
(
container_image
).
to
receive
(
:delete_tags
).
and_return
(
false
)
expect
{
service
.
execute
(
container_image
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotDestroyed
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录