Commit f068479e authored by Douwe Maan's avatar Douwe Maan

Merge branch 'use-restore-custom-hooks-gitaly' into 'master'

Use RestoreCustomHooks RPC in restore rake task

See merge request gitlab-org/gitlab-ce!19370
parents d0a040d3 2bbac66c
...@@ -419,7 +419,7 @@ group :ed25519 do ...@@ -419,7 +419,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.100.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.101.0', require: 'gitaly'
gem 'grpc', '~> 1.11.0' gem 'grpc', '~> 1.11.0'
# Locked until https://github.com/google/protobuf/issues/4210 is closed # Locked until https://github.com/google/protobuf/issues/4210 is closed
......
...@@ -283,7 +283,7 @@ GEM ...@@ -283,7 +283,7 @@ GEM
gettext_i18n_rails (>= 0.7.1) gettext_i18n_rails (>= 0.7.1)
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gitaly-proto (0.100.0) gitaly-proto (0.101.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.10) grpc (~> 1.10)
github-linguist (5.3.3) github-linguist (5.3.3)
...@@ -1040,7 +1040,7 @@ DEPENDENCIES ...@@ -1040,7 +1040,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.100.0) gitaly-proto (~> 0.101.0)
github-linguist (~> 5.3.3) github-linguist (~> 5.3.3)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-gollum-lib (~> 4.2) gitlab-gollum-lib (~> 4.2)
......
...@@ -112,18 +112,31 @@ module Backup ...@@ -112,18 +112,31 @@ module Backup
end end
end end
def local_restore_custom_hooks(project, dir)
path_to_project_repo = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
path_to_repo(project)
end
cmd = %W(tar -xf #{path_to_tars(project, dir)} -C #{path_to_project_repo} #{dir})
output, status = Gitlab::Popen.popen(cmd)
unless status.zero?
progress_warn(project, cmd.join(' '), output)
end
end
def gitaly_restore_custom_hooks(project, dir)
custom_hooks_path = path_to_tars(project, dir)
Gitlab::GitalyClient::RepositoryService.new(project.repository)
.restore_custom_hooks(custom_hooks_path)
end
def restore_custom_hooks(project) def restore_custom_hooks(project)
# TODO: Need to find a way to do this for gitaly
# Gitaly migration issue: https://gitlab.com/gitlab-org/gitaly/issues/1195
in_path(path_to_tars(project)) do |dir| in_path(path_to_tars(project)) do |dir|
path_to_project_repo = Gitlab::GitalyClient::StorageSettings.allow_disk_access do gitaly_migrate(:restore_custom_hooks) do |is_enabled|
path_to_repo(project) if is_enabled
end local_restore_custom_hooks(project, dir)
cmd = %W(tar -xf #{path_to_tars(project, dir)} -C #{path_to_project_repo} #{dir}) else
gitaly_restore_custom_hooks(project, dir)
output, status = Gitlab::Popen.popen(cmd) end
unless status.zero?
progress_warn(project, cmd.join(' '), output)
end end
end end
end end
......
...@@ -213,25 +213,20 @@ module Gitlab ...@@ -213,25 +213,20 @@ module Gitlab
end end
def create_from_bundle(bundle_path) def create_from_bundle(bundle_path)
request = Gitaly::CreateRepositoryFromBundleRequest.new(repository: @gitaly_repo) gitaly_repo_stream_request(
enum = Enumerator.new do |y| bundle_path,
File.open(bundle_path, 'rb') do |f|
while data = f.read(MAX_MSG_SIZE)
request.data = data
y.yield request
request = Gitaly::CreateRepositoryFromBundleRequest.new
end
end
end
GitalyClient.call(
@storage,
:repository_service,
:create_repository_from_bundle, :create_repository_from_bundle,
enum, Gitaly::CreateRepositoryFromBundleRequest,
timeout: GitalyClient.default_timeout GitalyClient.default_timeout
)
end
def restore_custom_hooks(custom_hooks_path)
gitaly_repo_stream_request(
custom_hooks_path,
:restore_custom_hooks,
Gitaly::RestoreCustomHooksRequest,
GitalyClient.default_timeout
) )
end end
...@@ -311,6 +306,30 @@ module Gitlab ...@@ -311,6 +306,30 @@ module Gitlab
request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query) request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query)
GitalyClient.call(@storage, :repository_service, :search_files_by_content, request).flat_map(&:matches) GitalyClient.call(@storage, :repository_service, :search_files_by_content, request).flat_map(&:matches)
end end
private
def gitaly_repo_stream_request(file_path, rpc_name, request_class, timeout)
request = request_class.new(repository: @gitaly_repo)
enum = Enumerator.new do |y|
File.open(file_path, 'rb') do |f|
while data = f.read(MAX_MSG_SIZE)
request.data = data
y.yield request
request = request_class.new
end
end
end
GitalyClient.call(
@storage,
:repository_service,
rpc_name,
enum,
timeout: timeout
)
end
end end
end end
end end
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