Add support for Gitaly calls over TCP connection

Closes gitaly#166
This commit is contained in:
Ahmad Sherif 2017-04-03 15:27:14 +02:00
parent 2fceb43741
commit 09751c75eb
4 changed files with 31 additions and 3 deletions

View File

@ -461,7 +461,7 @@ production: &base
storages: # You must have at least a `default` storage path.
default:
path: /home/git/repositories/
gitaly_address: unix:/home/git/gitlab/tmp/sockets/private/gitaly.socket
gitaly_address: unix:/home/git/gitlab/tmp/sockets/private/gitaly.socket # TCP connections are supported too (e.g. tcp://host:port)
## Backup settings
backup:

View File

@ -9,7 +9,7 @@ if Gitlab.config.gitaly.enabled || Rails.env.test?
raise "storage #{name.inspect} is missing a gitaly_address"
end
unless URI(address).scheme == 'unix'
unless URI(address).scheme.in?(%w(tcp unix))
raise "Unsupported Gitaly address: #{address.inspect}"
end

View File

@ -12,9 +12,11 @@ module Gitlab
end
def self.new_channel(address)
# NOTE: Gitaly currently runs on a Unix socket, so permissions are
address = address.sub(%r{^tcp://}, '') if URI(address).scheme == 'tcp'
# NOTE: When Gitaly runs on a Unix socket, permissions are
# handled using the file system and no additional authentication is
# required (therefore the :this_channel_is_insecure flag)
# TODO: Add authentication support when Gitaly is running on a TCP socket.
GRPC::Core::Channel.new(address, {}, :this_channel_is_insecure)
end

View File

@ -0,0 +1,26 @@
require 'spec_helper'
describe Gitlab::GitalyClient, lib: true do
describe '.new_channel' do
context 'when passed a UNIX socket address' do
it 'passes the address as-is to GRPC::Core::Channel initializer' do
address = 'unix:/tmp/gitaly.sock'
expect(GRPC::Core::Channel).to receive(:new).with(address, any_args)
described_class.new_channel(address)
end
end
context 'when passed a TCP address' do
it 'strips tcp:// prefix before passing it to GRPC::Core::Channel initializer' do
address = 'localhost:9876'
prefixed_address = "tcp://#{address}"
expect(GRPC::Core::Channel).to receive(:new).with(address, any_args)
described_class.new_channel(prefixed_address)
end
end
end
end