From d104a3e179782eb5f418187532e032e59daaa5b4 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Sep 2016 12:51:06 +0200 Subject: Add development environment database setup CI test --- .gitlab-ci.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b167fc74996..9969d54f604 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ variables: RSPEC_RETRY_RETRY_COUNT: "3" RAILS_ENV: "test" SIMPLECOV: "true" - USE_DB: "true" + SETUP_DB: "true" USE_BUNDLE_INSTALL: "true" GIT_DEPTH: "20" PHANTOMJS_VERSION: "2.1.1" @@ -23,7 +23,7 @@ before_script: - bundle --version - '[ "$USE_BUNDLE_INSTALL" != "true" ] || retry bundle install --without postgres production --jobs $(nproc) "${FLAGS[@]}"' - retry gem install knapsack - - '[ "$USE_DB" != "true" ] || bundle exec rake db:drop db:create db:schema:load db:migrate' + - '[ "$SETUP_DB" != "true" ] || bundle exec rake db:drop db:create db:schema:load db:migrate' stages: - prepare @@ -35,7 +35,7 @@ stages: .knapsack-state: &knapsack-state services: [] variables: - USE_DB: "false" + SETUP_DB: "false" USE_BUNDLE_INSTALL: "false" cache: key: "knapsack" @@ -196,7 +196,7 @@ spinach 9 10 ruby21: *spinach-knapsack-ruby21 .ruby-static-analysis: &ruby-static-analysis variables: SIMPLECOV: "false" - USE_DB: "false" + SETUP_DB: "false" USE_BUNDLE_INSTALL: "true" .exec: &exec @@ -224,6 +224,16 @@ rake db:migrate:reset: script: - rake db:migrate:reset +rake dev:setup: + stage: test + <<: *use-db + variables: + SETUP_DB: "false" + RAILS_ENV: development + script: + - mkdir -p /home/git/repositories + - rake dev:setup + teaspoon: stage: test <<: *use-db @@ -272,7 +282,7 @@ coverage: stage: post-test services: [] variables: - USE_DB: "false" + SETUP_DB: "false" USE_BUNDLE_INSTALL: "true" script: - bundle exec scripts/merge-simplecov @@ -288,7 +298,7 @@ coverage: notify:slack: stage: post-test variables: - USE_DB: "false" + SETUP_DB: "false" USE_BUNDLE_INSTALL: "false" script: - ./scripts/notify_slack.sh "#builds" "Build on \`$CI_BUILD_REF_NAME\` failed! Commit \`$(git log -1 --oneline)\` See " -- cgit v1.2.1 From 8b8e2626827a65b5dde5e7fa89becb82ef107a78 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Sep 2016 13:45:25 +0200 Subject: Fix pipeline fixtures for development environment --- app/models/ci/build.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index cb87b43f6be..522e2264bb8 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -91,7 +91,7 @@ module Ci sha: build.sha, ref: build.ref, tag: build.tag, - options: build.options[:environment], + options: build.options.to_h[:environment], variables: build.variables) service.execute(build) end -- cgit v1.2.1 From 9aa0127cc22f71de4ca432c63b03cbc6c839099d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Sep 2016 13:49:08 +0200 Subject: Add artifacts with development log when seed fails --- .gitlab-ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9969d54f604..7f9c610a842 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -233,6 +233,11 @@ rake dev:setup: script: - mkdir -p /home/git/repositories - rake dev:setup + artifacts: + when: on_failure + expire_in: 1d + paths: + - log/development.log teaspoon: stage: test -- cgit v1.2.1 From e7d24721f2ab9b91f661fd3ae1c767f21120bb08 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Sep 2016 14:28:37 +0200 Subject: Try cloning repositories before seeding database Seeding database requires gitlab-shell, and we would like to avoid adding this dependency to the CI. --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7f9c610a842..b2c4ee01c15 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -232,6 +232,8 @@ rake dev:setup: RAILS_ENV: development script: - mkdir -p /home/git/repositories + - git clone https://gitlab.com/gitlab-org/gitlab-ce.git /home/git/repositories/gitlab-org/gitlab-ce.git + - git clone https://gitlab.com/gitlab-org/gitlab-test.git /home/git/repositories/gitlab-org/gitlab-test.git - rake dev:setup artifacts: when: on_failure -- cgit v1.2.1 From 68771115441caef15f8302a23d9ea00824d192d8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Sep 2016 14:47:46 +0200 Subject: Improve CI job that tests database seeds --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b2c4ee01c15..3dfab341e39 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -224,7 +224,7 @@ rake db:migrate:reset: script: - rake db:migrate:reset -rake dev:setup: +rake db:seed_fu: stage: test <<: *use-db variables: @@ -232,9 +232,9 @@ rake dev:setup: RAILS_ENV: development script: - mkdir -p /home/git/repositories - - git clone https://gitlab.com/gitlab-org/gitlab-ce.git /home/git/repositories/gitlab-org/gitlab-ce.git - - git clone https://gitlab.com/gitlab-org/gitlab-test.git /home/git/repositories/gitlab-org/gitlab-test.git - - rake dev:setup + - git clone https://gitlab.com/gitlab-org/gitlab-test.git + /home/git/repositories/gitlab-org/gitlab-test.git + - bundle exec rake db:setup db:seed_fu artifacts: when: on_failure expire_in: 1d -- cgit v1.2.1 From 52e897dd14c423332188cae4785ecf6e1182cede Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 22 Sep 2016 17:25:52 +0200 Subject: Update `CurrentSettings` class that uses ENV --- lib/gitlab/current_settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 12fbb78c53e..76578978d5a 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -59,7 +59,7 @@ module Gitlab # When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised active_db_connection = ActiveRecord::Base.connection.active? rescue false - ENV['USE_DB'] != 'false' && + ENV['SETUP_DB'] != 'false' && active_db_connection && ActiveRecord::Base.connection.table_exists?('application_settings') -- cgit v1.2.1 From c2083b79974de34ffb2d44ec486c40323a99228c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 23 Sep 2016 10:21:12 +0200 Subject: Limit test environment size to one project in CI --- .gitlab-ci.yml | 4 ++-- db/fixtures/development/04_project.rb | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3dfab341e39..3f3873e57c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -228,10 +228,10 @@ rake db:seed_fu: stage: test <<: *use-db variables: + SIZE: "1" SETUP_DB: "false" - RAILS_ENV: development + RAILS_ENV: "development" script: - - mkdir -p /home/git/repositories - git clone https://gitlab.com/gitlab-org/gitlab-test.git /home/git/repositories/gitlab-org/gitlab-test.git - bundle exec rake db:setup db:seed_fu diff --git a/db/fixtures/development/04_project.rb b/db/fixtures/development/04_project.rb index e3316ecdb6c..a984eda5ab5 100644 --- a/db/fixtures/development/04_project.rb +++ b/db/fixtures/development/04_project.rb @@ -3,11 +3,11 @@ require 'sidekiq/testing' Sidekiq::Testing.inline! do Gitlab::Seeder.quiet do project_urls = [ - 'https://github.com/documentcloud/underscore.git', + 'https://gitlab.com/gitlab-org/gitlab-test.git', 'https://gitlab.com/gitlab-org/gitlab-ce.git', 'https://gitlab.com/gitlab-org/gitlab-ci.git', 'https://gitlab.com/gitlab-org/gitlab-shell.git', - 'https://gitlab.com/gitlab-org/gitlab-test.git', + 'https://github.com/documentcloud/underscore.git', 'https://github.com/twitter/flight.git', 'https://github.com/twitter/typeahead.js.git', 'https://github.com/h5bp/html5-boilerplate.git', @@ -38,12 +38,7 @@ Sidekiq::Testing.inline! do ] # You can specify how many projects you need during seed execution - size = if ENV['SIZE'].present? - ENV['SIZE'].to_i - else - 8 - end - + size = ENV['SIZE'].present? ? ENV['SIZE'].to_i : 8 project_urls.first(size).each_with_index do |url, i| group_path, project_path = url.split('/')[-2..-1] -- cgit v1.2.1 From cee66810f88ad7ba622c05529b2163e1d38b1b0f Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 23 Sep 2016 10:50:46 +0200 Subject: Remove use of `USE_DB` environment variable in code --- lib/gitlab/current_settings.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 76578978d5a..ef9160d6437 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -59,10 +59,8 @@ module Gitlab # When the DBMS is not available, an exception (e.g. PG::ConnectionBad) is raised active_db_connection = ActiveRecord::Base.connection.active? rescue false - ENV['SETUP_DB'] != 'false' && active_db_connection && - ActiveRecord::Base.connection.table_exists?('application_settings') - + ActiveRecord::Base.connection.table_exists?('application_settings') rescue ActiveRecord::NoDatabaseError false end -- cgit v1.2.1