diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 11:41:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-14 11:41:52 +0300 |
commit | 585826cb22ecea5998a2c2a4675735c94bdeedac (patch) | |
tree | 5b05f0b30d33cef48963609e8a18a4dff260eab3 /lib/container_registry | |
parent | df221d036e5d0c6c0ee4d55b9c97f481ee05dee8 (diff) |
Add latest changes from gitlab-org/gitlab@16-6-stable-eev16.6.0-rc42
Diffstat (limited to 'lib/container_registry')
-rw-r--r-- | lib/container_registry/client.rb | 8 | ||||
-rw-r--r-- | lib/container_registry/gitlab_api_client.rb | 20 | ||||
-rw-r--r-- | lib/container_registry/tag.rb | 17 |
3 files changed, 26 insertions, 19 deletions
diff --git a/lib/container_registry/client.rb b/lib/container_registry/client.rb index e2a1b8296f6..580ba2bdc0d 100644 --- a/lib/container_registry/client.rb +++ b/lib/container_registry/client.rb @@ -78,13 +78,9 @@ module ContainerRegistry delete_if_exists("/v2/#{name}/manifests/#{reference}") end - 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 + # an OPTIONS request to /v2/<name>/manifests/<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. @@ -93,7 +89,7 @@ module ContainerRegistry registry_features = Gitlab::CurrentSettings.container_registry_features || [] next true if ::Gitlab.com_except_jh? && registry_features.include?(REGISTRY_TAG_DELETE_FEATURE) - response = faraday.run_request(:options, '/v2/name/tags/reference/tag', '', {}) + response = faraday.run_request(:options, '/v2/name/manifests/tag', '', {}) response.success? && response.headers['allow']&.include?('DELETE') end end diff --git a/lib/container_registry/gitlab_api_client.rb b/lib/container_registry/gitlab_api_client.rb index bd833ec00af..9b6c37da847 100644 --- a/lib/container_registry/gitlab_api_client.rb +++ b/lib/container_registry/gitlab_api_client.rb @@ -103,7 +103,7 @@ module ContainerRegistry end end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#compliance-check + # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/spec/gitlab/api.md#compliance-check def supports_gitlab_api? strong_memoize(:supports_gitlab_api) do registry_features = Gitlab::CurrentSettings.container_registry_features || [] @@ -116,19 +116,19 @@ module ContainerRegistry end end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#import-repository + # Deprecated. Will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/409873. def pre_import_repository(path) response = start_import_for(path, pre: true) IMPORT_RESPONSES.fetch(response.status, :error) end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#import-repository + # Deprecated. Will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/409873. def import_repository(path) response = start_import_for(path, pre: false) IMPORT_RESPONSES.fetch(response.status, :error) end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#cancel-repository-import + # Deprecated. Will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/409873. def cancel_repository_import(path, force: false) response = with_import_token_faraday do |faraday_client| faraday_client.delete(import_url_for(path)) do |req| @@ -142,7 +142,7 @@ module ContainerRegistry { status: status, migration_state: actual_state } end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#get-repository-import-status + # Deprecated. Will be removed as part of https://gitlab.com/gitlab-org/gitlab/-/issues/409873. def import_status(path) with_import_token_faraday do |faraday_client| response = faraday_client.get(import_url_for(path)) @@ -156,7 +156,7 @@ module ContainerRegistry end end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#get-repository-details + # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/spec/gitlab/api.md#get-repository-details def repository_details(path, sizing: nil) with_token_faraday do |faraday_client| req = faraday_client.get("#{GITLAB_REPOSITORIES_PATH}/#{path}/") do |req| @@ -169,7 +169,7 @@ module ContainerRegistry end end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#list-repository-tags + # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/spec/gitlab/api.md#list-repository-tags def tags(path, page_size: 100, last: nil, before: nil, name: nil, sort: nil) limited_page_size = [page_size, MAX_TAGS_PAGE_SIZE].min with_token_faraday do |faraday_client| @@ -178,7 +178,7 @@ module ContainerRegistry req.params['n'] = limited_page_size req.params['last'] = last if last req.params['before'] = before if before - req.params['name'] = name if name + req.params['name'] = name if name.present? req.params['sort'] = sort if sort end @@ -202,7 +202,7 @@ module ContainerRegistry end end - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#list-sub-repositories + # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/spec/gitlab/api.md#list-sub-repositories def sub_repositories_with_tag(path, page_size: 100, last: nil) limited_page_size = [page_size, MAX_REPOSITORIES_PAGE_SIZE].min @@ -235,7 +235,7 @@ module ContainerRegistry # Given a path 'group/subgroup/project' and name 'newname', # with a successful rename, it will be 'group/subgroup/newname' - # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#rename-base-repository + # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs/spec/gitlab/api.md#rename-base-repository def rename_base_repository_path(path, name:, dry_run: false) with_token_faraday do |faraday_client| url = "#{GITLAB_REPOSITORIES_PATH}/#{path}/" diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb index bf44b74cf7b..70742e8bd38 100644 --- a/lib/container_registry/tag.rb +++ b/lib/container_registry/tag.rb @@ -5,16 +5,25 @@ module ContainerRegistry include Gitlab::Utils::StrongMemoize attr_reader :repository, :name, :updated_at - attr_writer :created_at + attr_writer :created_at, :manifest_digest, :revision, :total_size delegate :registry, :client, to: :repository - delegate :revision, :short_revision, to: :config_blob, allow_nil: true def initialize(repository, name) @repository = repository @name = name end + def revision + @revision || config_blob&.revision + end + + def short_revision + return unless revision + + revision[0..8] + end + def valid? manifest.present? end @@ -53,7 +62,7 @@ module ContainerRegistry def digest strong_memoize(:digest) do - client.repository_tag_digest(repository.path, name) + @manifest_digest || client.repository_tag_digest(repository.path, name) end end @@ -126,6 +135,8 @@ module ContainerRegistry # rubocop: disable CodeReuse/ActiveRecord def total_size + return @total_size if @total_size + return unless layers layers.sum(&:size) if v2? |