Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cb2ce845
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,发现更多精彩内容 >>
提交
cb2ce845
编写于
4月 04, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove legacy registry tags when deleting a project
上级
1c91d52a
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
92 addition
and
21 deletion
+92
-21
app/models/container_repository.rb
app/models/container_repository.rb
+4
-0
app/services/projects/destroy_service.rb
app/services/projects/destroy_service.rb
+20
-3
spec/models/container_repository_spec.rb
spec/models/container_repository_spec.rb
+18
-0
spec/services/projects/destroy_service_spec.rb
spec/services/projects/destroy_service_spec.rb
+50
-18
未找到文件。
app/models/container_repository.rb
浏览文件 @
cb2ce845
...
...
@@ -70,4 +70,8 @@ class ContainerRepository < ActiveRecord::Base
def
self
.
create_from_path!
(
path
)
build_from_path
(
path
).
tap
(
&
:save!
)
end
def
self
.
build_root_repository
(
project
)
self
.
new
(
project:
project
,
name:
''
)
end
end
app/services/projects/destroy_service.rb
浏览文件 @
cb2ce845
...
...
@@ -29,15 +29,20 @@ module Projects
Project
.
transaction
do
project
.
team
.
truncate
project
.
destroy!
unless
remove_legacy_registry_tags
raise_error
(
'Failed to remove some tags in project container registry. Please try again or contact administrator.'
)
end
unless
remove_repository
(
repo_path
)
raise_error
(
'Failed to remove project repository. Please try again or contact administrator'
)
raise_error
(
'Failed to remove project repository. Please try again or contact administrator
.
'
)
end
unless
remove_repository
(
wiki_path
)
raise_error
(
'Failed to remove wiki repository. Please try again or contact administrator'
)
raise_error
(
'Failed to remove wiki repository. Please try again or contact administrator
.
'
)
end
project
.
destroy!
end
log_info
(
"Project
\"
#{
project
.
path_with_namespace
}
\"
was removed"
)
...
...
@@ -64,6 +69,18 @@ module Projects
end
end
##
# This method makes sure that we correctly remove registry tags
# for legacy image repository (when repository path equals project path).
#
def
remove_legacy_registry_tags
return
true
unless
Gitlab
.
config
.
registry
.
enabled
ContainerRepository
.
build_root_repository
(
project
).
tap
do
|
repository
|
return
repository
.
delete_tags!
if
repository
.
has_tags?
end
end
def
raise_error
(
message
)
raise
DestroyError
.
new
(
message
)
end
...
...
spec/models/container_repository_spec.rb
浏览文件 @
cb2ce845
...
...
@@ -195,4 +195,22 @@ describe ContainerRepository do
end
end
end
describe
'.build_root_repository'
do
let
(
:repository
)
do
described_class
.
build_root_repository
(
project
)
end
it
'fabricates a root repository object'
do
expect
(
repository
).
to
be_root_repository
end
it
'assignes it to the correct project'
do
expect
(
repository
.
project
).
to
eq
project
end
it
'does not persist it'
do
expect
(
repository
).
not_to
be_persisted
end
end
end
spec/services/projects/destroy_service_spec.rb
浏览文件 @
cb2ce845
...
...
@@ -7,6 +7,11 @@ describe Projects::DestroyService, services: true do
let!
(
:remove_path
)
{
path
.
sub
(
/\.git\Z/
,
"+
#{
project
.
id
}
+deleted.git"
)
}
let!
(
:async
)
{
false
}
# execute or async_execute
before
do
stub_container_registry_config
(
enabled:
true
)
stub_container_registry_tags
(
repository: :any
,
tags:
[])
end
shared_examples
'deleting the project'
do
it
'deletes the project'
do
expect
(
Project
.
unscoped
.
all
).
not_to
include
(
project
)
...
...
@@ -89,37 +94,64 @@ describe Projects::DestroyService, services: true do
it_behaves_like
'deleting the project with pipeline and build'
end
context
'container registry'
do
describe
'container registry'
do
context
'when there are regular container repositories'
do
let
(
:container_repository
)
{
create
(
:container_repository
)
}
before
do
stub_container_registry_config
(
enabled:
true
)
stub_container_registry_tags
(
repository: :any
,
tags:
[
'tag'
])
stub_container_registry_tags
(
repository:
project
.
full_path
+
'/image'
,
tags:
[
'tag'
])
project
.
container_repositories
<<
container_repository
end
context
'images
deletion succeeds'
do
it
do
context
'when image repository
deletion succeeds'
do
it
'removes tags'
do
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_return
(
true
)
destroy_project
(
project
,
user
,
{}
)
destroy_project
(
project
,
user
)
end
end
context
'images
deletion fails'
do
before
do
context
'when image repository
deletion fails'
do
it
'raises an exception'
do
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_return
(
false
)
expect
{
destroy_project
(
project
,
user
)
}
.
to
raise_error
(
ActiveRecord
::
RecordNotDestroyed
)
end
end
end
subject
{
destroy_project
(
project
,
user
,
{})
}
context
'when there are tags for legacy root repository'
do
before
do
stub_container_registry_tags
(
repository:
project
.
full_path
,
tags:
[
'tag'
])
end
it
{
expect
{
subject
}.
to
raise_error
(
ActiveRecord
::
RecordNotDestroyed
)
}
context
'when image repository tags deletion succeeds'
do
it
'removes tags'
do
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_return
(
true
)
destroy_project
(
project
,
user
)
end
end
context
'when image repository tags deletion fails'
do
it
'raises an exception'
do
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_return
(
false
)
expect
{
destroy_project
(
project
,
user
)
}
.
to
raise_error
(
Projects
::
DestroyService
::
DestroyError
)
end
end
end
end
def
destroy_project
(
project
,
user
,
params
)
def
destroy_project
(
project
,
user
,
params
=
{}
)
if
async
Projects
::
DestroyService
.
new
(
project
,
user
,
params
).
async_execute
else
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录