Merge branch '1826-rake-cache-clear-attribute' into 'master'

Add support for rake_cache_clear attribute to enable/disable cleaning rails cache during chef run

Closes #1826

See merge request !1198
This commit is contained in:
Marin Jankovski 2017-01-26 10:48:08 +00:00
commit e4ba99139c
8 changed files with 113 additions and 8 deletions

View File

@ -370,6 +370,23 @@ for more information.
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:clean` task.
As it can take long time to finish. By default, cache clear task will run automatically
during reconfigure.
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,10 +403,10 @@ gitlab_rails['rack_attack_git_basic_auth'] = {
### 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.
**Warning** This action will overwrite
**Warning** This action will overwrite
list provided by omnibus-gitlab:
```ruby
@ -414,7 +431,7 @@ then you need to escape curly brackets or use single quoted string.
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

View File

@ -322,6 +322,10 @@ external_url 'GENERATED_EXTERNAL_URL'
#### 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.**

View File

@ -75,6 +75,7 @@ default['gitlab']['gitlab-rails']['uploads_directory'] = "/var/opt/gitlab/gitlab
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

View File

@ -60,7 +60,7 @@ bash "migrate gitlab-rails database" do
EOH
environment env_variables unless env_variables.empty?
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

View File

@ -245,7 +245,7 @@ templatesymlink "Create a gitlab.yml and create a symlink to Rails root" do
)
)
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

View File

@ -14,6 +14,11 @@ describe 'gitlab::database-migrations' do
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') }
it 'runs the migrations' do
@ -65,5 +70,17 @@ describe 'gitlab::database-migrations' do
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 rails cache clear resource' do
expect(chef_run.bash('migrate gitlab-rails database')).to notify(
'execute[clear the gitlab-rails cache]')
end
it 'should not notify rails cache clear resource if 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

View File

@ -101,20 +101,21 @@ describe 'gitlab::gitlab-rails' do
end
context 'creating gitlab.yml' do
gitlab_yml_path = '/var/opt/gitlab/gitlab-rails/etc/gitlab.yml'
context 'mattermost settings' do
context 'mattermost is configured' do
it 'exposes the mattermost host' do
stub_gitlab_rb(mattermost: { enable: true },
mattermost_external_url: 'http://mattermost.domain.com')
expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab.yml').
expect(chef_run).to render_file(gitlab_yml_path).
with_content("host: http://mattermost.domain.com")
end
end
context 'mattermost is not configured' do
it 'has empty values' do
expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/gitlab.yml').
expect(chef_run).to render_file(gitlab_yml_path).
with_content(/mattermost:\s+enabled: false\s+host:\s+/)
end
end
@ -139,6 +140,28 @@ describe 'gitlab::gitlab-rails' do
end
end
end
context 'creating gitlab.yml' do
let(:gitlab_yml) { chef_run.template(gitlab_yml_path) }
# 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 rails cache clear resource' do
expect(gitlab_yml).to notify('execute[clear the gitlab-rails cache]')
end
it 'should not notify rails cache clear resource if disabled' do
stub_gitlab_rb(gitlab_rails: { rake_cache_clear: false })
expect(gitlab_yml).not_to notify(
'execute[clear the gitlab-rails cache]')
end
end
end
end
context 'with environment variables' do

View File

@ -0,0 +1,43 @@
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') }
let (:gilab_yml_temp) { chef_run.find_resource(:templatesymlink,
'Create a gitlab.yml and create a symlink to Rails root') }
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