diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-07-31 16:17:14 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-08-01 11:48:46 +0300 |
commit | e99564568b2fefab8973ce571594aaa888cf8494 (patch) | |
tree | 9d00477a620e6fe3219eed92618f9efe42d5a17c | |
parent | a9f56ae16873af40c7f1f753aee4528f0fbc2e8d (diff) |
CI fixes for gitaly-ruby
-rw-r--r-- | .gitlab-ci.yml | 3 | ||||
-rw-r--r-- | lib/tasks/gitlab/gitaly.rake | 12 | ||||
-rwxr-xr-x | scripts/gitaly-test-build | 10 | ||||
-rwxr-xr-x | scripts/gitaly-test-spawn | 7 | ||||
-rw-r--r-- | spec/support/test_env.rb | 11 | ||||
-rw-r--r-- | spec/tasks/gitlab/gitaly_rake_spec.rb | 18 |
6 files changed, 50 insertions, 11 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index adde3400107..27fdf6ca0b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -96,6 +96,7 @@ stages: - export KNAPSACK_GENERATE_REPORT=true - export CACHE_CLASSES=true - cp ${KNAPSACK_RSPEC_SUITE_REPORT_PATH} ${KNAPSACK_REPORT_PATH} + - scripts/gitaly-test-spawn - knapsack rspec "--color --format documentation" artifacts: expire_in: 31d @@ -221,6 +222,7 @@ setup-test-env: - bundle exec rake gettext:po_to_json - bundle exec rake gitlab:assets:compile - bundle exec ruby -Ispec -e 'require "spec_helper" ; TestEnv.init' + - scripts/gitaly-test-build # Do not use 'bundle exec' here artifacts: expire_in: 7d paths: @@ -486,6 +488,7 @@ karma: BABEL_ENV: "coverage" CHROME_LOG_FILE: "chrome_debug.log" script: + - scripts/gitaly-test-spawn - bundle exec rake gettext:po_to_json - bundle exec rake karma coverage: '/^Statements *: (\d+\.\d+%)/' diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake index 9df07ea8d83..680e76af471 100644 --- a/lib/tasks/gitlab/gitaly.rake +++ b/lib/tasks/gitlab/gitaly.rake @@ -19,7 +19,10 @@ namespace :gitlab do Dir.chdir(args.dir) do create_gitaly_configuration - Bundler.with_original_env { run_command!([command]) } + # In CI we run scripts/gitaly-test-build instead of this command + unless ENV['CI'].present? + Bundler.with_original_env { run_command!(%w[/usr/bin/env -u BUNDLE_GEMFILE] + [command]) } + end end end @@ -30,7 +33,9 @@ namespace :gitlab do puts "# Gitaly storage configuration generated from #{Gitlab.config.source} on #{Time.current.to_s(:long)}" puts "# This is in TOML format suitable for use in Gitaly's config.toml file." - puts gitaly_configuration_toml + # Exclude gitaly-ruby configuration because that depends on the gitaly + # installation directory. + puts gitaly_configuration_toml(gitaly_ruby: false) end private @@ -41,7 +46,7 @@ namespace :gitlab do # only generate a configuration for the most common and simplest case: when # we have exactly one Gitaly process and we are sure it is running locally # because it uses a Unix socket. - def gitaly_configuration_toml + def gitaly_configuration_toml(gitaly_ruby: true) storages = [] address = nil @@ -60,6 +65,7 @@ namespace :gitlab do end config = { socket_path: address.sub(%r{\Aunix:}, ''), storage: storages } config[:auth] = { token: 'secret' } if Rails.env.test? + config[:'gitaly-ruby'] = { dir: File.join(Dir.pwd, 'ruby') } if gitaly_ruby TOML.dump(config) end diff --git a/scripts/gitaly-test-build b/scripts/gitaly-test-build new file mode 100755 index 00000000000..44d314009e2 --- /dev/null +++ b/scripts/gitaly-test-build @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +# This script assumes tmp/tests/gitaly already contains the correct +# Gitaly version. We just have to compile it and run its 'bundle +# install'. We have this separate script for that because weird things +# were happening in CI when we have a 'bundle exec' process that later +# called 'bundle install' using a different Gemfile, as happens with +# gitlab-ce and gitaly. + +abort 'gitaly build failed' unless system('make', chdir: 'tmp/tests/gitaly') diff --git a/scripts/gitaly-test-spawn b/scripts/gitaly-test-spawn new file mode 100755 index 00000000000..dd603eec7f6 --- /dev/null +++ b/scripts/gitaly-test-spawn @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +gitaly_dir = 'tmp/tests/gitaly' +args = %W[#{gitaly_dir}/gitaly #{gitaly_dir}/config.toml] + +# Print the PID of the spawned process +puts spawn(*args, [:out, :err] => 'log/gitaly-test.log') diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 86f9568c12e..f0603dfadde 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -144,10 +144,13 @@ module TestEnv end def start_gitaly(gitaly_dir) - gitaly_exec = File.join(gitaly_dir, 'gitaly') - gitaly_config = File.join(gitaly_dir, 'config.toml') - log_file = Rails.root.join('log/gitaly-test.log').to_s - @gitaly_pid = Bundler.with_original_env { spawn(gitaly_exec, gitaly_config, [:out, :err] => log_file) } + if ENV['CI'].present? + # Gitaly has been spawned outside this process already + return + end + + spawn_script = Rails.root.join('scripts/gitaly-test-spawn').to_s + @gitaly_pid = Bundler.with_original_env { IO.popen([spawn_script], &:read).to_i } end def stop_gitaly diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb index d42d2423f15..695231c7d15 100644 --- a/spec/tasks/gitlab/gitaly_rake_spec.rb +++ b/spec/tasks/gitlab/gitaly_rake_spec.rb @@ -41,6 +41,16 @@ describe 'gitlab:gitaly namespace rake task' do end describe 'gmake/make' do + let(:command_preamble) { %w[/usr/bin/env -u BUNDLE_GEMFILE] } + + before(:all) do + @old_env_ci = ENV.delete('CI') + end + + after(:all) do + ENV['CI'] = @old_env_ci if @old_env_ci + end + before do FileUtils.mkdir_p(clone_path) expect(Dir).to receive(:chdir).with(clone_path).and_call_original @@ -49,12 +59,12 @@ describe 'gitlab:gitaly namespace rake task' do context 'gmake is available' do before do expect_any_instance_of(Object).to receive(:checkout_or_clone_version) - allow_any_instance_of(Object).to receive(:run_command!).with(['gmake']).and_return(true) + allow_any_instance_of(Object).to receive(:run_command!).with(command_preamble + ['gmake']).and_return(true) end it 'calls gmake in the gitaly directory' do expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0]) - expect_any_instance_of(Object).to receive(:run_command!).with(['gmake']).and_return(true) + expect_any_instance_of(Object).to receive(:run_command!).with(command_preamble + ['gmake']).and_return(true) run_rake_task('gitlab:gitaly:install', clone_path) end @@ -63,12 +73,12 @@ describe 'gitlab:gitaly namespace rake task' do context 'gmake is not available' do before do expect_any_instance_of(Object).to receive(:checkout_or_clone_version) - allow_any_instance_of(Object).to receive(:run_command!).with(['make']).and_return(true) + allow_any_instance_of(Object).to receive(:run_command!).with(command_preamble + ['make']).and_return(true) end it 'calls make in the gitaly directory' do expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['', 42]) - expect_any_instance_of(Object).to receive(:run_command!).with(['make']).and_return(true) + expect_any_instance_of(Object).to receive(:run_command!).with(command_preamble + ['make']).and_return(true) run_rake_task('gitlab:gitaly:install', clone_path) end |