diff --git a/doc/settings/configuration.md b/doc/settings/configuration.md index c0868ea163635a2af3dea68eb2b21c10e215b90f_ZG9jL3NldHRpbmdzL2NvbmZpZ3VyYXRpb24ubWQ=..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_ZG9jL3NldHRpbmdzL2NvbmZpZ3VyYXRpb24ubWQ= 100644 --- a/doc/settings/configuration.md +++ b/doc/settings/configuration.md @@ -370,6 +370,22 @@ File `config/initializers/rack_attack.rb` is managed by omnibus-gitlab and must be configured in `/etc/gitlab/gitlab.rb`. +## Disabling automatic cache cleaning during installation + +If you have large gitlab installation, you might not want to run `rake cache:cleaner` task. +As it can take long time to finish. Default `rake_cache_clear` is true. + +Edit `/etc/gitlab/gitlab.rb`: + +```ruby +# This is advanced feature used by large gitlab deployments where loading +# whole RAILS env takes a lot of time. +gitlab_rails['rake_cache_clear'] = false +``` + +Don't forget to remove the `#` comment characters at the beginning of this +line. + ### Enabling/Disabling Rack Attack and setting up basic auth throttling Next configuration settings control Rack Attack: @@ -386,6 +402,6 @@ ### Setting up paths to be protected by Rack Attack -If you want to change default protected paths -set `gitlab_rails['rack_attack_protected_paths']` in config file. +If you want to change default protected paths +set `gitlab_rails['rack_attack_protected_paths']` in config file. @@ -391,5 +407,5 @@ -**Warning** This action will overwrite +**Warning** This action will overwrite list provided by omnibus-gitlab: ```ruby @@ -414,7 +430,7 @@ For example `"/api/#\{API::API.version\}/session.json"` or `'/api/#{API::API.version}/session.json'` -### Setting up throttling for 'paths to be protected' +### Setting up throttling for 'paths to be protected' Use next options to control throttling 'limit' and 'period': ```ruby diff --git a/files/gitlab-config-template/gitlab.rb.template b/files/gitlab-config-template/gitlab.rb.template index c0868ea163635a2af3dea68eb2b21c10e215b90f_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU=..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_ZmlsZXMvZ2l0bGFiLWNvbmZpZy10ZW1wbGF0ZS9naXRsYWIucmIudGVtcGxhdGU= 100644 --- a/files/gitlab-config-template/gitlab.rb.template +++ b/files/gitlab-config-template/gitlab.rb.template @@ -313,6 +313,10 @@ #### Enable or disable automatic database migrations # gitlab_rails['auto_migrate'] = true +#### This is advanced feature used by large gitlab deployments where loading +#### whole RAILS env takes a lot of time. +# gitlab_rails['rake_cache_clear'] = true + ### GitLab database settings ###! Docs: https://docs.gitlab.com/omnibus/settings/database.html ###! **Only needed if you use an external database.** diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index c0868ea163635a2af3dea68eb2b21c10e215b90f_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvYXR0cmlidXRlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -75,6 +75,7 @@ default['gitlab']['gitlab-rails']['rate_limit_requests_per_period'] = 10 default['gitlab']['gitlab-rails']['rate_limit_period'] = 60 default['gitlab']['gitlab-rails']['auto_migrate'] = true +default['gitlab']['gitlab-rails']['rake_cache_clear'] = true default['gitlab']['gitlab-rails']['gitlab_host'] = node['fqdn'] default['gitlab']['gitlab-rails']['gitlab_port'] = 80 diff --git a/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb b/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb index c0868ea163635a2af3dea68eb2b21c10e215b90f_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kYXRhYmFzZV9taWdyYXRpb25zLnJi..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kYXRhYmFzZV9taWdyYXRpb25zLnJi 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb @@ -55,7 +55,7 @@ EOH environment ({'GITLAB_ROOT_PASSWORD' => initial_root_password }) if initial_root_password notifies :run, 'execute[enable pg_trgm extension]', :before unless omnibus_helper.not_listening?("postgresql") || !node['gitlab']['postgresql']['enable'] - notifies :run, "execute[clear the gitlab-rails cache]", :immediately unless omnibus_helper.not_listening?("redis") + notifies :run, "execute[clear the gitlab-rails cache]", :immediately unless omnibus_helper.not_listening?("redis") || !node['gitlab']['gitlab-rails']['rake_cache_clear'] dependent_services.each do |svc| notifies :restart, svc, :immediately end diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb index c0868ea163635a2af3dea68eb2b21c10e215b90f_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHMucmI=..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItcmFpbHMucmI= 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb @@ -242,7 +242,7 @@ ) ) restarts dependent_services - notifies [:run, 'execute[clear the gitlab-rails cache]'] unless redis_not_listening + notifies [:run, 'execute[clear the gitlab-rails cache]'] unless redis_not_listening || !node['gitlab']['gitlab-rails']['rake_cache_clear'] end templatesymlink "Create a rack_attack.rb and create a symlink to Rails root" do diff --git a/spec/chef/recipes/database_migrations_spec.rb b/spec/chef/recipes/database_migrations_spec.rb index c0868ea163635a2af3dea68eb2b21c10e215b90f_c3BlYy9jaGVmL3JlY2lwZXMvZGF0YWJhc2VfbWlncmF0aW9uc19zcGVjLnJi..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_c3BlYy9jaGVmL3JlY2lwZXMvZGF0YWJhc2VfbWlncmF0aW9uc19zcGVjLnJi 100644 --- a/spec/chef/recipes/database_migrations_spec.rb +++ b/spec/chef/recipes/database_migrations_spec.rb @@ -14,6 +14,11 @@ end context 'when migration should run' do + + before do + allow_any_instance_of(OmnibusHelper).to receive(:not_listening?).and_return(false) + end + let(:bash_block) { chef_run.bash('migrate gitlab-rails database') } context 'places the log file' do @@ -34,5 +39,15 @@ migrate = %Q(/opt/gitlab/bin/gitlab-rake gitlab:db:configure 2>& 1 | tee ${log_file}) expect(bash_block.code).to match(/#{migrate}/) end + + # NOTE: Test if we pass proper notifications to other resources + it 'should notify execute[clear the gitlab-rails cache] resource' do + expect(chef_run.bash('migrate gitlab-rails database')).to notify('execute[clear the gitlab-rails cache]') + end + + it 'should not notify execute[clear the gitlab-rails cache] resource when disabled' do + stub_gitlab_rb(gitlab_rails: { rake_cache_clear: false }) + expect(chef_run.bash('migrate gitlab-rails database')).not_to notify('execute[clear the gitlab-rails cache]') + end end end diff --git a/spec/chef/recipes/gitlab-rails_spec.rb b/spec/chef/recipes/gitlab-rails_spec.rb index c0868ea163635a2af3dea68eb2b21c10e215b90f_c3BlYy9jaGVmL3JlY2lwZXMvZ2l0bGFiLXJhaWxzX3NwZWMucmI=..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_c3BlYy9jaGVmL3JlY2lwZXMvZ2l0bGFiLXJhaWxzX3NwZWMucmI= 100644 --- a/spec/chef/recipes/gitlab-rails_spec.rb +++ b/spec/chef/recipes/gitlab-rails_spec.rb @@ -119,6 +119,22 @@ end end end + + # NOTE: Test if we pass proper notifications to other resources + context 'rails cache management' do + before do + allow_any_instance_of(OmnibusHelper).to receive(:not_listening?).and_return(false) + end + + it 'should notify execute[clear the gitlab-rails cache] resource' do + expect(chef_run.templatesymlink('Create a gitlab.yml and create a symlink to Rails root')).to notify('execute[clear the gitlab-rails cache]') + end + + it 'should not notify execute[clear the gitlab-rails cache] resource when disabled' do + stub_gitlab_rb(gitlab_rails: { rake_cache_clear: false }) + expect(chef_run.templatesymlink('Create a gitlab.yml and create a symlink to Rails root')).to not_notify('execute[clear the gitlab-rails cache]') + end + end end context 'with environment variables' do diff --git a/spec/chef/recipes/rails_cache_clear_spec.rb b/spec/chef/recipes/rails_cache_clear_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..b0576c63c0cf3af4e34cc67ae2b4480c1021d1ec_c3BlYy9jaGVmL3JlY2lwZXMvcmFpbHNfY2FjaGVfY2xlYXJfc3BlYy5yYg== --- /dev/null +++ b/spec/chef/recipes/rails_cache_clear_spec.rb @@ -0,0 +1,40 @@ +require 'chef_helper' + +# NOTE: We do not try to verify if we pass proper notifications to +# execute['clear the gitlab-rails cache'] resource that's done in other specs +# We just test if we use proper command and that we can change default +# attribute value with gilab.rb setting. + +describe 'gitlab::rails-cache-clear' do + let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') } + + before do + allow(Gitlab).to receive(:[]).and_call_original + end + + context 'test clear cache execution' do + let(:clear_cache_exec) { chef_run.execute('clear the gitlab-rails cache') } + + it 'check rake_cache_clear default attribute value set to true' do + expect(chef_run.node['gitlab']['gitlab-rails']['rake_cache_clear']) + .to eql(true) + end + + it 'check rake_cache_clear attribute value set to true' do + stub_gitlab_rb(gitlab_rails: { rake_cache_clear: true }) + expect(chef_run.node['gitlab']['gitlab-rails']['rake_cache_clear']) + .to eql(true) + end + + it 'check rake_cache_clear attribute value set to false' do + stub_gitlab_rb(gitlab_rails: { rake_cache_clear: false }) + expect(chef_run.node['gitlab']['gitlab-rails']['rake_cache_clear']) + .to eql(false) + end + + it 'check command used to clear cache' do + expect(clear_cache_exec.command).to match('/opt/gitlab/bin/gitlab-rake cache:clear') + expect(clear_cache_exec).to do_nothing + end + end +end