diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-06-28 13:14:21 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-06-28 13:14:21 +0300 |
commit | fe0c59d2e61238e1241be448a37be0e3e702a5ce (patch) | |
tree | a002bc7887880f291b2294ebce044c3527dc7df4 | |
parent | aa3a3fd12fc7152020ffbe54faa36a4f17eb94b2 (diff) |
Introduce ci_builds.artifacts_sizes as JSON:
We store the sizes as a hash from path to bytes like:
``` ruby
{'ci_artifacts.txt' => 27,
'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' =>
71759,
'other_artifacts_0.1.2/doc_sample.txt' => 1314,
'rails_sample.jpg' => 35255,
'tests_encoding/utf8 test dir ✓/regular_file_2' => 7}
```
So that it's easier to access than reading gzip file again.
-rw-r--r-- | app/models/ci/build.rb | 21 | ||||
-rw-r--r-- | db/migrate/20160628085157_add_artifacts_sizes_to_ci_builds.rb | 11 | ||||
-rw-r--r-- | lib/ci/api/builds.rb | 1 | ||||
-rw-r--r-- | spec/requests/ci/api/builds_spec.rb | 14 |
4 files changed, 44 insertions, 3 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 2b0bec33131..d9544a4a279 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -5,6 +5,7 @@ module Ci belongs_to :erased_by, class_name: 'User' serialize :options + serialize :artifacts_sizes, JSON validates :coverage, numericality: true, allow_blank: true validates_presence_of :ref @@ -328,8 +329,19 @@ module Ci artifacts? && artifacts_metadata.exists? end + def artifacts_metadata_sizes + return unless artifacts_metadata? + + entries = new_artifacts_metadata('', recursive: true).find_entries! + + entries.inject({}) do |result, (path, metadata)| + result[path] = metadata[:size] if metadata[:size] + result + end + end + def artifacts_metadata_entry(path, **options) - Gitlab::Ci::Build::Artifacts::Metadata.new(artifacts_metadata.path, path, **options).to_entry + new_artifacts_metadata(path, **options).to_entry end def erase_artifacts! @@ -375,6 +387,13 @@ module Ci private + def new_artifacts_metadata(path, **options) + Gitlab::Ci::Build::Artifacts::Metadata.new( + artifacts_metadata.path, + path, + **options) + end + def erase_trace! self.trace = nil end diff --git a/db/migrate/20160628085157_add_artifacts_sizes_to_ci_builds.rb b/db/migrate/20160628085157_add_artifacts_sizes_to_ci_builds.rb new file mode 100644 index 00000000000..bad260b83ea --- /dev/null +++ b/db/migrate/20160628085157_add_artifacts_sizes_to_ci_builds.rb @@ -0,0 +1,11 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddArtifactsSizesToCiBuilds < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + def change + # Or :json if under PostgreSQL? + add_column(:ci_builds, :artifacts_sizes, :text) + end +end diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb index 9f270f7b387..93eed4496e4 100644 --- a/lib/ci/api/builds.rb +++ b/lib/ci/api/builds.rb @@ -147,6 +147,7 @@ module Ci build.artifacts_file = artifacts build.artifacts_metadata = metadata build.artifacts_expire_in = params['expire_in'] + build.artifacts_sizes = build.artifacts_metadata_sizes if build.save present(build, with: Entities::BuildDetails) diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb index ea984924701..fb164c221d0 100644 --- a/spec/requests/ci/api/builds_spec.rb +++ b/spec/requests/ci/api/builds_spec.rb @@ -309,7 +309,7 @@ describe Ci::API::API do shared_examples 'post artifact' do it 'updates successfully' do response_filename = - json_response["artifacts_file"]["filename"] + json_response['artifacts_file']['filename'] expect(response).to have_http_status(201) expect(response_filename).to eq(file_upload.original_filename) @@ -344,10 +344,14 @@ describe Ci::API::API do context 'should post artifacts file and metadata file' do let!(:artifacts) { file_upload } - let!(:metadata) { file_upload2 } + let!(:metadata) do + fixture_file_upload( + Rails.root + 'spec/fixtures/ci_build_artifacts_metadata.gz') + end let(:stored_artifacts_file) { build.reload.artifacts_file.file } let(:stored_metadata_file) { build.reload.artifacts_metadata.file } + let(:stored_artifacts_sizes) { build.reload.artifacts_sizes } before do post(post_url, post_data, headers_with_token) @@ -365,6 +369,12 @@ describe Ci::API::API do expect(response).to have_http_status(201) expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename) expect(stored_metadata_file.original_filename).to eq(metadata.original_filename) + expect(stored_artifacts_sizes).to eq( + 'ci_artifacts.txt' => 27, + 'other_artifacts_0.1.2/another-subdirectory/banana_sample.gif' => 71759, + 'other_artifacts_0.1.2/doc_sample.txt' => 1314, + 'rails_sample.jpg' => 35255, + 'tests_encoding/utf8 test dir ✓/regular_file_2' => 7) end end |