blob: 6db6b44967111b2c58e4bf3d917d14de4b9624e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# frozen_string_literal: true
module Projects
module ContainerRepository
class DestroyService < BaseService
CLEANUP_TAGS_SERVICE_PARAMS = {
'name_regex_delete' => '.*',
'container_expiration_policy' => true, # to avoid permissions checks
'keep_latest' => false
}.freeze
def execute(container_repository, disable_timeout: true)
return false unless can?(current_user, :update_container_image, project)
# Delete tags outside of the transaction to avoid hitting an idle-in-transaction timeout
unless delete_tags(container_repository, disable_timeout) &&
destroy_container_repository(container_repository)
container_repository.delete_failed!
end
end
private
def delete_tags(container_repository, disable_timeout)
service = Projects::ContainerRepository::CleanupTagsService.new(
container_repository: container_repository,
params: CLEANUP_TAGS_SERVICE_PARAMS.merge('disable_timeout' => disable_timeout)
)
result = service.execute
return true if result[:status] == :success
log_error(error_message(container_repository, 'error in deleting tags'))
false
end
def destroy_container_repository(container_repository)
return true if container_repository.destroy
log_error(error_message(container_repository, container_repository.errors.full_messages.join('. ')))
false
end
def error_message(container_repository, message)
"Container repository with ID: #{container_repository.id} and path: #{container_repository.path}" \
" failed with message: #{message}"
end
end
end
end
|