2017-03-13 14:04:46 +00:00
|
|
|
namespace :gitlab do
|
|
|
|
namespace :gitaly do
|
|
|
|
desc "GitLab | Install or upgrade gitaly"
|
2017-05-02 16:58:37 +00:00
|
|
|
task :install, [:dir, :repo] => :environment do |t, args|
|
2017-04-10 21:33:41 +00:00
|
|
|
require 'toml'
|
|
|
|
|
2017-03-13 14:04:46 +00:00
|
|
|
warn_user_is_not_gitlab
|
|
|
|
unless args.dir.present?
|
|
|
|
abort %(Please specify the directory where you want to install gitaly:\n rake "gitlab:gitaly:install[/home/git/gitaly]")
|
|
|
|
end
|
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
|
|
|
|
2017-05-02 16:58:37 +00:00
|
|
|
checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir)
|
2017-03-13 14:04:46 +00:00
|
|
|
|
2017-11-21 17:45:36 +00:00
|
|
|
command = %w[/usr/bin/env -u RUBYOPT -u BUNDLE_GEMFILE]
|
|
|
|
|
2017-03-13 14:04:46 +00:00
|
|
|
_, status = Gitlab::Popen.popen(%w[which gmake])
|
2017-11-21 17:45:36 +00:00
|
|
|
command << (status.zero? ? 'gmake' : 'make')
|
2017-08-10 16:24:44 +00:00
|
|
|
|
2017-11-21 12:28:02 +00:00
|
|
|
command << 'BUNDLE_FLAGS=--no-deployment' if Rails.env.test?
|
2017-03-13 14:04:46 +00:00
|
|
|
|
|
|
|
Dir.chdir(args.dir) do
|
2017-04-10 21:33:41 +00:00
|
|
|
create_gitaly_configuration
|
2017-07-31 13:17:14 +00:00
|
|
|
# In CI we run scripts/gitaly-test-build instead of this command
|
|
|
|
unless ENV['CI'].present?
|
2017-11-21 17:45:36 +00:00
|
|
|
Bundler.with_original_env { run_command!(command) }
|
2017-07-31 13:17:14 +00:00
|
|
|
end
|
2017-03-13 14:04:46 +00:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 14:06:07 +00:00
|
|
|
|
|
|
|
desc "GitLab | Print storage configuration in TOML format"
|
|
|
|
task storage_config: :environment do
|
|
|
|
require 'toml'
|
|
|
|
|
|
|
|
puts "# Gitaly storage configuration generated from #{Gitlab.config.source} on #{Time.current.to_s(:long)}"
|
|
|
|
puts "# This is in TOML format suitable for use in Gitaly's config.toml file."
|
|
|
|
|
2017-07-31 13:17:14 +00:00
|
|
|
# Exclude gitaly-ruby configuration because that depends on the gitaly
|
|
|
|
# installation directory.
|
|
|
|
puts gitaly_configuration_toml(gitaly_ruby: false)
|
2017-04-04 14:06:07 +00:00
|
|
|
end
|
2017-04-10 21:33:41 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# 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
|
2017-06-12 21:37:43 +00:00
|
|
|
# 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.
|
2017-09-12 10:26:59 +00:00
|
|
|
# For development and testing purposes, an extra storage is added to gitaly,
|
|
|
|
# which is not known to Rails, but must be explicitly stubbed.
|
2017-07-31 13:17:14 +00:00
|
|
|
def gitaly_configuration_toml(gitaly_ruby: true)
|
2017-04-10 21:33:41 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
storages << { name: key, path: val['path'] }
|
|
|
|
end
|
2017-09-12 10:26:59 +00:00
|
|
|
|
|
|
|
if Rails.env.test?
|
|
|
|
storages << { name: 'test_second_storage', path: Rails.root.join('tmp', 'tests', 'second_storage').to_s }
|
|
|
|
end
|
|
|
|
|
2017-06-20 15:42:54 +00:00
|
|
|
config = { socket_path: address.sub(%r{\Aunix:}, ''), storage: storages }
|
|
|
|
config[:auth] = { token: 'secret' } if Rails.env.test?
|
2017-07-31 13:17:14 +00:00
|
|
|
config[:'gitaly-ruby'] = { dir: File.join(Dir.pwd, 'ruby') } if gitaly_ruby
|
2017-08-04 09:42:13 +00:00
|
|
|
config[:'gitlab-shell'] = { dir: Gitlab.config.gitlab_shell.path }
|
2017-06-20 15:42:54 +00:00
|
|
|
TOML.dump(config)
|
2017-06-12 21:37:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_gitaly_configuration
|
2017-11-21 17:45:36 +00:00
|
|
|
File.open("config.toml", File::WRONLY | File::CREAT | File::EXCL) do |f|
|
2017-06-12 21:37:43 +00:00
|
|
|
f.puts gitaly_configuration_toml
|
2017-04-10 21:33:41 +00:00
|
|
|
end
|
2017-11-21 17:45:36 +00:00
|
|
|
rescue Errno::EEXIST
|
|
|
|
puts "Skipping config.toml generation:"
|
|
|
|
puts "A configuration file already exists."
|
2017-04-10 21:33:41 +00:00
|
|
|
rescue ArgumentError => e
|
|
|
|
puts "Skipping config.toml generation:"
|
|
|
|
puts e.message
|
|
|
|
end
|
2017-03-13 14:04:46 +00:00
|
|
|
end
|
|
|
|
end
|