Commit 8c021a2e authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Kamil Trzcinski

EE specific changes for multiple artifacts

parent e5580913
class JobArtifactUploader < GitlabUploader
storage :file
class JobArtifactUploader < ObjectStoreUploader
storage_options Gitlab.config.artifacts
def self.local_artifacts_store
def self.local_store_path
Gitlab.config.artifacts.path
end
......@@ -9,30 +9,22 @@ class JobArtifactUploader < GitlabUploader
File.join(self.local_artifacts_store, 'tmp/uploads/')
end
def initialize(artifact, _field)
@artifact = artifact
end
def size
return super if @artifact.size.nil?
@artifact.size
end
return super if subject.size.nil?
def store_dir
File.join(self.class.local_artifacts_store, default_path)
subject.size
end
private
def default_path
creation_date = @artifact.created_at.utc.strftime('%Y_%m_%d')
creation_date = subject.created_at.utc.strftime('%Y_%m_%d')
File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
creation_date, @artifact.job_id.to_s, @artifact.id.to_s)
creation_date, subject.job_id.to_s, subject.id.to_s)
end
def disk_hash
@disk_hash ||= Digest::SHA2.hexdigest(@artifact.project_id.to_s)
@disk_hash ||= Digest::SHA2.hexdigest(subject.project_id.to_s)
end
end
class AddFileStoreJobArtifacts < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
add_column(:ci_job_artifacts, :file_store, :integer)
# Run on an empty table, but else Rubocop is not happy
add_concurrent_index(:ci_job_artifacts, :file_store)
end
def down
drop_column(:ci_job_artifacts, :file_store)
end
end
......@@ -404,8 +404,10 @@ ActiveRecord::Schema.define(version: 20171124165823) do
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.string "file"
t.integer "file_store"
end
add_index "ci_job_artifacts", ["file_store"], name: "index_ci_job_artifacts_on_file_store", using: :btree
add_index "ci_job_artifacts", ["file_type"], name: "index_ci_job_artifacts_on_file_type", using: :btree
add_index "ci_job_artifacts", ["job_id"], name: "index_ci_job_artifacts_on_job_id", using: :btree
add_index "ci_job_artifacts", ["project_id"], name: "index_ci_job_artifacts_on_project_id", using: :btree
......
......@@ -4,6 +4,11 @@ FactoryGirl.define do
factory :ci_job_artifact, class: Ci::JobArtifact do
job factory: :ci_build
file_type :archive
file_store JobArtifactUploader::LOCAL_STORE
trait :remote_store do
file_store JobArtifactUploader::REMOTE_STORE
end
after :build do |artifact|
artifact.project ||= artifact.job.project
......
......@@ -2,7 +2,7 @@ require 'rails_helper'
describe ArtifactUploader do
let(:store) { described_class::LOCAL_STORE }
set(:job) { create(:ci_build, artifacts_file_store: store) }
let(:job) { create(:ci_build, artifacts_file_store: store) }
let(:uploader) { described_class.new(job, :artifacts_file) }
let(:local_path) { Gitlab.config.artifacts.path }
......@@ -66,11 +66,5 @@ describe ArtifactUploader do
subject { uploader.filename }
it { is_expected.to be_nil }
context 'with artifacts' do
let(:job) { create(:ci_build, :artifacts) }
it { is_expected.not_to be_nil }
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