Skip to content
Snippets Groups Projects
Commit 48b6306a authored by Ian Baum's avatar Ian Baum
Browse files

Merge branch 'sh-route-internal-api-workhorse' into 'master'

Make Gitaly internal API calls go through Workhorse

Closes #5666

See merge request gitlab-org/omnibus-gitlab!4592
parents f29fff74 9c16014a
No related branches found
No related tags found
No related merge requests found
---
title: Make Gitaly internal API calls go through Workhorse
merge_request: 4592
author:
type: changed
Loading
Loading
@@ -71,10 +71,7 @@ env_dir env_directory do
notifies :restart, "runit_service[gitaly]" if omnibus_helper.should_notify?('gitaly')
end
 
# If no internal_api_url is specified, default to the IP/port Unicorn listens on
webserver_service = WebServerHelper.service_name
gitlab_url = node['gitlab']['gitlab-rails']['internal_api_url']
gitlab_url ||= "http://#{node['gitlab'][webserver_service]['listen']}:#{node['gitlab'][webserver_service]['port']}#{node['gitlab'][webserver_service]['relative_url']}"
gitlab_url, gitlab_relative_path = WebServerHelper.internal_api_url(node)
 
template "Create Gitaly config.toml" do
path config_path
Loading
Loading
@@ -84,7 +81,8 @@ template "Create Gitaly config.toml" do
mode "0640"
variables node['gitaly'].to_hash.merge(
{ gitlab_shell: node['gitlab']['gitlab-shell'].to_hash,
gitlab_url: gitlab_url }
gitlab_url: gitlab_url,
gitlab_relative_path: gitlab_relative_path }
)
notifies :hup, "runit_service[gitaly]" if omnibus_helper.should_notify?('gitaly')
end
Loading
Loading
Loading
Loading
@@ -103,6 +103,10 @@ dir = "/opt/gitlab/embedded/service/gitlab-shell"
<% if @gitlab_url %>
url = '<%= @gitlab_url %>'
<% end %>
<% if @gitlab_relative_path %>
relative_url_root = '<%= @gitlab_relative_path %>'
<% end %>
<% if @gitlab_shell['http_settings'] %>
<% http_settings = @gitlab_shell['http_settings'] %>
[gitlab.http-settings]
Loading
Loading
Loading
Loading
@@ -12,5 +12,18 @@ class WebServerHelper
'puma'
end
end
def internal_api_url(node)
gitlab_url = node['gitlab']['gitlab-rails']['internal_api_url']
# If no internal_api_url is specified, default to Workhorse settings
use_socket = node['gitlab']['gitlab-workhorse']['listen_network'] == "unix"
workhorse_url = node['gitlab']['gitlab-workhorse']['listen_addr']
relative_path = Gitlab['gitlab_workhorse']['relative_url']
gitlab_url ||= use_socket ? "http+unix://#{ERB::Util.url_encode(workhorse_url)}" : "http://#{workhorse_url}#{relative_path}"
gitlab_relative_path = relative_path || '' if use_socket
[gitlab_url, gitlab_relative_path]
end
end
end
Loading
Loading
@@ -49,15 +49,7 @@ end
end
end
 
gitlab_url = node['gitlab']['gitlab-rails']['internal_api_url']
# If no internal_api_url is specified, default to workhorse settings
use_socket = node['gitlab']['gitlab-workhorse']['listen_network'] == "unix"
workhorse_url = node['gitlab']['gitlab-workhorse']['listen_addr']
relative_path = Gitlab['gitlab_workhorse']['relative_url']
gitlab_url ||= use_socket ? "http+unix://#{ERB::Util.url_encode(workhorse_url)}" : "http://#{workhorse_url}#{relative_path}"
gitlab_relative_path = relative_path || '' if use_socket
gitlab_url, gitlab_relative_path = WebServerHelper.internal_api_url(node)
 
templatesymlink "Create a config.yml and create a symlink to Rails root" do
link_from File.join(gitlab_shell_dir, "config.yml")
Loading
Loading
Loading
Loading
@@ -43,6 +43,7 @@ RSpec.describe 'gitaly' do
end
 
let(:gitlab_url) { 'http://localhost:3000' }
let(:workhorse_addr) { 'localhost:4000' }
let(:custom_hooks_dir) { '/path/to/custom/hooks' }
let(:user) { 'user123' }
let(:password) { 'password321' }
Loading
Loading
@@ -141,9 +142,9 @@ RSpec.describe 'gitaly' do
.with_content(%r{\[gitlab-shell\]\s+dir = "/opt/gitlab/embedded/service/gitlab-shell"})
end
 
it 'populates gitaly config.toml with gitlab values' do
it 'populates gitaly config.toml with gitlab-workhorse socket' do
expect(chef_run).to render_file(config_path)
.with_content(%r{\[gitlab\]\s+url = 'http://127.0.0.1:8080'})
.with_content(%r{\[gitlab\]\s+url = 'http\+unix://%2Fvar%2Fopt%2Fgitlab%2Fgitlab-workhorse%2Fsocket'\s+relative_url_root = ''})
end
end
 
Loading
Loading
@@ -193,6 +194,10 @@ RSpec.describe 'gitaly' do
self_signed_cert: self_signed_cert
}
},
gitlab_workhorse: {
listen_network: 'tcp',
listen_addr: workhorse_addr,
},
user: {
username: 'foo',
group: 'bar'
Loading
Loading
@@ -481,6 +486,47 @@ RSpec.describe 'gitaly' do
)
end
end
context 'with a non-default workhorse unix socket' do
before do
stub_gitlab_rb(gitlab_workhorse: { listen_addr: '/fake/workhorse/socket' })
end
it 'create config file with provided values' do
expect(chef_run).to render_file(config_path)
.with_content(%r{\[gitlab\]\s+url = 'http\+unix://%2Ffake%2Fworkhorse%2Fsocket'\s+relative_url_root = ''})
end
end
context 'with a tcp workhorse listener' do
before do
stub_gitlab_rb(
external_url: 'http://example.com/gitlab',
gitlab_workhorse: {
listen_network: 'tcp',
listen_addr: 'localhost:1234'
}
)
end
it 'create config file with only the URL set' do
expect(chef_run).to render_file(config_path).with_content { |content|
expect(content).to match(%r{\[gitlab\]\s+url = 'http://localhost:1234/gitlab'})
expect(content).not_to match(/relative_url_root/)
}
end
end
context 'with relative path in external_url' do
before do
stub_gitlab_rb(external_url: 'http://example.com/gitlab')
end
it 'create config file with the relative_url_root set' do
expect(chef_run).to render_file(config_path)
.with_content(%r{\[gitlab\]\s+url = 'http\+unix://%2Fvar%2Fopt%2Fgitlab%2Fgitlab-workhorse%2Fsocket'\s+relative_url_root = '/gitlab'})
end
end
end
 
RSpec.describe 'gitaly::git_data_dirs' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment