Commit 6a0db429 authored by Stan Hu's avatar Stan Hu

Merge branch '227808-improve-container-registry-client-supports-tag-delete' into 'master'

Improve the container registry client

See merge request gitlab-org/gitlab!46989
parents f3cafdff 53727c9c
---
title: Improve the container registry client tags delete method
merge_request: 46989
author:
type: changed
...@@ -15,6 +15,7 @@ module ContainerRegistry ...@@ -15,6 +15,7 @@ module ContainerRegistry
CONTAINER_IMAGE_V1_TYPE = 'application/vnd.docker.container.image.v1+json' CONTAINER_IMAGE_V1_TYPE = 'application/vnd.docker.container.image.v1+json'
REGISTRY_VERSION_HEADER = 'gitlab-container-registry-version' REGISTRY_VERSION_HEADER = 'gitlab-container-registry-version'
REGISTRY_FEATURES_HEADER = 'gitlab-container-registry-features' REGISTRY_FEATURES_HEADER = 'gitlab-container-registry-features'
REGISTRY_TAG_DELETE_FEATURE = 'tag_delete'
ACCEPTED_TYPES = [DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE, OCI_MANIFEST_V1_TYPE].freeze ACCEPTED_TYPES = [DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE, OCI_MANIFEST_V1_TYPE].freeze
...@@ -25,8 +26,6 @@ module ContainerRegistry ...@@ -25,8 +26,6 @@ module ContainerRegistry
registry_config = Gitlab.config.registry registry_config = Gitlab.config.registry
return false unless registry_config.enabled && registry_config.api_url.present? return false unless registry_config.enabled && registry_config.api_url.present?
return true if ::Gitlab.com?
token = Auth::ContainerRegistryAuthenticationService.access_token([], []) token = Auth::ContainerRegistryAuthenticationService.access_token([], [])
client = new(registry_config.api_url, token: token) client = new(registry_config.api_url, token: token)
client.supports_tag_delete? client.supports_tag_delete?
...@@ -81,6 +80,9 @@ module ContainerRegistry ...@@ -81,6 +80,9 @@ module ContainerRegistry
# the DELETE method in the Allow header. Others reply with an 404 Not Found. # the DELETE method in the Allow header. Others reply with an 404 Not Found.
def supports_tag_delete? def supports_tag_delete?
strong_memoize(:supports_tag_delete) do strong_memoize(:supports_tag_delete) do
registry_features = Gitlab::CurrentSettings.container_registry_features || []
next true if ::Gitlab.com? && registry_features.include?(REGISTRY_TAG_DELETE_FEATURE)
response = faraday.run_request(:options, '/v2/name/tags/reference/tag', '', {}) response = faraday.run_request(:options, '/v2/name/tags/reference/tag', '', {})
response.success? && response.headers['allow']&.include?('DELETE') response.success? && response.headers['allow']&.include?('DELETE')
end end
......
This diff is collapsed.
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