Commit 5384c720 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'env-var-in-redis-config' into 'master'

Allow to use ENV variables in redis config

See merge request !8073
parents 7a3ddc52 a532c604
---
title: Allow to use ENV variables in redis config
merge_request: 8073
author: Semyon Pupkov
...@@ -601,6 +601,12 @@ If you want to connect the Redis server via socket, then use the "unix:" URL sch ...@@ -601,6 +601,12 @@ If you want to connect the Redis server via socket, then use the "unix:" URL sch
production: production:
url: unix:/path/to/redis/socket url: unix:/path/to/redis/socket
Also you can use environment variables in the `config/resque.yml` file:
# example
production:
url: <%= ENV.fetch('GITLAB_REDIS_URL') %>
### Custom SSH Connection ### Custom SSH Connection
If you are running SSH on a non-standard port, you must change the GitLab user's SSH config. If you are running SSH on a non-standard port, you must change the GitLab user's SSH config.
......
...@@ -42,7 +42,7 @@ module Gitlab ...@@ -42,7 +42,7 @@ module Gitlab
return @_raw_config if defined?(@_raw_config) return @_raw_config if defined?(@_raw_config)
begin begin
@_raw_config = File.read(CONFIG_FILE).freeze @_raw_config = ERB.new(File.read(CONFIG_FILE)).result.freeze
rescue Errno::ENOENT rescue Errno::ENOENT
@_raw_config = false @_raw_config = false
end end
......
test:
url: <%= ENV['TEST_GITLAB_REDIS_URL'] %>
require 'spec_helper' require 'spec_helper'
describe Gitlab::Redis do describe Gitlab::Redis do
let(:redis_config) { Rails.root.join('config', 'resque.yml').to_s } include StubENV
before(:each) { clear_raw_config } before(:each) { clear_raw_config }
after(:each) { clear_raw_config } after(:each) { clear_raw_config }
...@@ -72,6 +72,20 @@ describe Gitlab::Redis do ...@@ -72,6 +72,20 @@ describe Gitlab::Redis do
expect(url2).not_to end_with('foobar') expect(url2).not_to end_with('foobar')
end end
context 'when yml file with env variable' do
let(:redis_config) { Rails.root.join('spec/fixtures/config/redis_config_with_env.yml') }
before do
stub_env('TEST_GITLAB_REDIS_URL', 'redis://redishost:6379')
end
it 'reads redis url from env variable' do
stub_const("#{described_class}::CONFIG_FILE", redis_config)
expect(described_class.url).to eq 'redis://redishost:6379'
end
end
end end
describe '._raw_config' do describe '._raw_config' do
......
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