upgrade-zulip-from-git: Create deployment directories with git worktree.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-05-13 12:53:04 -07:00 committed by Tim Abbott
parent 6e9683fe6f
commit 3f83b843c2
2 changed files with 18 additions and 5 deletions

View File

@ -63,7 +63,7 @@ try:
logging.info("Cloning the repository") logging.info("Cloning the repository")
subprocess.check_call( subprocess.check_call(
["git", "clone", "-q", remote_url, "--mirror", LOCAL_GIT_CACHE_DIR], ["git", "clone", "-q", remote_url, "--mirror", LOCAL_GIT_CACHE_DIR],
stdout=open("/dev/null", "w"), stdout=subprocess.DEVNULL,
) )
if os.stat(LOCAL_GIT_CACHE_DIR).st_uid == 0: if os.stat(LOCAL_GIT_CACHE_DIR).st_uid == 0:
subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR]) subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR])
@ -83,13 +83,17 @@ try:
logging.info("Fetching the latest commits") logging.info("Fetching the latest commits")
subprocess.check_call(["git", "fetch", "-q", "--tags", "--all"], preexec_fn=su_to_zulip) subprocess.check_call(["git", "fetch", "-q", "--tags", "--all"], preexec_fn=su_to_zulip)
# Generate the deployment directory via git clone from our local repository. # Generate the deployment directory via git worktree from our local repository.
subprocess.check_call( subprocess.check_call(
["git", "clone", "-q", "-b", refname, LOCAL_GIT_CACHE_DIR, deploy_path], ["git", "worktree", "add", "--detach", deploy_path, refname],
stdout=open("/dev/null", "w"), stdout=subprocess.DEVNULL,
preexec_fn=su_to_zulip, preexec_fn=su_to_zulip,
) )
os.chdir(deploy_path) os.chdir(deploy_path)
subprocess.check_call(
["git", "checkout", "-qtb", "deployment-" + os.path.basename(deploy_path), refname],
preexec_fn=su_to_zulip,
)
overwrite_symlink("/etc/zulip/settings.py", "zproject/prod_settings.py") overwrite_symlink("/etc/zulip/settings.py", "zproject/prod_settings.py")

View File

@ -7,7 +7,12 @@ from typing import Set
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(ZULIP_PATH) sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, get_recent_deployments, may_be_perform_purging from scripts.lib.zulip_tools import (
DEPLOYMENTS_DIR,
get_recent_deployments,
may_be_perform_purging,
su_to_zulip,
)
def parse_args() -> argparse.Namespace: def parse_args() -> argparse.Namespace:
@ -70,6 +75,10 @@ def main() -> None:
) )
if not args.dry_run: if not args.dry_run:
subprocess.check_call(
["git", "worktree", "prune"], cwd="/srv/zulip.git", preexec_fn=su_to_zulip
)
print("Deployments cleaned successfully...") print("Deployments cleaned successfully...")
print("Cleaning orphaned/unused caches...") print("Cleaning orphaned/unused caches...")