Module: Gitlab::SetupHelper::Gitaly
- Extended by:
- Gitlab::SetupHelper
- Defined in:
- lib/gitlab/setup_helper.rb
Class Method Summary collapse
-
.configuration_toml(gitaly_dir, storage_paths, options) ⇒ Object
We cannot create config.toml files for all possible Gitaly configuations.
-
.ensure_single_socket! ⇒ Object
We cannot create config.toml files for all possible Gitaly configurations.
Methods included from Gitlab::SetupHelper
create_configuration, generate_configuration
Class Method Details
.configuration_toml(gitaly_dir, storage_paths, options) ⇒ Object
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.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gitlab/setup_helper.rb', line 85 def configuration_toml(gitaly_dir, storage_paths, ) socket_path = ensure_single_socket! config = { socket_path: socket_path.delete_prefix('unix:') } if Rails.env.test? # Override the set gitaly_address since Praefect is in the loop socket_path = File.join(gitaly_dir, [:gitaly_socket] || "gitaly.socket") prometheus_listen_addr = [:prometheus_listen_addr] config = { socket_path: socket_path.delete_prefix('unix:'), 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. git: { catfile_cache_size: 5, use_bundled_binaries: true }, prometheus_listen_addr: prometheus_listen_addr }.compact end config[:storage] = storage_paths.map { |name, _| { name: name, path: storage_paths[name].to_s } } runtime_dir = [:runtime_dir] || File.join(gitaly_dir, 'run') FileUtils.mkdir_p(runtime_dir) config[:runtime_dir] = runtime_dir config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path } config[:bin_dir] = File.(File.join(gitaly_dir, '_build', 'bin')) # binaries by default are in `_build/bin` config[:gitlab] = { url: Gitlab.config.gitlab.url } config[:transactions] = { enabled: true } if [:transactions_enabled] config[:logging] = { dir: Rails.root.join('log').to_s } config[:logging][:level] = [:logging_level] if [:logging_level] TomlRB.dump(config) end |
.ensure_single_socket! ⇒ Object
We cannot create config.toml files for all possible Gitaly configurations. 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 validates that we have 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.
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/gitlab/setup_helper.rb', line 130 def ensure_single_socket! addresses = Gitlab.config.repositories.storages.map { |_, storage| storage[:gitaly_address] }.uniq raise ArgumentError, "Your gitlab.yml contains more than one gitaly_address." if addresses.length > 1 address = addresses.first if URI(address).scheme != 'unix' raise ArgumentError, "Automatic config.toml generation only supports 'unix:' addresses." end address end |