Commit 80a1afff authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Update storage settings to allow extra values per shard

This will be necessary when adding gitaly settings. This version
doesn't make any functional changes, but allows us to include this
breaking change in 9.0 and add the needed extra settings in the future
with backwards compatibility
parent 95545627
...@@ -81,8 +81,8 @@ module ApplicationSettingsHelper ...@@ -81,8 +81,8 @@ module ApplicationSettingsHelper
end end
def repository_storages_options_for_select def repository_storages_options_for_select
options = Gitlab.config.repositories.storages.map do |name, path| options = Gitlab.config.repositories.storages.map do |name, storage|
["#{name} - #{path}", name] ["#{name} - #{storage['path']}", name]
end end
options_for_select(options, @application_setting.repository_storages) options_for_select(options, @application_setting.repository_storages)
......
...@@ -434,7 +434,7 @@ class Project < ActiveRecord::Base ...@@ -434,7 +434,7 @@ class Project < ActiveRecord::Base
end end
def repository_storage_path def repository_storage_path
Gitlab.config.repositories.storages[repository_storage] Gitlab.config.repositories.storages[repository_storage]['path']
end end
def team def team
......
...@@ -58,10 +58,6 @@ class Repository ...@@ -58,10 +58,6 @@ class Repository
end end
end end
def self.storages
Gitlab.config.repositories.storages
end
def initialize(path_with_namespace, project) def initialize(path_with_namespace, project)
@path_with_namespace = path_with_namespace @path_with_namespace = path_with_namespace
@project = project @project = project
......
...@@ -4,8 +4,8 @@ class PostReceive ...@@ -4,8 +4,8 @@ class PostReceive
extend Gitlab::CurrentSettings extend Gitlab::CurrentSettings
def perform(repo_path, identifier, changes) def perform(repo_path, identifier, changes)
if path = Gitlab.config.repositories.storages.find { |p| repo_path.start_with?(p[1].to_s) } if repository_storage = Gitlab.config.repositories.storages.find { |p| repo_path.start_with?(p[1]['path'].to_s) }
repo_path.gsub!(path[1].to_s, "") repo_path.gsub!(repository_storage[1]['path'].to_s, "")
else else
log("Check gitlab.yml config for correct repositories.storages values. No repository storage path matches \"#{repo_path}\"") log("Check gitlab.yml config for correct repositories.storages values. No repository storage path matches \"#{repo_path}\"")
end end
......
---
title: Update storage settings to allow extra values per repository storage
merge_request: 9597
author:
...@@ -548,7 +548,8 @@ production: &base ...@@ -548,7 +548,8 @@ production: &base
# gitlab-shell invokes Dir.pwd inside the repository path and that results # gitlab-shell invokes Dir.pwd inside the repository path and that results
# real path not the symlink. # real path not the symlink.
storages: # You must have at least a `default` storage path. storages: # You must have at least a `default` storage path.
default: /home/git/repositories/ default:
path: /home/git/repositories/
## Backup settings ## Backup settings
backup: backup:
...@@ -659,7 +660,8 @@ test: ...@@ -659,7 +660,8 @@ test:
path: tmp/tests/gitlab-satellites/ path: tmp/tests/gitlab-satellites/
repositories: repositories:
storages: storages:
default: tmp/tests/repositories/ default:
path: tmp/tests/repositories/
backup: backup:
path: tmp/tests/backups path: tmp/tests/backups
gitlab_shell: gitlab_shell:
......
...@@ -445,8 +445,13 @@ Settings.gitlab_shell['ssh_path_prefix'] ||= Settings.send(:build_gitlab_shell_s ...@@ -445,8 +445,13 @@ Settings.gitlab_shell['ssh_path_prefix'] ||= Settings.send(:build_gitlab_shell_s
# #
Settings['repositories'] ||= Settingslogic.new({}) Settings['repositories'] ||= Settingslogic.new({})
Settings.repositories['storages'] ||= {} Settings.repositories['storages'] ||= {}
# Setting gitlab_shell.repos_path is DEPRECATED and WILL BE REMOVED in version 9.0 unless Settings.repositories.storages['default']
Settings.repositories.storages['default'] ||= Settings.gitlab_shell['repos_path'] || Settings.gitlab['user_home'] + '/repositories/' Settings.repositories.storages['default'] ||= {}
# We set the path only if the default storage doesn't exist, in case it exists
# but follows the pre-9.0 configuration structure. `6_validations.rb` initializer
# will validate all storages and throw a relevant error to the user if necessary.
Settings.repositories.storages['default']['path'] ||= Settings.gitlab['user_home'] + '/repositories/'
end
# #
# The repository_downloads_path is used to remove outdated repository # The repository_downloads_path is used to remove outdated repository
...@@ -455,11 +460,11 @@ Settings.repositories.storages['default'] ||= Settings.gitlab_shell['repos_path' ...@@ -455,11 +460,11 @@ Settings.repositories.storages['default'] ||= Settings.gitlab_shell['repos_path'
# data-integrity issue. In this case, we sets it to the default # data-integrity issue. In this case, we sets it to the default
# repository_downloads_path value. # repository_downloads_path value.
# #
repositories_storages_path = Settings.repositories.storages.values repositories_storages = Settings.repositories.storages.values
repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(/\/$/, '') repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(/\/$/, '')
repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home']) repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home'])
if repository_downloads_path.blank? || repositories_storages_path.any? { |path| [repository_downloads_path, repository_downloads_full_path].include?(path.gsub(/\/$/, '')) } if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs['path'].gsub(/\/$/, '')) }
Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive') Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive')
end end
......
...@@ -4,8 +4,8 @@ end ...@@ -4,8 +4,8 @@ end
def find_parent_path(name, path) def find_parent_path(name, path)
parent = Pathname.new(path).realpath.parent parent = Pathname.new(path).realpath.parent
Gitlab.config.repositories.storages.detect do |n, p| Gitlab.config.repositories.storages.detect do |n, rs|
name != n && Pathname.new(p).realpath == parent name != n && Pathname.new(rs['path']).realpath == parent
end end
end end
...@@ -16,10 +16,22 @@ end ...@@ -16,10 +16,22 @@ end
def validate_storages def validate_storages
storage_validation_error('No repository storage path defined') if Gitlab.config.repositories.storages.empty? storage_validation_error('No repository storage path defined') if Gitlab.config.repositories.storages.empty?
Gitlab.config.repositories.storages.each do |name, path| Gitlab.config.repositories.storages.each do |name, repository_storage|
storage_validation_error("\"#{name}\" is not a valid storage name") unless storage_name_valid?(name) storage_validation_error("\"#{name}\" is not a valid storage name") unless storage_name_valid?(name)
parent_name, _parent_path = find_parent_path(name, path) if repository_storage.is_a?(String)
error = "#{name} is not a valid storage, because it has no `path` key. " \
"It may be configured as:\n\n#{name}:\n path: #{repository_storage}\n\n" \
"Refer to gitlab.yml.example for an updated example"
storage_validation_error(error)
end
if !repository_storage.is_a?(Hash) || repository_storage['path'].nil?
storage_validation_error("#{name} is not a valid storage, because it has no `path` key. Refer to gitlab.yml.example for an updated example")
end
parent_name, _parent_path = find_parent_path(name, repository_storage['path'])
if parent_name if parent_name
storage_validation_error("#{name} is a nested path of #{parent_name}. Nested paths are not supported for repository storages") storage_validation_error("#{name} is a nested path of #{parent_name}. Nested paths are not supported for repository storages")
end end
......
...@@ -8,7 +8,7 @@ class MigrateRepoSize < ActiveRecord::Migration ...@@ -8,7 +8,7 @@ class MigrateRepoSize < ActiveRecord::Migration
project_data.each do |project| project_data.each do |project|
id = project['id'] id = project['id']
namespace_path = project['namespace_path'] || '' namespace_path = project['namespace_path'] || ''
repos_path = Gitlab.config.gitlab_shell['repos_path'] || Gitlab.config.repositories.storages.default repos_path = Gitlab.config.gitlab_shell['repos_path'] || Gitlab.config.repositories.storages.default['path']
path = File.join(repos_path, namespace_path, project['project_path'] + '.git') path = File.join(repos_path, namespace_path, project['project_path'] + '.git')
begin begin
......
...@@ -12,7 +12,7 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration ...@@ -12,7 +12,7 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration
end end
def repository_storage_path def repository_storage_path
Gitlab.config.repositories.storages[repository_storage] Gitlab.config.repositories.storages[repository_storage]['path']
end end
def repository_path def repository_path
......
...@@ -60,7 +60,7 @@ class RemoveDotGitFromGroupNames < ActiveRecord::Migration ...@@ -60,7 +60,7 @@ class RemoveDotGitFromGroupNames < ActiveRecord::Migration
def move_namespace(group_id, path_was, path) def move_namespace(group_id, path_was, path)
repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{group_id}").map do |row| repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{group_id}").map do |row|
Gitlab.config.repositories.storages[row['repository_storage']] Gitlab.config.repositories.storages[row['repository_storage']]['path']
end.compact end.compact
# Move the namespace directory in all storages paths used by member projects # Move the namespace directory in all storages paths used by member projects
......
...@@ -71,7 +71,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration ...@@ -71,7 +71,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
route_exists = route_exists?(path) route_exists = route_exists?(path)
Gitlab.config.repositories.storages.each_value do |storage| Gitlab.config.repositories.storages.each_value do |storage|
if route_exists || path_exists?(path, storage) if route_exists || path_exists?(path, storage['path'])
counter += 1 counter += 1
path = "#{base}#{counter}" path = "#{base}#{counter}"
...@@ -84,7 +84,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration ...@@ -84,7 +84,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
def move_namespace(namespace_id, path_was, path) def move_namespace(namespace_id, path_was, path)
repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{namespace_id}").map do |row| repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{namespace_id}").map do |row|
Gitlab.config.repositories.storages[row['repository_storage']] Gitlab.config.repositories.storages[row['repository_storage']]['path']
end.compact end.compact
# Move the namespace directory in all storages paths used by member projects # Move the namespace directory in all storages paths used by member projects
......
...@@ -52,9 +52,12 @@ respectively. ...@@ -52,9 +52,12 @@ respectively.
# Paths where repositories can be stored. Give the canonicalized absolute pathname. # Paths where repositories can be stored. Give the canonicalized absolute pathname.
# NOTE: REPOS PATHS MUST NOT CONTAIN ANY SYMLINK!!! # NOTE: REPOS PATHS MUST NOT CONTAIN ANY SYMLINK!!!
storages: # You must have at least a 'default' storage path. storages: # You must have at least a 'default' storage path.
default: /home/git/repositories default:
nfs: /mnt/nfs/repositories path: /home/git/repositories
cephfs: /mnt/cephfs/repositories nfs:
path: /mnt/nfs/repositories
cephfs:
path: /mnt/cephfs/repositories
``` ```
1. [Restart GitLab] for the changes to take effect. 1. [Restart GitLab] for the changes to take effect.
...@@ -75,9 +78,9 @@ working, you can remove the `repos_path` line. ...@@ -75,9 +78,9 @@ working, you can remove the `repos_path` line.
```ruby ```ruby
git_data_dirs({ git_data_dirs({
"default" => "/var/opt/gitlab/git-data", "default" => { "path" => "/var/opt/gitlab/git-data" },
"nfs" => "/mnt/nfs/git-data", "nfs" => { "path" => "/mnt/nfs/git-data" },
"cephfs" => "/mnt/cephfs/git-data" "cephfs" => { "path" => "/mnt/cephfs/git-data" }
}) })
``` ```
......
#### Configuration changes for repository storages
This version introduces a new configuration structure for repository storages.
Update your current configuration as follows, replacing with your storages names and paths:
**For installations from source**
1. Update your `gitlab.yml`, from
```yaml
repositories:
storages: # You must have at least a 'default' storage path.
default: /home/git/repositories
nfs: /mnt/nfs/repositories
cephfs: /mnt/cephfs/repositories
```
to
```yaml
repositories:
storages: # You must have at least a 'default' storage path.
default:
path: /home/git/repositories
nfs:
path: /mnt/nfs/repositories
cephfs:
path: /mnt/cephfs/repositories
```
**For Omnibus installations**
1. Upate your `/etc/gitlab/gitlab.rb`, from
```ruby
git_data_dirs({
"default" => "/var/opt/gitlab/git-data",
"nfs" => "/mnt/nfs/git-data",
"cephfs" => "/mnt/cephfs/git-data"
})
```
to
```ruby
git_data_dirs({
"default" => { "path" => "/var/opt/gitlab/git-data" },
"nfs" => { "path" => "/mnt/nfs/git-data" },
"cephfs" => { "path" => "/mnt/cephfs/git-data" }
})
```
#### Nginx configuration #### Nginx configuration
Ensure you're still up-to-date with the latest NGINX configuration changes: Ensure you're still up-to-date with the latest NGINX configuration changes:
......
...@@ -9,11 +9,11 @@ module API ...@@ -9,11 +9,11 @@ module API
# In addition, they may have a '.git' extension and multiple namespaces # In addition, they may have a '.git' extension and multiple namespaces
# #
# Transform all these cases to 'namespace/project' # Transform all these cases to 'namespace/project'
def clean_project_path(project_path, storage_paths = Repository.storages.values) def clean_project_path(project_path, storages = Gitlab.config.repositories.storages.values)
project_path = project_path.sub(/\.git\z/, '') project_path = project_path.sub(/\.git\z/, '')
storage_paths.each do |storage_path| storages.each do |storage|
storage_path = File.expand_path(storage_path) storage_path = File.expand_path(storage['path'])
if project_path.start_with?(storage_path) if project_path.start_with?(storage_path)
project_path = project_path.sub(storage_path, '') project_path = project_path.sub(storage_path, '')
......
...@@ -68,7 +68,8 @@ module Backup ...@@ -68,7 +68,8 @@ module Backup
end end
def restore def restore
Gitlab.config.repositories.storages.each do |name, path| Gitlab.config.repositories.storages.each do |name, repository_storage|
path = repository_storage['path']
next unless File.exist?(path) next unless File.exist?(path)
# Move repos dir to 'repositories.old' dir # Move repos dir to 'repositories.old' dir
...@@ -199,7 +200,7 @@ module Backup ...@@ -199,7 +200,7 @@ module Backup
private private
def repository_storage_paths_args def repository_storage_paths_args
Gitlab.config.repositories.storages.values Gitlab.config.repositories.storages.values.map { |rs| rs['path'] }
end end
end end
end end
...@@ -355,7 +355,8 @@ namespace :gitlab do ...@@ -355,7 +355,8 @@ namespace :gitlab do
def check_repo_base_exists def check_repo_base_exists
puts "Repo base directory exists?" puts "Repo base directory exists?"
Gitlab.config.repositories.storages.each do |name, repo_base_path| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path']
print "#{name}... " print "#{name}... "
if File.exist?(repo_base_path) if File.exist?(repo_base_path)
...@@ -379,7 +380,8 @@ namespace :gitlab do ...@@ -379,7 +380,8 @@ namespace :gitlab do
def check_repo_base_is_not_symlink def check_repo_base_is_not_symlink
puts "Repo storage directories are symlinks?" puts "Repo storage directories are symlinks?"
Gitlab.config.repositories.storages.each do |name, repo_base_path| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path']
print "#{name}... " print "#{name}... "
unless File.exist?(repo_base_path) unless File.exist?(repo_base_path)
...@@ -402,7 +404,8 @@ namespace :gitlab do ...@@ -402,7 +404,8 @@ namespace :gitlab do
def check_repo_base_permissions def check_repo_base_permissions
puts "Repo paths access is drwxrws---?" puts "Repo paths access is drwxrws---?"
Gitlab.config.repositories.storages.each do |name, repo_base_path| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path']
print "#{name}... " print "#{name}... "
unless File.exist?(repo_base_path) unless File.exist?(repo_base_path)
...@@ -432,7 +435,8 @@ namespace :gitlab do ...@@ -432,7 +435,8 @@ namespace :gitlab do
gitlab_shell_owner_group = Gitlab.config.gitlab_shell.owner_group gitlab_shell_owner_group = Gitlab.config.gitlab_shell.owner_group
puts "Repo paths owned by #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group}?" puts "Repo paths owned by #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group}?"
Gitlab.config.repositories.storages.each do |name, repo_base_path| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path']
print "#{name}... " print "#{name}... "
unless File.exist?(repo_base_path) unless File.exist?(repo_base_path)
...@@ -811,8 +815,8 @@ namespace :gitlab do ...@@ -811,8 +815,8 @@ namespace :gitlab do
namespace :repo do namespace :repo do
desc "GitLab | Check the integrity of the repositories managed by GitLab" desc "GitLab | Check the integrity of the repositories managed by GitLab"
task check: :environment do task check: :environment do
Gitlab.config.repositories.storages.each do |name, path| Gitlab.config.repositories.storages.each do |name, repository_storage|
namespace_dirs = Dir.glob(File.join(path, '*')) namespace_dirs = Dir.glob(File.join(repository_storage['path'], '*'))
namespace_dirs.each do |namespace_dir| namespace_dirs.each do |namespace_dir|
repo_dirs = Dir.glob(File.join(namespace_dir, '*')) repo_dirs = Dir.glob(File.join(namespace_dir, '*'))
......
...@@ -6,7 +6,8 @@ namespace :gitlab do ...@@ -6,7 +6,8 @@ namespace :gitlab do
remove_flag = ENV['REMOVE'] remove_flag = ENV['REMOVE']
namespaces = Namespace.pluck(:path) namespaces = Namespace.pluck(:path)
Gitlab.config.repositories.storages.each do |name, git_base_path| Gitlab.config.repositories.storages.each do |name, repository_storage|
git_base_path = repository_storage['path']
all_dirs = Dir.glob(git_base_path + '/*') all_dirs = Dir.glob(git_base_path + '/*')
puts git_base_path.color(:yellow) puts git_base_path.color(:yellow)
...@@ -75,7 +76,8 @@ namespace :gitlab do ...@@ -75,7 +76,8 @@ namespace :gitlab do
warn_user_is_not_gitlab warn_user_is_not_gitlab
move_suffix = "+orphaned+#{Time.now.to_i}" move_suffix = "+orphaned+#{Time.now.to_i}"
Gitlab.config.repositories.storages.each do |name, repo_root| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_root = repository_storage['path']
# Look for global repos (legacy, depth 1) and normal repos (depth 2) # Look for global repos (legacy, depth 1) and normal repos (depth 2)
IO.popen(%W(find #{repo_root} -mindepth 1 -maxdepth 2 -name *.git)) do |find| IO.popen(%W(find #{repo_root} -mindepth 1 -maxdepth 2 -name *.git)) do |find|
find.each_line do |path| find.each_line do |path|
......
...@@ -11,7 +11,8 @@ namespace :gitlab do ...@@ -11,7 +11,8 @@ namespace :gitlab do
# #
desc "GitLab | Import bare repositories from repositories -> storages into GitLab project instance" desc "GitLab | Import bare repositories from repositories -> storages into GitLab project instance"
task repos: :environment do task repos: :environment do
Gitlab.config.repositories.storages.each do |name, git_base_path| Gitlab.config.repositories.storages.each_value do |repository_storage|
git_base_path = repository_storage['path']
repos_to_import = Dir.glob(git_base_path + '/**/*.git') repos_to_import = Dir.glob(git_base_path + '/**/*.git')
repos_to_import.each do |repo_path| repos_to_import.each do |repo_path|
......
...@@ -77,8 +77,8 @@ namespace :gitlab do ...@@ -77,8 +77,8 @@ namespace :gitlab do
puts "GitLab Shell".color(:yellow) puts "GitLab Shell".color(:yellow)
puts "Version:\t#{gitlab_shell_version || "unknown".color(:red)}" puts "Version:\t#{gitlab_shell_version || "unknown".color(:red)}"
puts "Repository storage paths:" puts "Repository storage paths:"
Gitlab.config.repositories.storages.each do |name, path| Gitlab.config.repositories.storages.each do |name, repository_storage|
puts "- #{name}: \t#{path}" puts "- #{name}: \t#{repository_storage['path']}"
end end
puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}" puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}"
puts "Git:\t\t#{Gitlab.config.git.bin_path}" puts "Git:\t\t#{Gitlab.config.git.bin_path}"
......
...@@ -130,8 +130,8 @@ module Gitlab ...@@ -130,8 +130,8 @@ module Gitlab
end end
def all_repos def all_repos
Gitlab.config.repositories.storages.each do |name, path| Gitlab.config.repositories.storages.each_value do |repository_storage|
IO.popen(%W(find #{path} -mindepth 2 -maxdepth 2 -type d -name *.git)) do |find| IO.popen(%W(find #{repository_storage['path']} -mindepth 2 -maxdepth 2 -type d -name *.git)) do |find|
find.each_line do |path| find.each_line do |path|
yield path.chomp yield path.chomp
end end
...@@ -140,7 +140,7 @@ module Gitlab ...@@ -140,7 +140,7 @@ module Gitlab
end end
def repository_storage_paths_args def repository_storage_paths_args
Gitlab.config.repositories.storages.values Gitlab.config.repositories.storages.values.map { |rs| rs['path'] }
end end
def user_home def user_home
......
...@@ -14,7 +14,7 @@ describe '6_validations', lib: true do ...@@ -14,7 +14,7 @@ describe '6_validations', lib: true do
context 'with correct settings' do context 'with correct settings' do
before do before do
mock_storages('foo' => 'tmp/tests/paths/a/b/c', 'bar' => 'tmp/tests/paths/a/b/d') mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/d' })
end end
it 'passes through' do it 'passes through' do
...@@ -24,7 +24,7 @@ describe '6_validations', lib: true do ...@@ -24,7 +24,7 @@ describe '6_validations', lib: true do
context 'with invalid storage names' do context 'with invalid storage names' do
before do before do
mock_storages('name with spaces' => 'tmp/tests/paths/a/b/c') mock_storages('name with spaces' => { 'path' => 'tmp/tests/paths/a/b/c' })
end end
it 'throws an error' do it 'throws an error' do
...@@ -34,7 +34,7 @@ describe '6_validations', lib: true do ...@@ -34,7 +34,7 @@ describe '6_validations', lib: true do
context 'with nested storage paths' do context 'with nested storage paths' do
before do before do
mock_storages('foo' => 'tmp/tests/paths/a/b/c', 'bar' => 'tmp/tests/paths/a/b/c/d') mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/c/d' })
end end
it 'throws an error' do it 'throws an error' do
...@@ -44,7 +44,7 @@ describe '6_validations', lib: true do ...@@ -44,7 +44,7 @@ describe '6_validations', lib: true do
context 'with similar but un-nested storage paths' do context 'with similar but un-nested storage paths' do
before do before do
mock_storages('foo' => 'tmp/tests/paths/a/b/c', 'bar' => 'tmp/tests/paths/a/b/c2') mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/c2' })
end end
it 'passes through' do it 'passes through' do
...@@ -52,6 +52,26 @@ describe '6_validations', lib: true do ...@@ -52,6 +52,26 @@ describe '6_validations', lib: true do
end end
end end
context 'with incomplete settings' do
before do
mock_storages('foo' => {})
end
it 'throws an error suggesting the user to update its settings' do
expect { validate_storages }.to raise_error('foo is not a valid storage, because it has no `path` key. Refer to gitlab.yml.example for an updated example. Please fix this in your gitlab.yml before starting GitLab.')
end
end
context 'with deprecated settings structure' do
before do
mock_storages('foo' => 'tmp/tests/paths/a/b/c')
end
it 'throws an error suggesting the user to update its settings' do
expect { validate_storages }.to raise_error("foo is not a valid storage, because it has no `path` key. It may be configured as:\n\nfoo:\n path: tmp/tests/paths/a/b/c\n\nRefer to gitlab.yml.example for an updated example. Please fix this in your gitlab.yml before starting GitLab.")
end
end
def mock_storages(storages) def mock_storages(storages)
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
......
...@@ -163,7 +163,7 @@ describe Namespace, models: true do ...@@ -163,7 +163,7 @@ describe Namespace, models: true do
describe :rm_dir do describe :rm_dir do
let!(:project) { create(:empty_project, namespace: namespace) } let!(:project) { create(:empty_project, namespace: namespace) }
let!(:path) { File.join(Gitlab.config.repositories.storages.default, namespace.full_path) } let!(:path) { File.join(Gitlab.config.repositories.storages.default['path'], namespace.full_path) }
it "removes its dirs when deleted" do it "removes its dirs when deleted" do
namespace.destroy namespace.destroy
......
...@@ -183,7 +183,7 @@ describe Project, models: true do ...@@ -183,7 +183,7 @@ describe Project, models: true do
let(:project2) { build(:empty_project, repository_storage: 'missing') } let(:project2) { build(:empty_project, repository_storage: 'missing') }
before do before do
storages = { 'custom' => 'tmp/tests/custom_repositories' } storages = { 'custom' => { 'path' => 'tmp/tests/custom_repositories' } }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
...@@ -392,7 +392,7 @@ describe Project, models: true do ...@@ -392,7 +392,7 @@ describe Project, models: true do
before do before do
FileUtils.mkdir('tmp/tests/custom_repositories') FileUtils.mkdir('tmp/tests/custom_repositories')
storages = { 'custom' => 'tmp/tests/custom_repositories' } storages = { 'custom' => { 'path' => 'tmp/tests/custom_repositories' } }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
...@@ -1138,8 +1138,8 @@ describe Project, models: true do ...@@ -1138,8 +1138,8 @@ describe Project, models: true do
before do before do
storages = { storages = {
'default' => 'tmp/tests/repositories', 'default' => { 'path' => 'tmp/tests/repositories' },
'picked' => 'tmp/tests/repositories', 'picked' => { 'path' => 'tmp/tests/repositories' },
} }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
......
...@@ -21,7 +21,7 @@ describe ::API::Helpers::InternalHelpers do ...@@ -21,7 +21,7 @@ describe ::API::Helpers::InternalHelpers do
# Relative and absolute storage paths, with and without trailing / # Relative and absolute storage paths, with and without trailing /
['.', './', Dir.pwd, Dir.pwd + '/'].each do |storage_path| ['.', './', Dir.pwd, Dir.pwd + '/'].each do |storage_path|
context "storage path is #{storage_path}" do context "storage path is #{storage_path}" do
subject { clean_project_path(project_path, [storage_path]) } subject { clean_project_path(project_path, [{ 'path' => storage_path }]) }
it { is_expected.to eq(expected) } it { is_expected.to eq(expected) }
end end
......
...@@ -145,7 +145,7 @@ module TestEnv ...@@ -145,7 +145,7 @@ module TestEnv
end end
def repos_path def repos_path
Gitlab.config.repositories.storages.default Gitlab.config.repositories.storages.default['path']
end end
def backup_path def backup_path
......
...@@ -227,8 +227,8 @@ describe 'gitlab:app namespace rake task' do ...@@ -227,8 +227,8 @@ describe 'gitlab:app namespace rake task' do
FileUtils.mkdir('tmp/tests/default_storage') FileUtils.mkdir('tmp/tests/default_storage')
FileUtils.mkdir('tmp/tests/custom_storage') FileUtils.mkdir('tmp/tests/custom_storage')
storages = { storages = {
'default' => 'tmp/tests/default_storage', 'default' => { 'path' => 'tmp/tests/default_storage' },
'custom' => 'tmp/tests/custom_storage' 'custom' => { 'path' => 'tmp/tests/custom_storage' }
} }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
......
...@@ -116,6 +116,6 @@ describe PostReceive do ...@@ -116,6 +116,6 @@ describe PostReceive do
end end
def pwd(project) def pwd(project)
File.join(Gitlab.config.repositories.storages.default, project.path_with_namespace) File.join(Gitlab.config.repositories.storages.default['path'], project.path_with_namespace)
end end
end end
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