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
c1e42959a381
Commit
5c5dea2d
authored
Sep 19, 2018
by
Stan Hu
Browse files
Move registry destroy out of project transaction
parent
74d740d70bf9
Changes
5
Show whitespace changes
Inline
Side-by-side
app/models/container_repository.rb
View file @
c1e42959
...
...
@@ -8,8 +8,6 @@ class ContainerRepository < ActiveRecord::Base
delegate
:client
,
to: :registry
before_destroy
:delete_tags!
# rubocop: disable CodeReuse/ServiceClass
def
registry
@registry
||=
begin
...
...
app/services/projects/destroy_service.rb
View file @
c1e42959
...
...
@@ -133,11 +133,11 @@ def attempt_rollback(project, message)
end
def
attempt_destroy_transaction
(
project
)
Project
.
transaction
do
unless
remove_legacy_registry_tags
unless
remove_registry_tags
raise_error
(
'Failed to remove some tags in project container registry. Please try again or contact administrator.'
)
end
Project
.
transaction
do
log_destroy_event
trash_repositories!
...
...
@@ -156,6 +156,17 @@ def log_destroy_event
log_info
(
"Attempting to destroy
#{
project
.
full_path
}
(
#{
project
.
id
}
)"
)
end
def
remove_registry_tags
return
false
unless
remove_legacy_registry_tags
project
.
container_repositories
.
find_each
do
|
container_repository
|
service
=
Projects
::
ContainerRepository
::
DestroyService
.
new
(
project
,
current_user
)
service
.
execute
(
container_repository
)
end
true
end
##
# This method makes sure that we correctly remove registry tags
# for legacy image repository (when repository path equals project path).
...
...
spec/features/container_registry_spec.rb
View file @
c1e42959
...
...
@@ -39,7 +39,7 @@
visit_container_registry
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
twice
.
and_return
(
true
)
.
to
receive
(
:delete_tags!
).
and_return
(
true
)
click_on
(
class:
'js-remove-repo'
)
end
...
...
spec/services/projects/container_repository/destroy_service_spec.rb
View file @
c1e42959
...
...
@@ -33,7 +33,7 @@
end
it
'deletes the repository'
do
expect
(
repository
).
to
receive
(
:delete_tags!
).
twice
.
and_call_original
expect
(
repository
).
to
receive
(
:delete_tags!
).
and_call_original
expect
{
described_class
.
new
(
project
,
user
).
execute
(
repository
)
}.
to
change
{
ContainerRepository
.
all
.
count
}.
by
(
-
1
)
end
end
...
...
spec/services/projects/destroy_service_spec.rb
View file @
c1e42959
...
...
@@ -204,7 +204,7 @@
context
'when image repository deletion fails'
do
it
'raises an exception'
do
expect_any_instance_of
(
ContainerRepository
)
.
to
receive
(
:delete_tags!
).
and_r
eturn
(
false
)
.
to
receive
(
:delete_tags!
).
and_r
aise
(
RuntimeError
)
expect
(
destroy_project
(
project
,
user
)).
to
be
false
end
...
...
Write
Preview
Markdown
is supported
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