Commit a211cb21 authored by Stan Hu's avatar Stan Hu

Fix errors spawning Gitaly master in CI

There were a couple new issues that were caused by Gitaly absorbing
gitlab-shell functionality:

1. The Gitaly `config.toml` now needs the URL of the GitLab host
(https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2168).

2. `.gitlab_shell_secret` is now read by Gitaly at startup
(https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2214).

3. Praefect SQL failover is now enabled by default
(https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2218). We can
disable this for now since we don't need this for the GitLab tests.

Closes https://gitlab.com/gitlab-org/gitaly/-/issues/2831
parent a8141db1
...@@ -79,6 +79,7 @@ module Gitlab ...@@ -79,6 +79,7 @@ module Gitlab
config[:'gitaly-ruby'] = { dir: File.join(gitaly_dir, 'ruby') } if gitaly_ruby config[:'gitaly-ruby'] = { dir: File.join(gitaly_dir, 'ruby') } if gitaly_ruby
config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path } config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path }
config[:bin_dir] = Gitlab.config.gitaly.client_path config[:bin_dir] = Gitlab.config.gitaly.client_path
config[:gitlab] = { url: Gitlab.config.gitlab.url }
TomlRB.dump(config) TomlRB.dump(config)
end end
...@@ -97,7 +98,8 @@ module Gitlab ...@@ -97,7 +98,8 @@ module Gitlab
def configuration_toml(gitaly_dir, storage_paths) def configuration_toml(gitaly_dir, storage_paths)
nodes = [{ storage: 'default', address: "unix:#{gitaly_dir}/gitaly.socket", primary: true, token: 'secret' }] nodes = [{ storage: 'default', address: "unix:#{gitaly_dir}/gitaly.socket", primary: true, token: 'secret' }]
storages = [{ name: 'default', node: nodes }] storages = [{ name: 'default', node: nodes }]
config = { socket_path: "#{gitaly_dir}/praefect.socket", memory_queue_enabled: true, virtual_storage: storages } failover = { enabled: false }
config = { socket_path: "#{gitaly_dir}/praefect.socket", memory_queue_enabled: true, virtual_storage: storages, failover: failover }
config[:token] = 'secret' if Rails.env.test? config[:token] = 'secret' if Rails.env.test?
TomlRB.dump(config) TomlRB.dump(config)
......
...@@ -14,6 +14,7 @@ class GitalyTestBuild ...@@ -14,6 +14,7 @@ class GitalyTestBuild
def run def run
abort 'gitaly build failed' unless system(env, 'make', chdir: tmp_tests_gitaly_dir) abort 'gitaly build failed' unless system(env, 'make', chdir: tmp_tests_gitaly_dir)
ensure_gitlab_shell_secret!
check_gitaly_config! check_gitaly_config!
# Starting gitaly further validates its configuration # Starting gitaly further validates its configuration
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# Please be careful when modifying this file. Your changes must work # Please be careful when modifying this file. Your changes must work
# both for local development rspec runs, and in CI. # both for local development rspec runs, and in CI.
require 'securerandom'
require 'socket' require 'socket'
module GitalyTest module GitalyTest
...@@ -11,10 +12,22 @@ module GitalyTest ...@@ -11,10 +12,22 @@ module GitalyTest
File.expand_path('../tmp/tests/gitaly', __dir__) File.expand_path('../tmp/tests/gitaly', __dir__)
end end
def tmp_tests_gitlab_shell_dir
File.expand_path('../tmp/tests/gitlab-shell', __dir__)
end
def rails_gitlab_shell_secret
File.expand_path('../.gitlab_shell_secret', __dir__)
end
def gemfile def gemfile
File.join(tmp_tests_gitaly_dir, 'ruby', 'Gemfile') File.join(tmp_tests_gitaly_dir, 'ruby', 'Gemfile')
end end
def gitlab_shell_secret_file
File.join(tmp_tests_gitlab_shell_dir, '.gitlab_shell_secret')
end
def env def env
env_hash = { env_hash = {
'HOME' => File.expand_path('tmp/tests'), 'HOME' => File.expand_path('tmp/tests'),
...@@ -70,6 +83,20 @@ module GitalyTest ...@@ -70,6 +83,20 @@ module GitalyTest
pid pid
end end
# Taken from Gitlab::Shell.generate_and_link_secret_token
def ensure_gitlab_shell_secret!
secret_file = rails_gitlab_shell_secret
shell_link = gitlab_shell_secret_file
unless File.size?(secret_file)
File.write(secret_file, SecureRandom.hex(16))
end
unless File.exist?(shell_link)
FileUtils.ln_s(secret_file, shell_link)
end
end
def check_gitaly_config! def check_gitaly_config!
puts "Checking gitaly-ruby Gemfile..." puts "Checking gitaly-ruby Gemfile..."
......
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