From ff2d1dd2e87b067336bc7e373662fd05f494f14d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 16 Dec 2015 15:13:34 +0100 Subject: Add initial fixtures for CI builds --- db/fixtures/development/14_builds.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/fixtures/development/14_builds.rb (limited to 'db/fixtures/development') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb new file mode 100644 index 00000000000..ac3bd1e9d63 --- /dev/null +++ b/db/fixtures/development/14_builds.rb @@ -0,0 +1,12 @@ +Gitlab::Seeder.quiet do + project = Project.first + commits = project.repository.commits('master', nil, 10) + commits_sha = commits.map { |commit| commit.raw.id } + ci_commits = commits_sha.map do |sha| + project.ensure_ci_commit(sha) + end + + ci_commits.each do |ci_commit| + ci_commit.create_builds('master', nil, User.first) + end +end -- cgit v1.2.1 From 5f67bf74f460c9dd1e9061757a23a2bdf447fca3 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 16 Dec 2015 19:07:27 +0100 Subject: Improve CI builds fixtures --- db/fixtures/development/14_builds.rb | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'db/fixtures/development') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index ac3bd1e9d63..73cffcbc01e 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -1,12 +1,25 @@ Gitlab::Seeder.quiet do - project = Project.first - commits = project.repository.commits('master', nil, 10) - commits_sha = commits.map { |commit| commit.raw.id } - ci_commits = commits_sha.map do |sha| - project.ensure_ci_commit(sha) - end + Project.all.sample(5).each do |project| + commits = project.repository.commits('master', nil, 10) + commits_sha = commits.map { |commit| commit.raw.id } + ci_commits = commits_sha.map do |sha| + project.ensure_ci_commit(sha) + end + + ci_commits.each do |ci_commit| + attributes = { type: 'Ci::Build', name: 'test build', + commands: "$ build command", stage: 'test', + stage_idx: 1, ref: 'master', user_id: User.first, + gl_project_id: project.id, options: '---- opts', + status: %w(running pending success failed canceled).sample, + commit_id: ci_commit.id } - ci_commits.each do |ci_commit| - ci_commit.create_builds('master', nil, User.first) + begin + Ci::Build.create!(attributes) + print '.' + rescue ActiveRecord::RecordInvalid + print 'F' + end + end end end -- cgit v1.2.1 From 7027bf40c6898a26557d7325356e5e8760a3ff40 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 17 Dec 2015 11:00:53 +0100 Subject: Add database seed for build artifacts --- db/fixtures/development/14_builds.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'db/fixtures/development') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index 73cffcbc01e..f9b4482cbf9 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -1,24 +1,35 @@ Gitlab::Seeder.quiet do + build_artifacts_path = Rails.root + 'spec/fixtures/ci_build_artifacts.tar.gz' + build_artifacts_cache_file = build_artifacts_path.to_s.gsub('ci_', '') + Project.all.sample(5).each do |project| - commits = project.repository.commits('master', nil, 10) + commits = project.repository.commits('master', nil, 5) commits_sha = commits.map { |commit| commit.raw.id } ci_commits = commits_sha.map do |sha| project.ensure_ci_commit(sha) end ci_commits.each do |ci_commit| - attributes = { type: 'Ci::Build', name: 'test build', - commands: "$ build command", stage: 'test', - stage_idx: 1, ref: 'master', user_id: User.first, - gl_project_id: project.id, options: '---- opts', + attributes = { type: 'Ci::Build', name: 'test build', commands: "$ build command", + stage: 'test', stage_idx: 1, ref: 'master', + user_id: project.team.users.sample, gl_project_id: project.id, status: %w(running pending success failed canceled).sample, - commit_id: ci_commit.id } + commit_id: ci_commit.id, created_at: Time.now, updated_at: Time.now } + + build = Ci::Build.new(attributes) + build.artifacts_metadata = `tar tzf #{build_artifacts_path}`.split(/\n/) + + FileUtils.copy(build_artifacts_path, build_artifacts_cache_file) + build.artifacts_file = artifacts_file = File.open(build_artifacts_cache_file, 'r') begin - Ci::Build.create!(attributes) + build.save! print '.' rescue ActiveRecord::RecordInvalid + puts build.error.messages.inspect print 'F' + ensure + artifacts_file.close end end end -- cgit v1.2.1 From a385d39ff1ef3cca8b98f75b99022f762fa5b5e5 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 17 Dec 2015 12:59:39 +0100 Subject: Improve CI builds seeder --- db/fixtures/development/14_builds.rb | 81 ++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 22 deletions(-) (limited to 'db/fixtures/development') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index f9b4482cbf9..2e15f30adbb 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -1,36 +1,73 @@ -Gitlab::Seeder.quiet do - build_artifacts_path = Rails.root + 'spec/fixtures/ci_build_artifacts.tar.gz' - build_artifacts_cache_file = build_artifacts_path.to_s.gsub('ci_', '') +class Gitlab::Seeder::Builds + BUILD_STATUSES = %w(running pending success failed canceled) - Project.all.sample(5).each do |project| - commits = project.repository.commits('master', nil, 5) - commits_sha = commits.map { |commit| commit.raw.id } - ci_commits = commits_sha.map do |sha| - project.ensure_ci_commit(sha) - end + def initialize(project) + @project = project + end + def seed! ci_commits.each do |ci_commit| - attributes = { type: 'Ci::Build', name: 'test build', commands: "$ build command", - stage: 'test', stage_idx: 1, ref: 'master', - user_id: project.team.users.sample, gl_project_id: project.id, - status: %w(running pending success failed canceled).sample, - commit_id: ci_commit.id, created_at: Time.now, updated_at: Time.now } + build = Ci::Build.new(build_attributes_for(ci_commit)) - build = Ci::Build.new(attributes) - build.artifacts_metadata = `tar tzf #{build_artifacts_path}`.split(/\n/) - - FileUtils.copy(build_artifacts_path, build_artifacts_cache_file) - build.artifacts_file = artifacts_file = File.open(build_artifacts_cache_file, 'r') + FileUtils.copy(artifacts_path, artifacts_cache_file_path) + File.open(artifacts_cache_file_path, 'r') do |file| + build.artifacts_file = file + build.artifacts_metadata = artifacts_metadata + end begin build.save! print '.' rescue ActiveRecord::RecordInvalid - puts build.error.messages.inspect print 'F' - ensure - artifacts_file.close end end end + + def ci_commits + commits = @project.repository.commits('master', nil, 5) + commits_sha = commits.map { |commit| commit.raw.id } + commits_sha.map do |sha| + @project.ensure_ci_commit(sha) + end + rescue + [] + end + + def build_attributes_for(ci_commit) + { name: 'test build', commands: "$ build command", + stage: 'test', stage_idx: 1, ref: 'master', + user_id: build_user, gl_project_id: @project.id, + status: build_status, commit_id: ci_commit.id, + created_at: Time.now, updated_at: Time.now } + end + + def build_user + @project.team.users.sample + end + + def build_status + BUILD_STATUSES.sample + end + + def artifacts_path + Rails.root + 'spec/fixtures/ci_build_artifacts.tar.gz' + end + + def artifacts_cache_file_path + artifacts_path.to_s.gsub('ci_', "p#{@project.id}_") + end + + def artifacts_metadata + return @artifacts_metadata if @artifacts_metadata + logs, _exit_status = Gitlab::Popen.popen(%W(tar tzf #{artifacts_path})) + @artifacts_metadata = logs.split(/\n/) + end +end + +Gitlab::Seeder.quiet do + Project.all.sample(10).each do |project| + project_builds = Gitlab::Seeder::Builds.new(project) + project_builds.seed! + end end -- cgit v1.2.1 From ebd69c5fc1296f30238326b901ad73c891d696da Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 10:35:51 +0100 Subject: Remove artifacts metadata column from database --- db/fixtures/development/14_builds.rb | 7 ------- 1 file changed, 7 deletions(-) (limited to 'db/fixtures/development') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index 2e15f30adbb..e625fd6b75a 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -12,7 +12,6 @@ class Gitlab::Seeder::Builds FileUtils.copy(artifacts_path, artifacts_cache_file_path) File.open(artifacts_cache_file_path, 'r') do |file| build.artifacts_file = file - build.artifacts_metadata = artifacts_metadata end begin @@ -57,12 +56,6 @@ class Gitlab::Seeder::Builds def artifacts_cache_file_path artifacts_path.to_s.gsub('ci_', "p#{@project.id}_") end - - def artifacts_metadata - return @artifacts_metadata if @artifacts_metadata - logs, _exit_status = Gitlab::Popen.popen(%W(tar tzf #{artifacts_path})) - @artifacts_metadata = logs.split(/\n/) - end end Gitlab::Seeder.quiet do -- cgit v1.2.1 From 87df1df3cd1a38bbb523d365b229e5e03f890788 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 28 Dec 2015 10:54:22 +0100 Subject: Seed db with CI build artifacts using a zip archive --- db/fixtures/development/14_builds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'db/fixtures/development') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index e625fd6b75a..f86fff0692e 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -50,7 +50,7 @@ class Gitlab::Seeder::Builds end def artifacts_path - Rails.root + 'spec/fixtures/ci_build_artifacts.tar.gz' + Rails.root + 'spec/fixtures/ci_build_artifacts.zip' end def artifacts_cache_file_path -- cgit v1.2.1 From ad5302ba155725f2438e0c53e977f16aba32242a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 30 Dec 2015 15:21:05 +0100 Subject: Seed db on development with artifacts metadata fixture --- db/fixtures/development/14_builds.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'db/fixtures/development') diff --git a/db/fixtures/development/14_builds.rb b/db/fixtures/development/14_builds.rb index f86fff0692e..03a12323845 100644 --- a/db/fixtures/development/14_builds.rb +++ b/db/fixtures/development/14_builds.rb @@ -9,11 +9,14 @@ class Gitlab::Seeder::Builds ci_commits.each do |ci_commit| build = Ci::Build.new(build_attributes_for(ci_commit)) - FileUtils.copy(artifacts_path, artifacts_cache_file_path) - File.open(artifacts_cache_file_path, 'r') do |file| + artifacts_cache_file(artifacts_archive_path) do |file| build.artifacts_file = file end + artifacts_cache_file(artifacts_metadata_path) do |file| + build.artifacts_metadata = file + end + begin build.save! print '.' @@ -49,12 +52,22 @@ class Gitlab::Seeder::Builds BUILD_STATUSES.sample end - def artifacts_path + def artifacts_archive_path Rails.root + 'spec/fixtures/ci_build_artifacts.zip' end - def artifacts_cache_file_path - artifacts_path.to_s.gsub('ci_', "p#{@project.id}_") + def artifacts_metadata_path + Rails.root + 'spec/fixtures/ci_build_artifacts_metadata.gz' + + end + + def artifacts_cache_file(file_path) + cache_path = file_path.to_s.gsub('ci_', "p#{@project.id}_") + + FileUtils.copy(file_path, cache_path) + File.open(cache_path) do |file| + yield file + end end end -- cgit v1.2.1