From dc4b89fb085fb8e6c7da8a09bb5d3bed3da86b0a Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 28 Jul 2016 13:04:19 -0700 Subject: [PATCH] deploy-zulip-from-git: Add a cache directory. --- scripts/deploy-zulip-from-git | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/deploy-zulip-from-git b/scripts/deploy-zulip-from-git index 41378232ab..550768c05d 100755 --- a/scripts/deploy-zulip-from-git +++ b/scripts/deploy-zulip-from-git @@ -8,6 +8,7 @@ import logging config_file = configparser.RawConfigParser() config_file.read("/etc/zulip/zulip.conf") +LOCAL_GIT_CACHE_DIR = '/srv/zulip.git' ZULIP_COM = config_file.get('machine', 'deploy_type') in ['zulip.com-prod', 'zulip.com-staging'] @@ -20,7 +21,7 @@ os.environ["PYTHONUNBUFFERED"] = "y" sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \ - get_deployment_lock, release_deployment_lock + get_deployment_lock, release_deployment_lock, su_to_zulip logging.basicConfig(format="%(asctime)s update-deployment: %(message)s", level=logging.INFO) @@ -40,10 +41,20 @@ get_deployment_lock(error_rerun_script) try: deploy_path = make_deploy_path() + if not os.path.exists(LOCAL_GIT_CACHE_DIR): + os.chdir('/srv/') + logging.info("Cloning the repository") + subprocess.check_call(["git", "clone", "-q", git_url, "--mirror", LOCAL_GIT_CACHE_DIR], + stdout=open('/dev/null', 'w')) + subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR]) - logging.info("Cloning the repository") - subprocess.check_call(["git", "clone", "-q", "-b", refname, git_url, deploy_path], - stdout=open('/dev/null', 'w')) + logging.info("Fetching the latest commits") + os.chdir(LOCAL_GIT_CACHE_DIR) + subprocess.check_call(["git", "fetch", "-q"], preexec_fn=su_to_zulip) + + subprocess.check_call(["git", "clone", "-q", "-b", refname, LOCAL_GIT_CACHE_DIR, deploy_path], + stdout=open('/dev/null', 'w'), + preexec_fn=su_to_zulip) os.chdir(deploy_path)