Commit c10e910d authored by Stan Hu's avatar Stan Hu

Fix dependency proxy not working with object storage

Previously the dependency proxy controller would save the blob into
object storage, but the `file_store` column was never updated. As a
result, blobs could not be downloaded because it appeared to GitLab as
though the files never made it to object storage.

Just as we do with CI job artifacts, LFS files, and project exports, we
need to update this column after the CarrierWave-mounted file is saved.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/231563
parent 490fd60f
---
title: Fix dependency proxy not working with object storage
merge_request: 37878
author:
type: fixed
......@@ -9,6 +9,8 @@ class DependencyProxy::Blob < ApplicationRecord
mount_uploader :file, DependencyProxy::FileUploader
after_save :update_file_store, if: :saved_change_to_file?
def self.total_size
sum(:size)
end
......@@ -16,4 +18,10 @@ class DependencyProxy::Blob < ApplicationRecord
def self.find_or_build(file_name)
find_or_initialize_by(file_name: file_name)
end
def update_file_store
# The file.object_store is set during `uploader.store!`
# which happens after object is inserted/updated
self.update_column(:file_store, file.object_store)
end
end
......@@ -36,4 +36,30 @@ RSpec.describe DependencyProxy::Blob, type: :model do
expect(described_class.find_or_build(blob.file_name)).to eq(blob)
end
end
describe 'file is being stored' do
subject { create(:dependency_proxy_blob) }
context 'when existing object has local store' do
it 'is stored locally' do
expect(subject.file_store).to be(ObjectStorage::Store::LOCAL)
expect(subject.file).to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::LOCAL)
end
end
context 'when direct upload is enabled' do
before do
stub_dependency_proxy_object_storage(direct_upload: true)
end
context 'when file is stored' do
it 'is stored remotely' do
expect(subject.file_store).to eq(ObjectStorage::Store::REMOTE)
expect(subject.file).not_to be_file_storage
expect(subject.file.object_store).to eq(ObjectStorage::Store::REMOTE)
end
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