Commit a2804512 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'feature/sm/add-check-sum-to-job-artifacts' into 'master'

Add checksum to ci_job_artifacts

Closes #43599

See merge request gitlab-org/gitlab-ce!17354
parents 09634b98 03438886
---
title: Store sha256 checksum to job artifacts
merge_request: 17354
author:
type: performance
class AddChecksumToCiJobArtifacts < ActiveRecord::Migration
DOWNTIME = false
def change
add_column :ci_job_artifacts, :file_sha256, :binary
end
end
...@@ -346,6 +346,7 @@ ActiveRecord::Schema.define(version: 20180305144721) do ...@@ -346,6 +346,7 @@ ActiveRecord::Schema.define(version: 20180305144721) 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.binary "file_sha256"
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
......
...@@ -204,6 +204,7 @@ module API ...@@ -204,6 +204,7 @@ module API
optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse))
optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse)) optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse))
optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse)) optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse))
optional 'file.sha256', type: String, desc: %q(sha256 checksum of the file)
optional 'metadata.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) optional 'metadata.path', type: String, desc: %q(path to locally stored body (generated by Workhorse))
optional 'metadata.name', type: String, desc: %q(filename (generated by Workhorse)) optional 'metadata.name', type: String, desc: %q(filename (generated by Workhorse))
end end
...@@ -224,7 +225,7 @@ module API ...@@ -224,7 +225,7 @@ module API
expire_in = params['expire_in'] || expire_in = params['expire_in'] ||
Gitlab::CurrentSettings.current_application_settings.default_artifacts_expire_in Gitlab::CurrentSettings.current_application_settings.default_artifacts_expire_in
job.build_job_artifacts_archive(project: job.project, file_type: :archive, file: artifacts, expire_in: expire_in) job.build_job_artifacts_archive(project: job.project, file_type: :archive, file: artifacts, file_sha256: params['file.sha256'], expire_in: expire_in)
job.build_job_artifacts_metadata(project: job.project, file_type: :metadata, file: metadata, expire_in: expire_in) if metadata job.build_job_artifacts_metadata(project: job.project, file_type: :metadata, file: metadata, expire_in: expire_in) if metadata
job.artifacts_expire_in = expire_in job.artifacts_expire_in = expire_in
......
...@@ -1100,11 +1100,13 @@ describe API::Runner do ...@@ -1100,11 +1100,13 @@ describe API::Runner do
context 'posts artifacts file and metadata file' do context 'posts artifacts file and metadata file' do
let!(:artifacts) { file_upload } let!(:artifacts) { file_upload }
let!(:artifacts_sha256) { Digest::SHA256.file(artifacts.path).hexdigest }
let!(:metadata) { file_upload2 } let!(:metadata) { file_upload2 }
let(:stored_artifacts_file) { job.reload.artifacts_file.file } let(:stored_artifacts_file) { job.reload.artifacts_file.file }
let(:stored_metadata_file) { job.reload.artifacts_metadata.file } let(:stored_metadata_file) { job.reload.artifacts_metadata.file }
let(:stored_artifacts_size) { job.reload.artifacts_size } let(:stored_artifacts_size) { job.reload.artifacts_size }
let(:stored_artifacts_sha256) { job.reload.job_artifacts_archive.file_sha256 }
before do before do
post(api("/jobs/#{job.id}/artifacts"), post_data, headers_with_token) post(api("/jobs/#{job.id}/artifacts"), post_data, headers_with_token)
...@@ -1114,6 +1116,7 @@ describe API::Runner do ...@@ -1114,6 +1116,7 @@ describe API::Runner do
let(:post_data) do let(:post_data) do
{ 'file.path' => artifacts.path, { 'file.path' => artifacts.path,
'file.name' => artifacts.original_filename, 'file.name' => artifacts.original_filename,
'file.sha256' => artifacts_sha256,
'metadata.path' => metadata.path, 'metadata.path' => metadata.path,
'metadata.name' => metadata.original_filename } 'metadata.name' => metadata.original_filename }
end end
...@@ -1123,6 +1126,7 @@ describe API::Runner do ...@@ -1123,6 +1126,7 @@ describe API::Runner do
expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename) expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename)
expect(stored_metadata_file.original_filename).to eq(metadata.original_filename) expect(stored_metadata_file.original_filename).to eq(metadata.original_filename)
expect(stored_artifacts_size).to eq(72821) expect(stored_artifacts_size).to eq(72821)
expect(stored_artifacts_sha256).to eq(artifacts_sha256)
end 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