summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2017-04-04 16:06:07 +0200
committerAhmad Sherif <me@ahmadsherif.com>2017-04-04 19:35:35 +0200
commit62521f20e4bfead7b224ea9067be9733fc6e2f90 (patch)
tree8df484fb82fcdd0bbd4afa6b905ed9918e55dcf4
parent5efd67942cec39d733d27a52edc2ebc86babce30 (diff)
downloadgitlab-ce-feature/add-rake-task-prints-storage-config-in-toml.tar.gz
Add rake task that prints TOML storage configurationfeature/add-rake-task-prints-storage-config-in-toml
Closes gitaly#173
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock4
-rw-r--r--lib/tasks/gitlab/gitaly.rake14
-rw-r--r--spec/tasks/gitlab/gitaly_rake_spec.rb32
4 files changed, 52 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
index 910ab318227..089c02119d8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -353,3 +353,5 @@ gem 'sys-filesystem', '~> 1.1.6'
# Gitaly GRPC client
gem 'gitaly', '~> 0.5.0'
+
+gem 'toml-rb', '~> 0.3.15', require: false
diff --git a/Gemfile.lock b/Gemfile.lock
index 304fc9f2bb3..de74761b029 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -117,6 +117,7 @@ GEM
chronic_duration (0.10.6)
numerizer (~> 0.1.1)
chunky_png (1.3.5)
+ citrus (3.0.2)
cliver (0.3.2)
coderay (1.1.1)
coercible (1.0.0)
@@ -784,6 +785,8 @@ GEM
tilt (2.0.6)
timecop (0.8.1)
timfel-krb5-auth (0.8.3)
+ toml-rb (0.3.15)
+ citrus (~> 3.0, > 3.0)
tool (0.2.3)
truncato (0.7.8)
htmlentities (~> 4.3.1)
@@ -1014,6 +1017,7 @@ DEPENDENCIES
test_after_commit (~> 1.1)
thin (~> 1.7.0)
timecop (~> 0.8.0)
+ toml-rb (~> 0.3.15)
truncato (~> 0.7.8)
u2f (~> 0.2.1)
uglifier (~> 2.7.2)
diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake
index c288e17ac8d..9f6cfe3957c 100644
--- a/lib/tasks/gitlab/gitaly.rake
+++ b/lib/tasks/gitlab/gitaly.rake
@@ -19,5 +19,19 @@ namespace :gitlab do
run_command!([command])
end
end
+
+ 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."
+
+ config = Gitlab.config.repositories.storages.map do |key, val|
+ { name: key, path: val['path'] }
+ end
+
+ puts TOML.dump(storage: config)
+ end
end
end
diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb
index d95baddf546..b369dcbb305 100644
--- a/spec/tasks/gitlab/gitaly_rake_spec.rb
+++ b/spec/tasks/gitlab/gitaly_rake_spec.rb
@@ -75,4 +75,36 @@ describe 'gitlab:gitaly namespace rake task' do
end
end
end
+
+ describe 'storage_config' do
+ it 'prints storage configuration in a TOML format' do
+ config = {
+ 'default' => { 'path' => '/path/to/default' },
+ 'nfs_01' => { 'path' => '/path/to/nfs_01' },
+ }
+ allow(Gitlab.config.repositories).to receive(:storages).and_return(config)
+
+ orig_stdout = $stdout
+ $stdout = StringIO.new
+
+ header = ''
+ Timecop.freeze do
+ header = <<~TOML
+ # Gitaly storage configuration generated from #{Gitlab.config.source} on #{Time.current.to_s(:long)}
+ # This is in TOML format suitable for use in Gitaly's config.toml file.
+ TOML
+ run_rake_task('gitlab:gitaly:storage_config')
+ end
+
+ output = $stdout.string
+ $stdout = orig_stdout
+
+ expect(output).to include(header)
+
+ parsed_output = TOML.parse(output)
+ config.each do |name, params|
+ expect(parsed_output['storage']).to include({ 'name' => name, 'path' => params['path'] })
+ end
+ end
+ end
end