Commit cf4e99d0 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '196158-fix-no-redirect-case-for-docker-blob-replication' into 'master'

Fix Docker repository sync for local storage

See merge request gitlab-org/gitlab!22981
parents aea81378 981f932a
---
title: 'Geo: Fix Docker repository synchronization for local storage'
merge_request: 22981
author:
type: fixed
......@@ -42,13 +42,16 @@ module EE
def pull_blob(name, digest)
file = Tempfile.new("blob-#{digest}")
blob_url = "/v2/#{name}/blobs/#{digest}"
response = HTTP
.headers({ "Authorization" => "Bearer #{@options[:token]}" }) # rubocop:disable Gitlab/ModuleWithInstanceVariables
.get("#{@base_uri}/v2/#{name}/blobs/#{digest}") # rubocop:disable Gitlab/ModuleWithInstanceVariables
.get(::Gitlab::Utils.append_path(@base_uri, blob_url)) # rubocop:disable Gitlab/ModuleWithInstanceVariables
raise Error.new("Pull Blob error: #{response.body}") unless response.status.redirect?
if response.status.redirect?
response = HTTP.get(response['Location'])
end
response = HTTP.get(response['Location'])
response.body.each do |chunk|
file.binmode
file.write(chunk)
......
......@@ -146,7 +146,7 @@ describe ContainerRegistry::Client do
.to_return(status: 302, headers: { "Location" => 'http://download-link.com' })
end
it 'GET "/v2/:name/blobs/:reference' do
it 'downloads file successfully when' do
stub_request(:get, "http://download-link.com/")
.to_return(status: 200)
......@@ -173,5 +173,30 @@ describe ContainerRegistry::Client do
expect { client.pull_blob('group/test', 'e2312abc') }.to raise_error(EE::ContainerRegistry::Client::Error)
end
context 'when primary_api_url is specified with trailing slash' do
let(:client) { described_class.new("http://registry/", options) }
it 'builds correct URL' do
stub_request(:get, "http://registry//v2/group/test/blobs/e2312abc")
.with(headers: auth_headers)
.to_return(status: 500)
stub_request(:get, "http://download-link.com/")
.to_return(status: 200)
expect(client.pull_blob('group/test', 'e2312abc')).to be_a_kind_of(Tempfile)
end
end
context 'direct link to download, no redirect' do
it 'downloads blob successfully' do
stub_request(:get, "http://registry/v2/group/test/blobs/e2312abc")
.with(headers: auth_headers)
.to_return(status: 200)
expect(client.pull_blob('group/test', 'e2312abc')).to be_a_kind_of(Tempfile)
end
end
end
end
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