Commit 9a794c07 authored by Steve Abrams's avatar Steve Abrams

Manifest content-type to be stored in obj storage

Update dependency proxy uploader to set the
content-type based on what is returned from
the original request.
parent 6e55e330
......@@ -20,8 +20,14 @@ class Groups::DependencyProxyForContainersController < Groups::ApplicationContro
response.headers['Content-Length'] = result[:manifest].size
response.headers['Docker-Distribution-Api-Version'] = DependencyProxy::DISTRIBUTION_API_VERSION
response.headers['Etag'] = "\"#{result[:manifest].digest}\""
send_upload(result[:manifest].file, send_params: { type: result[:manifest].content_type })
content_type = result[:manifest].content_type
send_upload(
result[:manifest].file,
proxy: true,
redirect_params: { query: { 'response-content-type' => content_type } },
send_params: { type: content_type }
)
else
render status: result[:http_status], json: result[:message]
end
......
......@@ -3,6 +3,7 @@
class DependencyProxy::FileUploader < GitlabUploader
include ObjectStorage::Concern
before :cache, :set_content_type
storage_options Gitlab.config.dependency_proxy
alias_method :upload, :model
......@@ -17,6 +18,17 @@ class DependencyProxy::FileUploader < GitlabUploader
private
# Docker manifests return a custom content type
# GCP will only use the content-type that is stored with the file
# and will not allow it to be overwritten when downloaded
# so we must store the custom content type in object storage.
# This does not apply to DependencyProxy::Blob uploads.
def set_content_type(file)
return unless model.class == DependencyProxy::Manifest
file.content_type = model.content_type
end
def dynamic_segment
Gitlab::HashedPath.new('dependency_proxy', model.group_id, 'files', model.id, root_hash: model.group_id)
end
......
......@@ -2,25 +2,43 @@
require 'spec_helper'
RSpec.describe DependencyProxy::FileUploader do
let(:blob) { create(:dependency_proxy_blob) }
let(:uploader) { described_class.new(blob, :file) }
let(:path) { Gitlab.config.dependency_proxy.storage_path }
describe 'DependencyProxy::Blob uploader' do
let_it_be(:blob) { create(:dependency_proxy_blob) }
let_it_be(:path) { Gitlab.config.dependency_proxy.storage_path }
let(:uploader) { described_class.new(blob, :file) }
subject { uploader }
subject { uploader }
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}],
cache_dir: %r[/dependency_proxy/tmp/cache],
work_dir: %r[/dependency_proxy/tmp/work]
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}],
cache_dir: %r[/dependency_proxy/tmp/cache],
work_dir: %r[/dependency_proxy/tmp/work]
context 'object store is remote' do
before do
stub_dependency_proxy_object_storage
end
context 'object store is remote' do
before do
stub_dependency_proxy_object_storage
include_context 'with storage', described_class::Store::REMOTE
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}]
end
end
include_context 'with storage', described_class::Store::REMOTE
describe 'DependencyProxy::Manifest uploader' do
let_it_be(:manifest) { create(:dependency_proxy_manifest) }
let_it_be(:initial_content_type) { 'application/json' }
let_it_be(:fixture_file) { fixture_file_upload('spec/fixtures/dependency_proxy/manifest', initial_content_type) }
let(:uploader) { described_class.new(manifest, :file) }
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}]
subject { uploader }
it 'will change upload file content type to match the model content type', :aggregate_failures do
uploader.cache!(fixture_file)
expect(uploader.file.content_type).to eq(manifest.content_type)
expect(uploader.file.content_type).not_to eq(initial_content_type)
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