Merge branch '2032-workhorse-config' into 'master'
Configuration file for gitlab-workhorse Closes #2032 See merge request !1361
This commit is contained in:
commit
835144eed2
|
@ -5,18 +5,24 @@ class RedisHelper
|
|||
@node = node
|
||||
end
|
||||
|
||||
def redis_url
|
||||
def redis_url(workhorse = false)
|
||||
gitlab_rails = @node['gitlab']['gitlab-rails']
|
||||
|
||||
if gitlab_rails['redis_socket']
|
||||
uri = URI('unix:/')
|
||||
uri.path = gitlab_rails['redis_socket']
|
||||
else
|
||||
uri = URI::Redis.parse('redis:/')
|
||||
uri.host = gitlab_rails['redis_host']
|
||||
uri.port = gitlab_rails['redis_port']
|
||||
uri.password = gitlab_rails['redis_password']
|
||||
uri.path = "/#{gitlab_rails['redis_database']}"
|
||||
if workhorse
|
||||
uri = URI('tcp:/')
|
||||
uri.host = gitlab_rails['redis_host']
|
||||
uri.port = gitlab_rails['redis_port']
|
||||
else
|
||||
uri = URI::Redis.parse('redis:/')
|
||||
uri.host = gitlab_rails['redis_host']
|
||||
uri.port = gitlab_rails['redis_port']
|
||||
uri.password = gitlab_rails['redis_password']
|
||||
uri.path = "/#{gitlab_rails['redis_database']}"
|
||||
end
|
||||
end
|
||||
|
||||
uri
|
||||
|
|
|
@ -56,3 +56,17 @@ file File.join(working_dir, "VERSION") do
|
|||
content VersionHelper.version("/opt/gitlab/embedded/bin/gitlab-workhorse --version")
|
||||
notifies :restart, "service[gitlab-workhorse]"
|
||||
end
|
||||
|
||||
redis_url = RedisHelper.new(node).redis_url(true).to_s
|
||||
redis_password = node['gitlab']['gitlab-rails']['redis_password']
|
||||
redis_sentinels = node['gitlab']['gitlab-rails']['redis_sentinels']
|
||||
redis_sentinel_master = node['gitlab']['redis']['master_name']
|
||||
redis_sentinel_master_password = node['gitlab']['redis']['master_password']
|
||||
config_file_path = File.join(working_dir, "config.toml")
|
||||
|
||||
template config_file_path do
|
||||
source "workhorse-config.toml.erb"
|
||||
owner account_helper.gitlab_user
|
||||
variables(:redis_url => redis_url, :password => redis_password, :sentinels => redis_sentinels, :sentinel_master => redis_sentinel_master, :master_password => redis_sentinel_master_password)
|
||||
notifies :restart, "service[gitlab-workhorse]"
|
||||
end
|
||||
|
|
|
@ -36,7 +36,8 @@ exec chpst -e /opt/gitlab/etc/gitlab-workhorse/env -P \
|
|||
<% end %>
|
||||
-secretPath /opt/gitlab/embedded/service/gitlab-rails/.gitlab_workhorse_secret \
|
||||
<% if node['gitlab']['gitlab-workhorse']['api_ci_long_polling_duration'] %>
|
||||
-apiCiLongPollingDuration <%= node['gitlab']['gitlab-workhorse']['api_ci_long_polling_duration'] %>
|
||||
-apiCiLongPollingDuration <%= node['gitlab']['gitlab-workhorse']['api_ci_long_polling_duration'] %> \
|
||||
<% end %>
|
||||
-config config.toml \
|
||||
|
||||
# Do not remove this line; it prevents trouble with the trailing backslashes above.
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[redis]
|
||||
<% if @sentinels.empty? %>
|
||||
URL = "<%= @redis_url %>"
|
||||
Password = "<%= @password %>"
|
||||
<% else %>
|
||||
Sentinel = <%= @sentinels.map{ |sentinel| "tcp://#{sentinel['host']}:#{sentinel['port']}" }.to_s %>
|
||||
SentinelMaster = "<%= @sentinel_master %>"
|
||||
Password = "<%= @master_password %>"
|
||||
<% end %>
|
|
@ -78,4 +78,120 @@ describe 'gitlab::gitlab-workhorse' do
|
|||
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiCiLongPollingDuration 60s/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with default value for working directory' do
|
||||
it 'should generate config file in the correct directory' do
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml")
|
||||
end
|
||||
end
|
||||
|
||||
context 'with working directory specified' do
|
||||
before do
|
||||
stub_gitlab_rb(gitlab_workhorse: { dir: "/home/random/dir" })
|
||||
end
|
||||
it 'should generate config file in the correct directory' do
|
||||
expect(chef_run).to render_file("/home/random/dir/config.toml")
|
||||
end
|
||||
end
|
||||
|
||||
context 'with default values for redis' do
|
||||
it 'should generate config file' do
|
||||
content_url = 'URL = "unix:/var/opt/gitlab/redis/redis.socket"'
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
|
||||
expect(chef_run).not_to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(/Sentinel/)
|
||||
end
|
||||
|
||||
it 'should pass config file to workhorse' do
|
||||
expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-config config.toml/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with host/port/password values for redis specified and socket disabled' do
|
||||
before do
|
||||
stub_gitlab_rb(
|
||||
gitlab_rails: {
|
||||
redis_host: "10.0.15.1",
|
||||
redis_port: "1234",
|
||||
redis_password: 'examplepassword'
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it 'should generate config file with the specified values' do
|
||||
content_url = 'URL = "tcp://10.0.15.1:1234/"'
|
||||
content_password = 'Password = "examplepassword"'
|
||||
content_sentinel = 'Sentinel'
|
||||
content_sentinel_master = 'SentinelMaster'
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_password)
|
||||
expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel)
|
||||
expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_master)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with socket for redis specified' do
|
||||
before do
|
||||
stub_gitlab_rb(gitlab_rails: { redis_socket: "/home/random/path.socket", redis_password: 'examplepassword' })
|
||||
end
|
||||
|
||||
it 'should generate config file with the specified values' do
|
||||
content_url = 'URL = "unix:/home/random/path.socket"'
|
||||
content_password = 'Password = "examplepassword"'
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_password)
|
||||
expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(/Sentinel/)
|
||||
expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(/SentinelMaster/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with Sentinels specified with default master' do
|
||||
before do
|
||||
stub_gitlab_rb(
|
||||
gitlab_rails: {
|
||||
redis_sentinels: [
|
||||
{'host' => '127.0.0.1', 'port' => 2637},
|
||||
{'host' => '127.0.8.1', 'port' => 1234}
|
||||
]
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it 'should generate config file with the specified values' do
|
||||
content = 'Sentinel = ["tcp://127.0.0.1:2637", "tcp://127.0.8.1:1234"]'
|
||||
content_url = 'URL ='
|
||||
content_sentinel_master = 'SentinelMaster = "gitlab-redis"'
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content)
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_master)
|
||||
expect(chef_run).not_to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with Sentinels and master specified' do
|
||||
before do
|
||||
stub_gitlab_rb(
|
||||
gitlab_rails: {
|
||||
redis_sentinels: [
|
||||
{'host' => '127.0.0.1', 'port' => 26379},
|
||||
{'host' => '127.0.8.1', 'port' => 12345}
|
||||
]
|
||||
},
|
||||
redis: {
|
||||
master_name: 'examplemaster',
|
||||
master_password: 'examplepassword'
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it 'should generate config file with the specified values' do
|
||||
content = 'Sentinel = ["tcp://127.0.0.1:26379", "tcp://127.0.8.1:12345"]'
|
||||
content_sentinel_master = 'SentinelMaster = "examplemaster"'
|
||||
content_sentinel_password = 'Password = "examplepassword"'
|
||||
content_url = 'URL ='
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content)
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_master)
|
||||
expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_password)
|
||||
expect(chef_run).not_to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue