Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Anders Kaseorg3f83b843c24a
diff --git a/scripts/lib/upgrade-zulip-from-git b/scripts/lib/upgrade-zulip-from-git
index 42d318f86eb..6701bb51a8a 100755
--- a/scripts/lib/upgrade-zulip-from-git
+++ b/scripts/lib/upgrade-zulip-from-git
@@ -63,7 +63,7 @@ try:
logging.info("Cloning the repository")
subprocess.check_call(
["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:
subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR])
@@ -83,13 +83,17 @@ try:
logging.info("Fetching the latest commits")
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(
- ["git", "clone", "-q", "-b", refname, LOCAL_GIT_CACHE_DIR, deploy_path],
- stdout=open("/dev/null", "w"),
+ ["git", "worktree", "add", "--detach", deploy_path, refname],
+ stdout=subprocess.DEVNULL,
preexec_fn=su_to_zulip,
)
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")
diff --git a/scripts/purge-old-deployments b/scripts/purge-old-deployments
index 953feb9891d..0e6f68a71ae 100755
--- a/scripts/purge-old-deployments
+++ b/scripts/purge-old-deployments
@@ -7,7 +7,12 @@ from typing import Set
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
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:
@@ -70,6 +75,10 @@ def main() -> None:
)
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("Cleaning orphaned/unused caches...")