summaryrefslogtreecommitdiff
path: root/lib/gitlab/setup_helper.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 18:08:10 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 18:08:10 +0000
commit5d75b2b9a9d11c20667895e6aa68ea4e76658c5d (patch)
tree2aa529b0a153c805f5f4ecb357321a4e4f4c59cb /lib/gitlab/setup_helper.rb
parent6f2065c468b05658125b746169c56764a8ccddb1 (diff)
downloadgitlab-ce-5d75b2b9a9d11c20667895e6aa68ea4e76658c5d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/setup_helper.rb')
-rw-r--r--lib/gitlab/setup_helper.rb143
1 files changed, 89 insertions, 54 deletions
diff --git a/lib/gitlab/setup_helper.rb b/lib/gitlab/setup_helper.rb
index 99a7e617884..196dc0e3447 100644
--- a/lib/gitlab/setup_helper.rb
+++ b/lib/gitlab/setup_helper.rb
@@ -4,75 +4,110 @@ require 'toml-rb'
module Gitlab
module SetupHelper
- class << self
- # We cannot create config.toml files for all possible Gitaly configuations.
- # For instance, if Gitaly is running on another machine then it makes no
- # sense to write a config.toml file on the current machine. This method will
- # 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.
- # For development and testing purposes, an extra storage is added to gitaly,
- # which is not known to Rails, but must be explicitly stubbed.
- def gitaly_configuration_toml(gitaly_dir, storage_paths, gitaly_ruby: true)
- storages = []
- address = nil
-
- Gitlab.config.repositories.storages.each do |key, val|
- if address
- if address != val['gitaly_address']
- raise ArgumentError, "Your gitlab.yml contains more than one gitaly_address."
+ def create_configuration(dir, storage_paths, force: false)
+ generate_configuration(
+ configuration_toml(dir, storage_paths),
+ get_config_path(dir),
+ force: force
+ )
+ end
+
+ # rubocop:disable Rails/Output
+ def generate_configuration(toml_data, config_path, force: false)
+ FileUtils.rm_f(config_path) if force
+
+ File.open(config_path, File::WRONLY | File::CREAT | File::EXCL) do |f|
+ f.puts toml_data
+ end
+ rescue Errno::EEXIST
+ puts 'Skipping config.toml generation:'
+ puts 'A configuration file already exists.'
+ rescue ArgumentError => e
+ puts 'Skipping config.toml generation:'
+ puts e.message
+ end
+ # rubocop:enable Rails/Output
+
+ module Gitaly
+ extend Gitlab::SetupHelper
+ class << self
+ # We cannot create config.toml files for all possible Gitaly configuations.
+ # For instance, if Gitaly is running on another machine then it makes no
+ # sense to write a config.toml file on the current machine. This method will
+ # 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.
+ # For development and testing purposes, an extra storage is added to gitaly,
+ # which is not known to Rails, but must be explicitly stubbed.
+ def configuration_toml(gitaly_dir, storage_paths, gitaly_ruby: true)
+ storages = []
+ address = nil
+
+ Gitlab.config.repositories.storages.each do |key, val|
+ if address
+ if address != val['gitaly_address']
+ raise ArgumentError, "Your gitlab.yml contains more than one gitaly_address."
+ end
+ elsif URI(val['gitaly_address']).scheme != 'unix'
+ raise ArgumentError, "Automatic config.toml generation only supports 'unix:' addresses."
+ else
+ address = val['gitaly_address']
end
- elsif URI(val['gitaly_address']).scheme != 'unix'
- raise ArgumentError, "Automatic config.toml generation only supports 'unix:' addresses."
- else
- address = val['gitaly_address']
+
+ storages << { name: key, path: storage_paths[key] }
end
- storages << { name: key, path: storage_paths[key] }
- end
+ config = { socket_path: address.sub(/\Aunix:/, '') }
- if Rails.env.test?
- storage_path = Rails.root.join('tmp', 'tests', 'second_storage').to_s
- storages << { name: 'test_second_storage', path: storage_path }
- end
+ if Rails.env.test?
+ storage_path = Rails.root.join('tmp', 'tests', 'second_storage').to_s
+ storages << { name: 'test_second_storage', path: storage_path }
+
+ config[:auth] = { token: 'secret' }
+ # Compared to production, tests run in constrained environments. This
+ # number is meant to grow with the number of concurrent rails requests /
+ # sidekiq jobs, and concurrency will be low anyway in test.
+ config[:git] = { catfile_cache_size: 5 }
+ end
- config = { socket_path: address.sub(/\Aunix:/, ''), storage: storages }
- config[:auth] = { token: 'secret' } if Rails.env.test?
+ config[:storage] = storages
- internal_socket_dir = File.join(gitaly_dir, 'internal_sockets')
- FileUtils.mkdir(internal_socket_dir) unless File.exist?(internal_socket_dir)
- config[:internal_socket_dir] = internal_socket_dir
+ internal_socket_dir = File.join(gitaly_dir, 'internal_sockets')
+ FileUtils.mkdir(internal_socket_dir) unless File.exist?(internal_socket_dir)
+ config[:internal_socket_dir] = internal_socket_dir
- config[:'gitaly-ruby'] = { dir: File.join(gitaly_dir, 'ruby') } if gitaly_ruby
- config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path }
- config[:bin_dir] = Gitlab.config.gitaly.client_path
+ config[:'gitaly-ruby'] = { dir: File.join(gitaly_dir, 'ruby') } if gitaly_ruby
+ config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path }
+ config[:bin_dir] = Gitlab.config.gitaly.client_path
- if Rails.env.test?
- # Compared to production, tests run in constrained environments. This
- # number is meant to grow with the number of concurrent rails requests /
- # sidekiq jobs, and concurrency will be low anyway in test.
- config[:git] = { catfile_cache_size: 5 }
+ TomlRB.dump(config)
end
- TomlRB.dump(config)
+ private
+
+ def get_config_path(dir)
+ File.join(dir, 'config.toml')
+ end
end
+ end
+
+ module Praefect
+ extend Gitlab::SetupHelper
+ class << self
+ def configuration_toml(gitaly_dir, storage_paths)
+ nodes = [{ storage: 'default', address: "unix:#{gitaly_dir}/gitaly.socket", primary: true, token: 'secret' }]
+ config = { socket_path: "#{gitaly_dir}/praefect.socket", virtual_storage_name: 'default', token: 'secret', node: nodes }
+ config[:token] = 'secret' if Rails.env.test?
+
+ TomlRB.dump(config)
+ end
- # rubocop:disable Rails/Output
- def create_gitaly_configuration(dir, storage_paths, force: false)
- config_path = File.join(dir, 'config.toml')
- FileUtils.rm_f(config_path) if force
+ private
- File.open(config_path, File::WRONLY | File::CREAT | File::EXCL) do |f|
- f.puts gitaly_configuration_toml(dir, storage_paths)
+ def get_config_path(dir)
+ File.join(dir, 'praefect.config.toml')
end
- rescue Errno::EEXIST
- puts "Skipping config.toml generation:"
- puts "A configuration file already exists."
- rescue ArgumentError => e
- puts "Skipping config.toml generation:"
- puts e.message
end
- # rubocop:enable Rails/Output
end
end
end