Commit 311beef2 authored by Stan Hu's avatar Stan Hu

Move registry destroy out of project transaction

parent a1912ccc
...@@ -8,8 +8,6 @@ class ContainerRepository < ActiveRecord::Base ...@@ -8,8 +8,6 @@ class ContainerRepository < ActiveRecord::Base
delegate :client, to: :registry delegate :client, to: :registry
before_destroy :delete_tags!
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def registry def registry
@registry ||= begin @registry ||= begin
......
...@@ -133,11 +133,11 @@ module Projects ...@@ -133,11 +133,11 @@ module Projects
end end
def attempt_destroy_transaction(project) def attempt_destroy_transaction(project)
Project.transaction do unless remove_registry_tags
unless remove_legacy_registry_tags raise_error('Failed to remove some tags in project container registry. Please try again or contact administrator.')
raise_error('Failed to remove some tags in project container registry. Please try again or contact administrator.') end
end
Project.transaction do
log_destroy_event log_destroy_event
trash_repositories! trash_repositories!
...@@ -156,6 +156,17 @@ module Projects ...@@ -156,6 +156,17 @@ module Projects
log_info("Attempting to destroy #{project.full_path} (#{project.id})") log_info("Attempting to destroy #{project.full_path} (#{project.id})")
end 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 # This method makes sure that we correctly remove registry tags
# for legacy image repository (when repository path equals project path). # for legacy image repository (when repository path equals project path).
......
...@@ -39,7 +39,7 @@ describe "Container Registry", :js do ...@@ -39,7 +39,7 @@ describe "Container Registry", :js do
visit_container_registry visit_container_registry
expect_any_instance_of(ContainerRepository) 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') click_on(class: 'js-remove-repo')
end end
......
...@@ -33,7 +33,7 @@ describe Projects::ContainerRepository::DestroyService do ...@@ -33,7 +33,7 @@ describe Projects::ContainerRepository::DestroyService do
end end
it 'deletes the repository' do 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) expect { described_class.new(project, user).execute(repository) }.to change { ContainerRepository.all.count }.by(-1)
end end
end end
......
...@@ -204,7 +204,7 @@ describe Projects::DestroyService do ...@@ -204,7 +204,7 @@ describe Projects::DestroyService do
context 'when image repository deletion fails' do context 'when image repository deletion fails' do
it 'raises an exception' do it 'raises an exception' do
expect_any_instance_of(ContainerRepository) expect_any_instance_of(ContainerRepository)
.to receive(:delete_tags!).and_return(false) .to receive(:delete_tags!).and_raise(RuntimeError)
expect(destroy_project(project, user)).to be false expect(destroy_project(project, user)).to be false
end end
......
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