Commit 272af7a2 authored by Micaël Bergeron's avatar Micaël Bergeron

porting spec/support/db

parent b47d64b0
...@@ -2,6 +2,7 @@ module Ci ...@@ -2,6 +2,7 @@ module Ci
class JobArtifact < ActiveRecord::Base class JobArtifact < ActiveRecord::Base
prepend EE::Ci::JobArtifact prepend EE::Ci::JobArtifact
include AfterCommitQueue include AfterCommitQueue
include ObjectStorage::BackgroundMove
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
belongs_to :project belongs_to :project
...@@ -9,6 +10,8 @@ module Ci ...@@ -9,6 +10,8 @@ module Ci
before_save :set_size, if: :file_changed? before_save :set_size, if: :file_changed?
scope :with_files_stored_locally, -> { where(file_store: [nil, ::JobArtifactUploader::Store::LOCAL]) }
mount_uploader :file, JobArtifactUploader mount_uploader :file, JobArtifactUploader
delegate :exists?, :open, to: :file delegate :exists?, :open, to: :file
...@@ -23,6 +26,10 @@ module Ci ...@@ -23,6 +26,10 @@ module Ci
self.where(project: project).sum(:size) self.where(project: project).sum(:size)
end end
def local_store?
[nil, ::JobArtifactUploader::Store::LOCAL].include?(self.file_store)
end
def set_size def set_size
self.size = file.size self.size = file.size
end end
......
class LfsObject < ActiveRecord::Base class LfsObject < ActiveRecord::Base
prepend EE::LfsObject prepend EE::LfsObject
include AfterCommitQueue include AfterCommitQueue
include ObjectStorage::BackgroundMove
has_many :lfs_objects_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :lfs_objects_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :projects, through: :lfs_objects_projects has_many :projects, through: :lfs_objects_projects
scope :with_files_stored_locally, -> { where(file_store: [nil, LfsObjectUploader::Store::LOCAL]) }
validates :oid, presence: true, uniqueness: true validates :oid, presence: true, uniqueness: true
mount_uploader :file, LfsObjectUploader mount_uploader :file, LfsObjectUploader
...@@ -19,6 +22,10 @@ class LfsObject < ActiveRecord::Base ...@@ -19,6 +22,10 @@ class LfsObject < ActiveRecord::Base
projects.exists?(project.lfs_storage_project.id) projects.exists?(project.lfs_storage_project.id)
end end
def local_store?
[nil, LfsObjectUploader::Store::LOCAL].include?(self.file_store)
end
def self.destroy_unreferenced def self.destroy_unreferenced
joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id") joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id")
.where(lfs_objects_projects: { id: nil }) .where(lfs_objects_projects: { id: nil })
......
...@@ -93,11 +93,12 @@ _The artifacts are stored by default in ...@@ -93,11 +93,12 @@ _The artifacts are stored by default in
9.4 lacks this feature. 9.4 lacks this feature.
> Available in [GitLab Premium](https://about.gitlab.com/products/) and > Available in [GitLab Premium](https://about.gitlab.com/products/) and
[GitLab.com Silver](https://about.gitlab.com/gitlab-com/). [GitLab.com Silver](https://about.gitlab.com/gitlab-com/).
> Since version 10.6, available in [GitLab CE](https://about.gitlab.com/products/)
If you don't want to use the local disk where GitLab is installed to store the If you don't want to use the local disk where GitLab is installed to store the
artifacts, you can use an object storage like AWS S3 instead. artifacts, you can use an object storage like AWS S3 instead.
This configuration relies on valid AWS credentials to be configured already. This configuration relies on valid AWS credentials to be configured already.
Use an [Object storage option][ee-os] like AWS S3 to store job artifacts. Use an [Object storage option][os] like AWS S3 to store job artifacts.
### Object Storage Settings ### Object Storage Settings
...@@ -313,4 +314,4 @@ memory and disk I/O. ...@@ -313,4 +314,4 @@ memory and disk I/O.
[eep]: https://about.gitlab.com/products/ "GitLab Premium" [eep]: https://about.gitlab.com/products/ "GitLab Premium"
[ee-1762]: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1762 [ee-1762]: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1762
[browsable]: ../user/project/pipelines/job_artifacts.md#browsing-job-artifacts [browsable]: ../user/project/pipelines/job_artifacts.md#browsing-job-artifacts
[ee-os]: https://docs.gitlab.com/ee/administration/job_artifacts.html#using-object-storage [os]: https://docs.gitlab.com/administration/job_artifacts.html#using-object-storage
...@@ -21,7 +21,6 @@ There are various configuration options to help GitLab server administrators: ...@@ -21,7 +21,6 @@ There are various configuration options to help GitLab server administrators:
### Omnibus packages ### Omnibus packages
In `/etc/gitlab/gitlab.rb`: In `/etc/gitlab/gitlab.rb`:
```ruby ```ruby
...@@ -48,6 +47,7 @@ In `config/gitlab.yml`: ...@@ -48,6 +47,7 @@ In `config/gitlab.yml`:
## Setting up S3 compatible object storage ## Setting up S3 compatible object storage
> **Note:** [Introduced][ee-2760] in [GitLab Premium][eep] 10.0. > **Note:** [Introduced][ee-2760] in [GitLab Premium][eep] 10.0.
> Available in [GitLab CE][ce] 10.6
It is possible to store LFS objects on remote object storage instead of on a local disk. It is possible to store LFS objects on remote object storage instead of on a local disk.
......
...@@ -7,15 +7,7 @@ module EE ...@@ -7,15 +7,7 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
include ObjectStorage::BackgroundMove
after_destroy :log_geo_event after_destroy :log_geo_event
scope :with_files_stored_locally, -> { where(file_store: [nil, ::JobArtifactUploader::Store::LOCAL]) }
end
def local_store?
[nil, ::JobArtifactUploader::Store::LOCAL].include?(self.file_store)
end end
private private
......
...@@ -7,16 +7,7 @@ module EE ...@@ -7,16 +7,7 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
include ObjectStorage::BackgroundMove
after_destroy :log_geo_event after_destroy :log_geo_event
scope :with_files_stored_locally, -> { where(file_store: [nil, LfsObjectUploader::Store::LOCAL]) }
scope :with_files_stored_remotely, -> { where(file_store: ObjectStorage::Store::REMOTE) }
end
def local_store?
[nil, LfsObjectUploader::Store::LOCAL].include?(self.file_store)
end end
private private
......
require 'rake_helper' require 'rake_helper'
describe 'gitlab:uploads rake tasks' do describe 'gitlab:uploads:check rake tasks' do
describe 'check' do let!(:upload) { create(:upload, path: Rails.root.join('spec/fixtures/banana_sample.gif')) }
let!(:upload) { create(:upload, path: Rails.root.join('spec/fixtures/banana_sample.gif')) }
before do before do
Rake.application.rake_require('tasks/gitlab/uploads/check') Rake.application.rake_require 'tasks/gitlab/uploads/check'
stub_env('VERBOSE' => 'true') end
end
it 'outputs the integrity check for each batch' do it 'outputs the integrity check for each uploaded file' do
expect { run_rake_task('gitlab:uploads:check') }.to output(/Failures: 0/).to_stdout expect { run_rake_task('gitlab:uploads:check') }.to output(/Checking file \(#{upload.id}\): #{Regexp.quote(upload.absolute_path)}/).to_stdout
end end
it 'errors out about missing files on the file system' do it 'errors out about missing files on the file system' do
missing_upload = create(:upload) create(:upload)
expect { run_rake_task('gitlab:uploads:check') }.to output(/No such file.*#{Regexp.quote(missing_upload.absolute_path)}/).to_stdout expect { run_rake_task('gitlab:uploads:check') }.to output(/File does not exist on the file system/).to_stdout
end end
it 'errors out about invalid checksum' do it 'errors out about invalid checksum' do
upload.update_column(:checksum, '01a3156db2cf4f67ec823680b40b7302f89ab39179124ad219f94919b8a1769e') upload.update_column(:checksum, '01a3156db2cf4f67ec823680b40b7302f89ab39179124ad219f94919b8a1769e')
expect { run_rake_task('gitlab:uploads:check') }.to output(/Checksum mismatch/).to_stdout expect { run_rake_task('gitlab:uploads:check') }.to output(/File checksum \(9e697aa09fe196909813ee36103e34f721fe47a5fdc8aac0e4e4ac47b9b38282\) does not match the one in the database \(#{upload.checksum}\)/).to_stdout
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