2017-11-07 04:18:32 -05:00
|
|
|
class JobArtifactUploader < GitlabUploader
|
|
|
|
storage :file
|
|
|
|
|
2017-11-23 12:51:20 -05:00
|
|
|
def self.local_store_path
|
2017-11-07 04:18:32 -05:00
|
|
|
Gitlab.config.artifacts.path
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.artifacts_upload_path
|
2017-11-23 12:51:20 -05:00
|
|
|
File.join(self.local_store_path, 'tmp/uploads/')
|
2017-11-07 04:18:32 -05:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
2017-11-23 12:51:20 -05:00
|
|
|
def store_dir
|
|
|
|
default_local_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def cache_dir
|
|
|
|
File.join(self.class.local_store_path, 'tmp/cache')
|
|
|
|
end
|
|
|
|
|
|
|
|
def work_dir
|
|
|
|
File.join(self.class.local_store_path, 'tmp/work')
|
|
|
|
end
|
|
|
|
|
2017-11-07 04:18:32 -05:00
|
|
|
private
|
|
|
|
|
2017-11-23 12:51:20 -05:00
|
|
|
def default_local_path
|
|
|
|
File.join(self.class.local_store_path, default_path)
|
|
|
|
end
|
|
|
|
|
2017-09-21 04:34:12 -04:00
|
|
|
def default_path
|
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
|