diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-02-26 12:21:03 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-03-06 11:02:47 +0300 |
commit | b5f5b6dc50b2963f3190caecf12f63d4ba2da878 (patch) | |
tree | 010c77127fc0cfa8ecf18b2239281342ad4db7d7 | |
parent | 2e87923dcb1cf7984690f5b5fdfc61bddfba923e (diff) |
Add checksum to ci_job_artifacts
-rw-r--r-- | app/models/ci/job_artifact.rb | 5 | ||||
-rw-r--r-- | app/uploaders/job_artifact_uploader.rb | 10 | ||||
-rw-r--r-- | db/migrate/20180226050030_add_checksum_to_ci_job_artifacts.rb | 8 | ||||
-rw-r--r-- | db/schema.rb | 1 |
4 files changed, 24 insertions, 0 deletions
diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb index 0a599f72bc7..a06a4bc502e 100644 --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -6,6 +6,7 @@ module Ci belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id before_save :set_size, if: :file_changed? + before_save :set_checksum, if: :file_changed? mount_uploader :file, JobArtifactUploader @@ -25,6 +26,10 @@ module Ci self.size = file.size end + def set_checksum + self.checksum = file.checksum + end + def expire_in expire_at - Time.now if expire_at end diff --git a/app/uploaders/job_artifact_uploader.rb b/app/uploaders/job_artifact_uploader.rb index ad5385f45a4..5560700f442 100644 --- a/app/uploaders/job_artifact_uploader.rb +++ b/app/uploaders/job_artifact_uploader.rb @@ -9,6 +9,12 @@ class JobArtifactUploader < GitlabUploader model.size end + def checksum + return calc_checksum if model.checksum.nil? + + model.checksum + end + def store_dir dynamic_segment end @@ -21,6 +27,10 @@ class JobArtifactUploader < GitlabUploader private + def calc_checksum + Digest::SHA256.file(file.path).hexdigest + end + def dynamic_segment creation_date = model.created_at.utc.strftime('%Y_%m_%d') diff --git a/db/migrate/20180226050030_add_checksum_to_ci_job_artifacts.rb b/db/migrate/20180226050030_add_checksum_to_ci_job_artifacts.rb new file mode 100644 index 00000000000..30973f6f5c5 --- /dev/null +++ b/db/migrate/20180226050030_add_checksum_to_ci_job_artifacts.rb @@ -0,0 +1,8 @@ +class AddChecksumToCiJobArtifacts < ActiveRecord::Migration + DOWNTIME = false + + def change + add_column :ci_job_artifacts, :checksum, :string, limit: 64 + end +end + diff --git a/db/schema.rb b/db/schema.rb index 9e117440ed2..6a752593c96 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -346,6 +346,7 @@ ActiveRecord::Schema.define(version: 20180304204842) do t.datetime_with_timezone "updated_at", null: false t.datetime_with_timezone "expire_at" t.string "file" + t.string "checksum", limit: 64 end add_index "ci_job_artifacts", ["expire_at", "job_id"], name: "index_ci_job_artifacts_on_expire_at_and_job_id", using: :btree |