Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ebe9381c
Commit
ebe9381c
authored
Nov 25, 2019
by
Giorgenes Gelatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor tag delete code quality
parent
00ed8ef7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
17 deletions
+21
-17
app/services/projects/container_repository/cleanup_tags_service.rb
...ces/projects/container_repository/cleanup_tags_service.rb
+2
-2
app/services/projects/container_repository/delete_tags_service.rb
...ices/projects/container_repository/delete_tags_service.rb
+19
-15
No files found.
app/services/projects/container_repository/cleanup_tags_service.rb
View file @
ebe9381c
...
...
@@ -26,13 +26,13 @@ module Projects
def
delete_tags
(
tags_to_delete
,
tags_by_digest
)
deleted_digests
=
group_by_digest
(
tags_to_delete
).
select
do
|
digest
,
tags
|
delete_tag_digest
(
digest
,
tags
,
tags_by_digest
[
digest
])
delete_tag_digest
(
tags
,
tags_by_digest
[
digest
])
end
deleted_digests
.
values
.
flatten
end
def
delete_tag_digest
(
digest
,
tags
,
other_tags
)
def
delete_tag_digest
(
tags
,
other_tags
)
# Issue: https://gitlab.com/gitlab-org/gitlab-foss/issues/21405
# we have to remove all tags due
# to Docker Distribution bug unable
...
...
app/services/projects/container_repository/delete_tags_service.rb
View file @
ebe9381c
...
...
@@ -24,32 +24,36 @@ module Projects
dummy_manifest
=
container_repository
.
client
.
generate_empty_manifest
(
container_repository
.
path
)
return
error
(
'could not generate manifest'
)
if
dummy_manifest
.
nil?
# update the manifests of the tags with the new dummy image
deleted_tags
=
[]
tag_digests
=
[]
deleted_tags
=
replace_tag_manifests
(
container_repository
,
dummy_manifest
,
tag_names
)
# Deletes the dummy image
# All created tag digests are the same since they all have the same dummy image.
# a single delete is sufficient to remove all tags with it
if
deleted_tags
.
any?
&&
container_repository
.
delete_tag_by_digest
(
deleted_tags
.
values
.
first
)
success
(
deleted:
deleted_tags
.
keys
)
else
error
(
'could not delete tags'
)
end
end
# update the manifests of the tags with the new dummy image
def
replace_tag_manifests
(
container_repository
,
dummy_manifest
,
tag_names
)
deleted_tags
=
{}
tag_names
.
each
do
|
name
|
digest
=
container_repository
.
client
.
put_tag
(
container_repository
.
path
,
name
,
dummy_manifest
)
next
unless
digest
deleted_tags
<<
name
tag_digests
<<
digest
deleted_tags
[
name
]
=
digest
end
# make sure the digests are the same (it should always be)
tag_digests
.
uniq!
digests
=
deleted_tags
.
values
.
uniq
# rubocop: disable CodeReuse/ActiveRecord
Gitlab
::
Sentry
.
track_exception
(
ArgumentError
.
new
(
'multiple tag digests'
))
if
tag_
digests
.
many?
Gitlab
::
Sentry
.
track_exception
(
ArgumentError
.
new
(
'multiple tag digests'
))
if
digests
.
many?
# Deletes the dummy image
# All created tag digests are the same since they all have the same dummy image.
# a single delete is sufficient to remove all tags with it
if
tag_digests
.
any?
&&
container_repository
.
delete_tag_by_digest
(
tag_digests
.
first
)
success
(
deleted:
deleted_tags
)
else
error
(
'could not delete tags'
)
end
deleted_tags
end
end
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