2021-02-05 12:09:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-13 14:04:46 +00:00
|
|
|
namespace :gitlab do
|
|
|
|
namespace :gitaly do
|
2021-12-16 18:14:09 +00:00
|
|
|
desc 'GitLab | Gitaly | Clone and checkout gitaly'
|
|
|
|
task :clone, [:dir, :storage_path, :repo] => :gitlab_environment do |t, args|
|
2017-03-13 14:04:46 +00:00
|
|
|
warn_user_is_not_gitlab
|
2018-01-11 16:34:01 +00:00
|
|
|
|
2018-08-09 05:08:09 +00:00
|
|
|
unless args.dir.present? && args.storage_path.present?
|
|
|
|
abort %(Please specify the directory where you want to install gitaly and the path for the default storage
|
|
|
|
Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]")
|
2017-03-13 14:04:46 +00:00
|
|
|
end
|
2018-01-11 16:34:01 +00:00
|
|
|
|
2017-05-02 16:58:37 +00:00
|
|
|
args.with_defaults(repo: 'https://gitlab.com/gitlab-org/gitaly.git')
|
2017-03-13 14:04:46 +00:00
|
|
|
|
2017-04-10 23:15:48 +00:00
|
|
|
version = Gitlab::GitalyClient.expected_server_version
|
2017-03-13 14:04:46 +00:00
|
|
|
|
2020-05-14 15:08:14 +00:00
|
|
|
checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1])
|
2021-12-16 18:14:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'GitLab | Gitaly | Install or upgrade gitaly'
|
|
|
|
task :install, [:dir, :storage_path, :repo] => [:gitlab_environment, 'gitlab:gitaly:clone'] do |t, args|
|
|
|
|
warn_user_is_not_gitlab
|
2017-03-13 14:04:46 +00:00
|
|
|
|
2018-08-09 05:08:09 +00:00
|
|
|
storage_paths = { 'default' => args.storage_path }
|
2020-03-25 18:08:10 +00:00
|
|
|
Gitlab::SetupHelper::Gitaly.create_configuration(args.dir, storage_paths)
|
2021-04-01 15:08:54 +00:00
|
|
|
|
2017-03-13 14:04:46 +00:00
|
|
|
Dir.chdir(args.dir) do
|
2021-04-01 15:08:54 +00:00
|
|
|
Bundler.with_original_env do
|
|
|
|
env = { "RUBYOPT" => nil, "BUNDLE_GEMFILE" => nil }
|
|
|
|
|
|
|
|
if Rails.env.test?
|
|
|
|
env["GEM_HOME"] = Bundler.bundle_path.to_s
|
|
|
|
env["BUNDLE_DEPLOYMENT"] = 'false'
|
|
|
|
end
|
|
|
|
|
2021-10-25 15:12:11 +00:00
|
|
|
output, status = Gitlab::Popen.popen([make_cmd, 'all', 'git'], nil, env)
|
|
|
|
raise "Gitaly failed to compile: #{output}" unless status&.zero?
|
2017-07-31 13:17:14 +00:00
|
|
|
end
|
2017-03-13 14:04:46 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-01 15:08:54 +00:00
|
|
|
|
|
|
|
def make_cmd
|
|
|
|
_, status = Gitlab::Popen.popen(%w[which gmake])
|
|
|
|
status == 0 ? 'gmake' : 'make'
|
|
|
|
end
|
2021-08-06 06:10:16 +00:00
|
|
|
|
|
|
|
def warn_gitaly_out_of_date!(gitaly_binary, expected_version)
|
|
|
|
binary_version, exit_status = Gitlab::Popen.popen(%W[#{gitaly_binary} -version])
|
|
|
|
|
|
|
|
raise "Failed to run `#{gitaly_binary} -version`" unless exit_status == 0
|
|
|
|
|
|
|
|
binary_version = binary_version.strip
|
|
|
|
|
|
|
|
# See help for `git describe` for format
|
|
|
|
git_describe_sha = /g([a-f0-9]{5,40})\z/
|
|
|
|
match = binary_version.match(git_describe_sha)
|
|
|
|
|
|
|
|
# Just skip if the version does not have a sha component
|
|
|
|
return unless match
|
|
|
|
|
|
|
|
return if expected_version.start_with?(match[1])
|
|
|
|
|
|
|
|
puts "WARNING: #{binary_version.strip} does not exactly match repository version #{expected_version}"
|
|
|
|
end
|
2017-03-13 14:04:46 +00:00
|
|
|
end
|
|
|
|
end
|