diff options
author | Ahmad Hassan <ahmad.hassan612@gmail.com> | 2018-06-04 15:15:54 +0200 |
---|---|---|
committer | Ahmad Hassan <ahmad.hassan612@gmail.com> | 2018-06-05 14:09:18 +0200 |
commit | e08a79122dc1f0b47144eb872962ba93343aaa4f (patch) | |
tree | 10ed63bc2c48146afca02fa2568b284a7e00ad50 | |
parent | 5f0a5367c8081a788f03a8e14907838481128fae (diff) | |
download | gitlab-ce-e08a79122dc1f0b47144eb872962ba93343aaa4f.tar.gz |
Use RestoreCustomHooks RPC in restore rake taskuse-restore-custom-hooks-gitaly
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | lib/backup/repository.rb | 25 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 21 |
4 files changed, 42 insertions, 10 deletions
@@ -415,7 +415,7 @@ group :ed25519 do end # Gitaly GRPC client -gem 'gitaly-proto', '~> 0.100.0', require: 'gitaly' +gem 'gitaly-proto', '~> 0.101.0', require: 'gitaly' gem 'grpc', '~> 1.11.0' # Locked until https://github.com/google/protobuf/issues/4210 is closed diff --git a/Gemfile.lock b/Gemfile.lock index e6e8f3d11bc..78b57ca80a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -281,7 +281,7 @@ GEM gettext_i18n_rails (>= 0.7.1) po_to_json (>= 1.0.0) rails (>= 3.2.0) - gitaly-proto (0.100.0) + gitaly-proto (0.101.0) google-protobuf (~> 3.1) grpc (~> 1.10) github-linguist (5.3.3) @@ -1036,7 +1036,7 @@ DEPENDENCIES gettext (~> 3.2.2) gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails_js (~> 1.3) - gitaly-proto (~> 0.100.0) + gitaly-proto (~> 0.101.0) github-linguist (~> 5.3.3) gitlab-flowdock-git-hook (~> 1.0.1) gitlab-gollum-lib (~> 4.2) diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb index 84670d6582e..5f3b3163180 100644 --- a/lib/backup/repository.rb +++ b/lib/backup/repository.rb @@ -107,16 +107,27 @@ module Backup end end + def local_restore_custom_hooks(project, dir) + path_to_project_repo = path_to_repo(project) + 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) - # 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| - path_to_project_repo = path_to_repo(project) - cmd = %W(tar -xf #{path_to_tars(project, dir)} -C #{path_to_project_repo} #{dir}) + gitaly_migrate(:restore_custom_hooks) do |is_enabled| + return local_restore_custom_hooks(project, dir) unless is_enabled - output, status = Gitlab::Popen.popen(cmd) - unless status.zero? - progress_warn(project, cmd.join(' '), output) + gitaly_restore_custom_hooks(project, dir) end end end diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index ee01f5a5bd9..7a70cc39740 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -235,6 +235,27 @@ module Gitlab ) end + def restore_custom_hooks(custom_hooks_path) + request = Gitaly::RestoreCustomHooksRequest.new(repository: @gitaly_repo) + enum = Enumerator.new do |y| + File.open(custom_hooks_path, 'rb') do |f| + while data = f.read(MAX_MSG_SIZE) + request.data = data + + y.yield request + request = Gitaly::RestoreCustomHooksRequest.new + end + end + end + GitalyClient.call( + @storage, + :repository_service, + :restore_custom_hooks, + enum, + timeout: GitalyClient.default_timeout + ) + end + def create_from_snapshot(http_url, http_auth) request = Gitaly::CreateRepositoryFromSnapshotRequest.new( repository: @gitaly_repo, |