Skip to content

Commit 4beb352

Browse files
author
Ahmad Sherif
committed
Create git_data_dirs even if gitlab_rails is disabled
Currently, `gitlab_rails` service needs to be enabled in order for `gitaly` service to function properly. Specifically, `gitlab_rails` creates `git_data_dirs` (e.g. `/var/opt/gitlab/git-data/repositories`) which is needed for Gitaly to start-up. If only the `gitaly` service is enabled, then Gitaly won't start due to config validation error (i.e. storage directories have to be present). This MR makes the creation of these directories the responsibility of the `gitaly` cookbook. The `gitlab` cookbook still creates the directories as backward-compatibility measure, as I'm not sure if these directories are needed outside of Gitaly. This is needed as part of https://gitlab.com/gitlab-com/gl-infra/production-engineering/-/issues/24530. Changelog: fixed
1 parent f09ef50 commit 4beb352

File tree

6 files changed

+74
-27
lines changed

6 files changed

+74
-27
lines changed

files/gitlab-cookbooks/gitaly/recipes/enable.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
cgroups_hierarchy_root = node.dig('gitaly', 'configuration', 'cgroups', 'hierarchy_root')
3333
use_wrapper = node['gitaly']['use_wrapper']
3434

35+
include_recipe 'gitaly::git_data_dirs'
36+
3537
directory working_dir do
3638
owner account_helper.gitlab_user
3739
mode '0700'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
# Copyright:: Copyright (c) 2024 GitLab Inc.
3+
# License:: Apache License, Version 2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
account_helper = AccountHelper.new(node)
19+
gitlab_user = account_helper.gitlab_user
20+
gitlab_group = account_helper.gitlab_group
21+
22+
# Holds git-data, by default one shard at /var/opt/gitlab/git-data
23+
# Can be changed by user using git_data_dirs option
24+
Mash.new(Gitlab['git_data_dirs']).each do |_name, git_data_directory|
25+
storage_directory git_data_directory['path'] do
26+
owner gitlab_user
27+
group gitlab_group
28+
mode "0700"
29+
end
30+
end
31+
32+
# Holds git repositories, by default at /var/opt/gitlab/git-data/repositories
33+
# Should not be changed by user. Different permissions to git_data_dir set.
34+
repositories_storages = node['gitlab']['gitlab_rails']['repositories_storages']
35+
repositories_storages.each do |_name, repositories_storage|
36+
storage_directory repositories_storage['path'] do
37+
owner gitlab_user
38+
group gitlab_group
39+
mode "2770"
40+
end
41+
end

files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,7 @@
4343
gitlab_user = account_helper.gitlab_user
4444
gitlab_group = account_helper.gitlab_group
4545

46-
# Holds git-data, by default one shard at /var/opt/gitlab/git-data
47-
# Can be changed by user using git_data_dirs option
48-
Mash.new(Gitlab['git_data_dirs']).each do |_name, git_data_directory|
49-
storage_directory git_data_directory['path'] do
50-
owner gitlab_user
51-
group gitlab_group
52-
mode "0700"
53-
end
54-
end
55-
56-
# Holds git repositories, by default at /var/opt/gitlab/git-data/repositories
57-
# Should not be changed by user. Different permissions to git_data_dir set.
58-
repositories_storages = node['gitlab']['gitlab_rails']['repositories_storages']
59-
repositories_storages.each do |_name, repositories_storage|
60-
storage_directory repositories_storage['path'] do
61-
owner gitlab_user
62-
group gitlab_group
63-
mode "2770"
64-
end
65-
end
46+
include_recipe 'gitaly::git_data_dirs'
6647

6748
include_recipe 'gitlab::rails_pages_shared_path'
6849

spec/chef/cookbooks/gitaly/recipes/gitaly_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,26 @@
10311031
RSpec.describe 'gitaly::git_data_dirs' do
10321032
let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
10331033

1034+
before do
1035+
allow(Gitlab).to receive(:[]).and_call_original
1036+
1037+
stub_gitlab_rb(gitlab_rails: {
1038+
enable: false,
1039+
}, gitaly: {
1040+
enable: true,
1041+
}, git_data_dirs: {
1042+
'default' => {
1043+
'path' => '/tmp/git-data'
1044+
}
1045+
})
1046+
end
1047+
1048+
include_examples "git data directory", "/tmp/git-data"
1049+
end
1050+
1051+
RSpec.describe 'git_data_dirs configuration' do
1052+
let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
1053+
10341054
before do
10351055
allow(Gitlab).to receive(:[]).and_call_original
10361056
end

spec/chef/cookbooks/gitlab/recipes/gitlab-rails_spec.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@
135135
ChefSpec::SoloRunner.converge('gitlab::default')
136136
end
137137

138-
it 'creates the git-data directory' do
139-
expect(chef_run).to create_storage_directory('/tmp/git-data').with(owner: 'git', group: 'git', mode: '0700')
140-
end
141-
142-
it 'creates the repositories directory' do
143-
expect(chef_run).to create_storage_directory('/tmp/git-data/repositories').with(owner: 'git', group: 'git', mode: '2770')
144-
end
138+
include_examples "git data directory", "/tmp/git-data"
145139

146140
it 'creates the shared directory' do
147141
expect(chef_run).to create_storage_directory('/tmp/shared').with(owner: 'git', group: 'gitlab-www', mode: '0751')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
RSpec.shared_examples 'git data directory' do |git_data_path|
2+
it 'creates the git-data directory' do
3+
expect(chef_run).to create_storage_directory(git_data_path).with(owner: 'git', group: 'git', mode: '0700')
4+
end
5+
6+
it 'creates the repositories directory' do
7+
expect(chef_run).to create_storage_directory("#{git_data_path}/repositories").with(owner: 'git', group: 'git', mode: '2770')
8+
end
9+
end

0 commit comments

Comments
 (0)