Commit b5f5b6dc authored by Shinya Maeda's avatar Shinya Maeda

Add checksum to ci_job_artifacts

parent 2e87923d
...@@ -6,6 +6,7 @@ module Ci ...@@ -6,6 +6,7 @@ module Ci
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
before_save :set_size, if: :file_changed? before_save :set_size, if: :file_changed?
before_save :set_checksum, if: :file_changed?
mount_uploader :file, JobArtifactUploader mount_uploader :file, JobArtifactUploader
...@@ -25,6 +26,10 @@ module Ci ...@@ -25,6 +26,10 @@ module Ci
self.size = file.size self.size = file.size
end end
def set_checksum
self.checksum = file.checksum
end
def expire_in def expire_in
expire_at - Time.now if expire_at expire_at - Time.now if expire_at
end end
......
...@@ -9,6 +9,12 @@ class JobArtifactUploader < GitlabUploader ...@@ -9,6 +9,12 @@ class JobArtifactUploader < GitlabUploader
model.size model.size
end end
def checksum
return calc_checksum if model.checksum.nil?
model.checksum
end
def store_dir def store_dir
dynamic_segment dynamic_segment
end end
...@@ -21,6 +27,10 @@ class JobArtifactUploader < GitlabUploader ...@@ -21,6 +27,10 @@ class JobArtifactUploader < GitlabUploader
private private
def calc_checksum
Digest::SHA256.file(file.path).hexdigest
end
def dynamic_segment def dynamic_segment
creation_date = model.created_at.utc.strftime('%Y_%m_%d') creation_date = model.created_at.utc.strftime('%Y_%m_%d')
......
class AddChecksumToCiJobArtifacts < ActiveRecord::Migration
DOWNTIME = false
def change
add_column :ci_job_artifacts, :checksum, :string, limit: 64
end
end
...@@ -346,6 +346,7 @@ ActiveRecord::Schema.define(version: 20180304204842) do ...@@ -346,6 +346,7 @@ ActiveRecord::Schema.define(version: 20180304204842) do
t.datetime_with_timezone "updated_at", null: false t.datetime_with_timezone "updated_at", null: false
t.datetime_with_timezone "expire_at" t.datetime_with_timezone "expire_at"
t.string "file" t.string "file"
t.string "checksum", limit: 64
end end
add_index "ci_job_artifacts", ["expire_at", "job_id"], name: "index_ci_job_artifacts_on_expire_at_and_job_id", using: :btree add_index "ci_job_artifacts", ["expire_at", "job_id"], name: "index_ci_job_artifacts_on_expire_at_and_job_id", using: :btree
......
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