From 3d7b77616490cf5f31206a04226f4a3c1fd9efc0 Mon Sep 17 00:00:00 2001 From: Bruno Pimentel Date: Mon, 13 Dec 2021 16:03:23 -0300 Subject: [PATCH] Sets depth=1 to Git clone/fetch This is to avoid exhausting the resources while cloning very large repos (such as github.com/openshift/origin). The above case is consuming ~3GB memory during the cloning process. Signed-off-by: Bruno Pimentel --- cachito/workers/scm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cachito/workers/scm.py b/cachito/workers/scm.py index 0df31ac2e..4c7013be1 100644 --- a/cachito/workers/scm.py +++ b/cachito/workers/scm.py @@ -158,9 +158,13 @@ def clone_and_archive(self, gitsubmodule=False): self.url, clone_path, no_checkout=True, + # Clone with depth 1 to save resources on large repos + depth=1, # Don't allow git to prompt for a username if we don't have access env={"GIT_TERMINAL_PROMPT": "0"}, ) + + repo.remote().fetch(refspec=self.ref, depth=1) except: # noqa E722 log.exception("Cloning the Git repository from %s failed", self.url) raise CachitoError("Cloning the Git repository failed") @@ -190,7 +194,7 @@ def update_and_archive(self, previous_archive, gitsubmodule=False): try: # The reference must be specified to handle commits which are not part # of a branch. - repo.remote().fetch(refspec=self.ref) + repo.remote().fetch(refspec=self.ref, depth=1) except: # noqa E722 log.exception("Failed to fetch from remote %s", self.url) raise CachitoError("Failed to fetch from the remote Git repository")