diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-04 13:57:38 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-04-04 13:57:38 +0300 |
commit | cb2ce8452fe2e9e156add5ccfe8fd2ec5cda9ace (patch) | |
tree | 260585123547b6bc30bf537fc9463a37b2b239aa /app | |
parent | 1c91d52a70407e15f9b106bafc6505895214f3b8 (diff) |
Remove legacy registry tags when deleting a project
Diffstat (limited to 'app')
-rw-r--r-- | app/models/container_repository.rb | 4 | ||||
-rw-r--r-- | app/services/projects/destroy_service.rb | 23 |
2 files changed, 24 insertions, 3 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 36158d75ae8..463eb5b7d69 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -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 diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb index 4e1964f79dd..a47e74ba9b0 100644 --- a/app/services/projects/destroy_service.rb +++ b/app/services/projects/destroy_service.rb @@ -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 |