2018-02-02 08:59:43 -05:00
|
|
|
class JobArtifactUploader < GitlabUploader
|
2018-02-06 09:18:32 -05:00
|
|
|
prepend EE::JobArtifactUploader
|
2018-02-02 08:59:43 -05:00
|
|
|
extend Workhorse::UploadPath
|
|
|
|
include ObjectStorage::Concern
|
2017-11-07 04:18:32 -05:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
storage_options Gitlab.config.artifacts
|
2017-11-07 04:18:32 -05:00
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def size
|
2017-11-23 10:57:27 -05:00
|
|
|
return super if model.size.nil?
|
2017-09-21 04:34:12 -04:00
|
|
|
|
2017-11-23 10:57:27 -05:00
|
|
|
model.size
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
def store_dir
|
|
|
|
dynamic_segment
|
|
|
|
end
|
|
|
|
|
2018-02-06 09:18:32 -05:00
|
|
|
def open
|
|
|
|
raise 'Only File System is supported' unless file_storage?
|
|
|
|
|
|
|
|
File.open(path, "rb") if path
|
|
|
|
end
|
|
|
|
|
2017-11-07 04:18:32 -05:00
|
|
|
private
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
def dynamic_segment
|
2017-11-23 10:57:27 -05:00
|
|
|
creation_date = model.created_at.utc.strftime('%Y_%m_%d')
|
2017-09-21 04:34:12 -04:00
|
|
|
|
|
|
|
File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
|
2017-11-23 10:57:27 -05:00
|
|
|
creation_date, model.job_id.to_s, model.id.to_s)
|
2017-11-07 04:18:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def disk_hash
|
2017-11-23 10:57:27 -05:00
|
|
|
@disk_hash ||= Digest::SHA2.hexdigest(model.project_id.to_s)
|
2017-09-21 04:34:12 -04:00
|
|
|
end
|
|
|
|
end
|