Commit 37afaaee authored by Gabriel Mazetto's avatar Gabriel Mazetto

Import Geo repository using git clone

parent 043a8f97
...@@ -941,6 +941,10 @@ class Repository ...@@ -941,6 +941,10 @@ class Repository
end end
end end
def clone_as_mirror(url, http_authorization_header: "")
import_repository(url, http_authorization_header: http_authorization_header)
end
def fetch_as_mirror(url, forced: false, refmap: :all_refs, prune: true, http_authorization_header: "") def fetch_as_mirror(url, forced: false, refmap: :all_refs, prune: true, http_authorization_header: "")
fetch_remote(url, refmap: refmap, forced: forced, prune: prune, http_authorization_header: http_authorization_header) fetch_remote(url, refmap: refmap, forced: forced, prune: prune, http_authorization_header: http_authorization_header)
end end
......
...@@ -59,7 +59,9 @@ module Geo ...@@ -59,7 +59,9 @@ module Geo
elsif repository.exists? elsif repository.exists?
fetch_geo_mirror(repository) fetch_geo_mirror(repository)
else else
ensure_repository clone_geo_mirror(repository)
repository.expire_status_cache # after_create
# Because we ensure a repository exists by this point, we need to # Because we ensure a repository exists by this point, we need to
# mark it as new, even if fetching the mirror fails, we should run # mark it as new, even if fetching the mirror fails, we should run
# housekeeping to enable object deduplication to run # housekeeping to enable object deduplication to run
...@@ -98,11 +100,19 @@ module Geo ...@@ -98,11 +100,19 @@ module Geo
::Gitlab::Geo.current_node ::Gitlab::Geo.current_node
end end
# Update an existing repository using special credentials
# @param [Repository] repository
def fetch_geo_mirror(repository) def fetch_geo_mirror(repository)
# Fetch the repository, using a JWT header for authentication # Fetch the repository, using a JWT header for authentication
repository.fetch_as_mirror(remote_url, forced: true, http_authorization_header: jwt_authentication_header) repository.fetch_as_mirror(remote_url, forced: true, http_authorization_header: jwt_authentication_header)
end end
# Clone a new repository using Geo special credentials
# @param [Repository] repository
def clone_geo_mirror(repository)
repository.clone_as_mirror(remote_url, http_authorization_header: jwt_authentication_header)
end
# Build a JWT header for authentication # Build a JWT header for authentication
def jwt_authentication_header def jwt_authentication_header
::Gitlab::Geo::RepoSyncRequest.new( ::Gitlab::Geo::RepoSyncRequest.new(
......
...@@ -841,11 +841,11 @@ module Gitlab ...@@ -841,11 +841,11 @@ module Gitlab
end end
end end
def import_repository(url) def import_repository(url, http_authorization_header: "")
raise ArgumentError, "don't use disk paths with import_repository: #{url.inspect}" if url.start_with?('.', '/') raise ArgumentError, "don't use disk paths with import_repository: #{url.inspect}" if url.start_with?('.', '/')
wrapped_gitaly_errors do wrapped_gitaly_errors do
gitaly_repository_client.import_repository(url) gitaly_repository_client.import_repository(url, http_authorization_header: http_authorization_header)
end end
end end
......
...@@ -145,10 +145,11 @@ module Gitlab ...@@ -145,10 +145,11 @@ module Gitlab
) )
end end
def import_repository(source) def import_repository(source, http_authorization_header: '')
request = Gitaly::CreateRepositoryFromURLRequest.new( request = Gitaly::CreateRepositoryFromURLRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
url: source url: source,
http_authorization_header: http_authorization_header
) )
GitalyClient.call( GitalyClient.call(
......
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