diff --git a/files/gitlab-cookbooks/gitaly/recipes/enable.rb b/files/gitlab-cookbooks/gitaly/recipes/enable.rb index a06500a0611e560f37db711c05753adc09424b3f_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRhbHkvcmVjaXBlcy9lbmFibGUucmI=..f3db239d74b37cc8b2a2ed85d1706fd116af3319_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRhbHkvcmVjaXBlcy9lbmFibGUucmI= 100644 --- a/files/gitlab-cookbooks/gitaly/recipes/enable.rb +++ b/files/gitlab-cookbooks/gitaly/recipes/enable.rb @@ -32,6 +32,8 @@ cgroups_hierarchy_root = node.dig('gitaly', 'configuration', 'cgroups', 'hierarchy_root') use_wrapper = node['gitaly']['use_wrapper'] +include_recipe 'gitaly::git_data_dirs' + directory working_dir do owner account_helper.gitlab_user mode '0700' diff --git a/files/gitlab-cookbooks/gitaly/recipes/git_data_dirs.rb b/files/gitlab-cookbooks/gitaly/recipes/git_data_dirs.rb new file mode 100644 index 0000000000000000000000000000000000000000..f3db239d74b37cc8b2a2ed85d1706fd116af3319_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRhbHkvcmVjaXBlcy9naXRfZGF0YV9kaXJzLnJi --- /dev/null +++ b/files/gitlab-cookbooks/gitaly/recipes/git_data_dirs.rb @@ -0,0 +1,41 @@ +# +# Copyright:: Copyright (c) 2024 GitLab Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +account_helper = AccountHelper.new(node) +gitlab_user = account_helper.gitlab_user +gitlab_group = account_helper.gitlab_group + +# Holds git-data, by default one shard at /var/opt/gitlab/git-data +# Can be changed by user using git_data_dirs option +Mash.new(Gitlab['git_data_dirs']).each do |_name, git_data_directory| + storage_directory git_data_directory['path'] do + owner gitlab_user + group gitlab_group + mode "0700" + end +end + +# Holds git repositories, by default at /var/opt/gitlab/git-data/repositories +# Should not be changed by user. Different permissions to git_data_dir set. +repositories_storages = node['gitlab']['gitlab_rails']['repositories_storages'] +repositories_storages.each do |_name, repositories_storage| + storage_directory repositories_storage['path'] do + owner gitlab_user + group gitlab_group + mode "2770" + end +end diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb index a06500a0611e560f37db711c05753adc09424b3f_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHMucmI=..f3db239d74b37cc8b2a2ed85d1706fd116af3319_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHMucmI= 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb @@ -43,26 +43,7 @@ gitlab_user = account_helper.gitlab_user gitlab_group = account_helper.gitlab_group -# Holds git-data, by default one shard at /var/opt/gitlab/git-data -# Can be changed by user using git_data_dirs option -Mash.new(Gitlab['git_data_dirs']).each do |_name, git_data_directory| - storage_directory git_data_directory['path'] do - owner gitlab_user - group gitlab_group - mode "0700" - end -end - -# Holds git repositories, by default at /var/opt/gitlab/git-data/repositories -# Should not be changed by user. Different permissions to git_data_dir set. -repositories_storages = node['gitlab']['gitlab_rails']['repositories_storages'] -repositories_storages.each do |_name, repositories_storage| - storage_directory repositories_storage['path'] do - owner gitlab_user - group gitlab_group - mode "2770" - end -end +include_recipe 'gitaly::git_data_dirs' include_recipe 'gitlab::rails_pages_shared_path' diff --git a/spec/chef/cookbooks/gitaly/recipes/gitaly_spec.rb b/spec/chef/cookbooks/gitaly/recipes/gitaly_spec.rb index a06500a0611e560f37db711c05753adc09424b3f_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRhbHkvcmVjaXBlcy9naXRhbHlfc3BlYy5yYg==..f3db239d74b37cc8b2a2ed85d1706fd116af3319_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRhbHkvcmVjaXBlcy9naXRhbHlfc3BlYy5yYg== 100644 --- a/spec/chef/cookbooks/gitaly/recipes/gitaly_spec.rb +++ b/spec/chef/cookbooks/gitaly/recipes/gitaly_spec.rb @@ -1033,6 +1033,26 @@ before do allow(Gitlab).to receive(:[]).and_call_original + + stub_gitlab_rb(gitlab_rails: { + enable: false, + }, gitaly: { + enable: true, + }, git_data_dirs: { + 'default' => { + 'path' => '/tmp/git-data' + } + }) + end + + include_examples "git data directory", "/tmp/git-data" +end + +RSpec.describe 'git_data_dirs configuration' do + let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') } + + before do + allow(Gitlab).to receive(:[]).and_call_original end context 'when user has not specified git_data_dir' do diff --git a/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb index a06500a0611e560f37db711c05753adc09424b3f_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHNfc3BlYy5yYg==..f3db239d74b37cc8b2a2ed85d1706fd116af3319_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHNfc3BlYy5yYg== 100644 --- a/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb +++ b/spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb @@ -135,13 +135,7 @@ ChefSpec::SoloRunner.converge('gitlab::default') end - it 'creates the git-data directory' do - expect(chef_run).to create_storage_directory('/tmp/git-data').with(owner: 'git', group: 'git', mode: '0700') - end - - it 'creates the repositories directory' do - expect(chef_run).to create_storage_directory('/tmp/git-data/repositories').with(owner: 'git', group: 'git', mode: '2770') - end + include_examples "git data directory", "/tmp/git-data" it 'creates the shared directory' do expect(chef_run).to create_storage_directory('/tmp/shared').with(owner: 'git', group: 'gitlab-www', mode: '0751') diff --git a/spec/chef/support/shared_examples/git_data_dirs.rb b/spec/chef/support/shared_examples/git_data_dirs.rb new file mode 100644 index 0000000000000000000000000000000000000000..f3db239d74b37cc8b2a2ed85d1706fd116af3319_c3BlYy9jaGVmL3N1cHBvcnQvc2hhcmVkX2V4YW1wbGVzL2dpdF9kYXRhX2RpcnMucmI= --- /dev/null +++ b/spec/chef/support/shared_examples/git_data_dirs.rb @@ -0,0 +1,9 @@ +RSpec.shared_examples 'git data directory' do |git_data_path| + it 'creates the git-data directory' do + expect(chef_run).to create_storage_directory(git_data_path).with(owner: 'git', group: 'git', mode: '0700') + end + + it 'creates the repositories directory' do + expect(chef_run).to create_storage_directory("#{git_data_path}/repositories").with(owner: 'git', group: 'git', mode: '2770') + end +end