Commit 981f932a authored by Valery Sizov's avatar Valery Sizov Committed by Douglas Barbosa Alexandre

Fix Docker repository sync for direct link case

When local storage is used we get a direct link without redirect
it used to work but it was broken by
https://gitlab.com/gitlab-org/gitlab/merge_requests/21068.
It wasn't noticed because this bug was disguised by another small bug -
if primaty_api_url was specified with trailing slash it worked well.
parent aea81378
---
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