Commit e94f41c9 authored by Toon Claes's avatar Toon Claes

test: Inject bundler config in environment

Setting up and spawning Gitaly in tests needs to have some Bundler
settings configured. Until now this was done by writing to the local
config file in the ruby directory inside the gitaly dir used in test.

This method didn't seem to be robust for all our user and
use-cases (i.e. CI), because this configuration _could_ be done from
different places.

To make the situation more predictable, this change injects all Bundler
configuration through environment variables instead. It sets
BUNDLE_IGNORE_CONFIG to make sure any existing configuration written to
file is ignored, this includes the .bundle/config inside the project and
possibly in the user's $HOME directory.
parent 11b65c76
......@@ -13,8 +13,6 @@ class GitalyTestBuild
include GitalySetup
def run
set_bundler_config
# If we have the binaries from the cache, we can skip building them again
if File.exist?(tmp_tests_gitaly_bin_dir)
GitalySetup::LOGGER.debug "Gitaly binary already built. Skip building...\n"
......
......@@ -9,7 +9,6 @@ class GitalyTestSpawn
include GitalySetup
def run
set_bundler_config
install_gitaly_gems if ENV['CI']
check_gitaly_config!
......
......@@ -51,9 +51,11 @@ module GitalySetup
{
'HOME' => File.expand_path('tmp/tests'),
'GEM_PATH' => Gem.path.join(':'),
'BUNDLE_APP_CONFIG' => File.join(gemfile_dir, '.bundle'),
'BUNDLE_INSTALL_FLAGS' => nil,
'BUNDLE_IGNORE_CONFIG' => '1',
'BUNDLE_GEMFILE' => gemfile,
'BUNDLE_PATH' => bundle_path,
'BUNDLE_JOBS' => '4',
'BUNDLE_RETRY' => '3',
'RUBYOPT' => nil,
# Git hooks can't run during tests as the internal API is not running.
......@@ -62,19 +64,13 @@ module GitalySetup
}
end
# rubocop:disable GitlabSecurity/SystemCommandInjection
def set_bundler_config
system('bundle config set --local jobs 4', chdir: gemfile_dir)
system('bundle config set --local retry 3', chdir: gemfile_dir)
bundle_path = File.expand_path(Bundler.configured_bundle_path.base_path)
def bundle_path
if ENV['CI']
bundle_path = File.expand_path('../../../vendor/gitaly-ruby', __dir__)
File.expand_path('../../../vendor/gitaly-ruby', __dir__)
else
File.expand_path(Bundler.configured_bundle_path.base_path)
end
system('bundle', 'config', 'set', '--local', 'path', bundle_path, chdir: gemfile_dir)
end
# rubocop:enable GitlabSecurity/SystemCommandInjection
def config_path(service)
case service
......
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