summaryrefslogtreecommitdiff
path: root/lib/container_registry
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-12 15:09:37 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-12 15:09:37 +0000
commit2c89e169769ead722394a79ed67fcd08e96863dd (patch)
tree0dadb576846c484475b895f75fab41f71cdb952e /lib/container_registry
parentbd497e352ebd279536ae11855871162e82a3f88c (diff)
downloadgitlab-ce-2c89e169769ead722394a79ed67fcd08e96863dd.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/container_registry')
-rw-r--r--lib/container_registry/client.rb33
-rw-r--r--lib/container_registry/tag.rb2
2 files changed, 28 insertions, 7 deletions
diff --git a/lib/container_registry/client.rb b/lib/container_registry/client.rb
index bc0347f6ea1..12f7f04634f 100644
--- a/lib/container_registry/client.rb
+++ b/lib/container_registry/client.rb
@@ -6,6 +6,8 @@ require 'digest'
module ContainerRegistry
class Client
+ include Gitlab::Utils::StrongMemoize
+
attr_accessor :uri
DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE = 'application/vnd.docker.distribution.manifest.v2+json'
@@ -35,10 +37,25 @@ module ContainerRegistry
response.headers['docker-content-digest'] if response.success?
end
- def delete_repository_tag(name, reference)
- result = faraday.delete("/v2/#{name}/manifests/#{reference}")
+ def delete_repository_tag_by_digest(name, reference)
+ delete_if_exists("/v2/#{name}/manifests/#{reference}")
+ end
- result.success? || result.status == 404
+ def delete_repository_tag_by_name(name, reference)
+ delete_if_exists("/v2/#{name}/tags/reference/#{reference}")
+ end
+
+ # Check if the registry supports tag deletion. This is only supported by the
+ # GitLab registry fork. The fastest and safest way to check this is to send
+ # an OPTIONS request to /v2/<name>/tags/reference/<tag>, using a random
+ # repository name and tag (the registry won't check if they exist).
+ # Registries that support tag deletion will reply with a 200 OK and include
+ # the DELETE method in the Allow header. Others reply with an 404 Not Found.
+ def supports_tag_delete?
+ strong_memoize(:supports_tag_delete) do
+ response = faraday.run_request(:options, '/v2/name/tags/reference/tag', '', {})
+ response.success? && response.headers['allow']&.include?('DELETE')
+ end
end
def upload_raw_blob(path, blob)
@@ -86,9 +103,7 @@ module ContainerRegistry
end
def delete_blob(name, digest)
- result = faraday.delete("/v2/#{name}/blobs/#{digest}")
-
- result.success? || result.status == 404
+ delete_if_exists("/v2/#{name}/blobs/#{digest}")
end
def put_tag(name, reference, manifest)
@@ -163,6 +178,12 @@ module ContainerRegistry
conn.adapter :net_http
end
end
+
+ def delete_if_exists(path)
+ result = faraday.delete(path)
+
+ result.success? || result.status == 404
+ end
end
end
diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb
index 3c308258a3f..e1a2891e43a 100644
--- a/lib/container_registry/tag.rb
+++ b/lib/container_registry/tag.rb
@@ -118,7 +118,7 @@ module ContainerRegistry
def unsafe_delete
return unless digest
- client.delete_repository_tag(repository.path, digest)
+ client.delete_repository_tag_by_digest(repository.path, digest)
end
end
end