summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-04-25 08:21:06 +0000
committerRémy Coutable <remy@rymai.me>2017-04-25 08:21:06 +0000
commita9a1f7a61a71399a95b953272e1ff66d60297571 (patch)
tree8be7331ec6c434b3712dacd8b1a5976d99a20787 /lib/tasks
parent080aac050d852c332181a0e3fed7821d52d16c1a (diff)
parent476037b05b1a773bbe163ad01bc2046e38bf5a1f (diff)
downloadgitlab-ce-a9a1f7a61a71399a95b953272e1ff66d60297571.tar.gz
Merge branch 'gitaly-testing-toml' into 'master'
Gitaly testing toml Closes gitaly#182 See merge request !10605
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gitlab/gitaly.rake37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake
index 8079c6e416c..046780481ba 100644
--- a/lib/tasks/gitlab/gitaly.rake
+++ b/lib/tasks/gitlab/gitaly.rake
@@ -2,6 +2,8 @@ namespace :gitlab do
namespace :gitaly do
desc "GitLab | Install or upgrade gitaly"
task :install, [:dir] => :environment do |t, args|
+ require 'toml'
+
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]")
@@ -16,6 +18,7 @@ namespace :gitlab do
command = status.zero? ? 'gmake' : 'make'
Dir.chdir(args.dir) do
+ create_gitaly_configuration
run_command!([command])
end
end
@@ -33,5 +36,39 @@ namespace :gitlab do
puts TOML.dump(storage: config)
end
+
+ 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
+ # only write a config.toml file in the most common and simplest case: the
+ # case where we have exactly one Gitaly process and we are sure it is
+ # running locally because it uses a Unix socket.
+ def create_gitaly_configuration
+ 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
+
+ File.open("config.toml", "w") do |f|
+ f.puts TOML.dump(socket_path: address.sub(%r{\Aunix:}, ''), storages: storages)
+ end
+ rescue ArgumentError => e
+ puts "Skipping config.toml generation:"
+ puts e.message
+ end
end
end