Skip to content

Commit 630d3e7

Browse files
committed
enhance run-dev-zerver.sh with provision-only and run-only options
1 parent 75ecc7a commit 630d3e7

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

scripts/run-dev-zerver.sh

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ usage() {
77
cat <<'EOF'
88
Usage: run-dev-zerver.sh [--ref GIT_REF] [--repo URL]
99
10-
Spin up an isolated Zulip dev server instance cloned from the specified git ref.
11-
The server runs inside its own network namespace and is reachable via the
12-
provided loopback IP (e.g. 127.0.123.123).
10+
Spin up a Zulip dev server instance cloned from the specified git ref.
1311
1412
Options:
1513
--ref Git ref (branch, tag, or commit) to check out. Defaults to "main".
1614
--repo Git repository URL. Defaults to https://github.com/zulip/zulip.git.
15+
--provision-only
16+
Only provision the instance; do not start the dev server.
17+
--run-only
18+
Only run the dev server; do not provision the instance.
1719
-h, --help Show this help.
1820
1921
Example:
@@ -32,6 +34,8 @@ log() {
3234

3335
REF="main"
3436
REPO_URL="https://github.com/zulip/zulip.git"
37+
PROVISION_ONLY=false
38+
RUN_ONLY=false
3539

3640
while [[ $# -gt 0 ]]; do
3741
case "$1" in
@@ -45,6 +49,14 @@ while [[ $# -gt 0 ]]; do
4549
REPO_URL="$2"
4650
shift 2
4751
;;
52+
--provision-only)
53+
PROVISION_ONLY=true
54+
shift 1
55+
;;
56+
--run-only)
57+
RUN_ONLY=true
58+
shift 1
59+
;;
4860
-h|--help)
4961
usage
5062
exit 0
@@ -58,30 +70,50 @@ done
5870
BASE_DIR="${TMPDIR:-/tmp}/zulip-zerver"
5971
INSTANCE_DIR="${BASE_DIR}/${REF}"
6072
REPO_DIR="${INSTANCE_DIR}/zulip"
61-
mkdir -p "$INSTANCE_DIR"
62-
log "Instance files will be stored in $INSTANCE_DIR"
63-
64-
log "Cloning Zulip repo ($REPO_URL) into $REPO_DIR"
65-
if [[ ! -d "$REPO_DIR/.git" ]]; then
66-
git clone --filter=blob:none "$REPO_URL" "$REPO_DIR"
67-
else
68-
log "Repository already exists at $REPO_DIR; reusing"
69-
fi
7073

71-
log "Checking out $REF"
74+
provision() {
75+
mkdir -p "$INSTANCE_DIR"
76+
log "Instance files will be stored in $INSTANCE_DIR"
77+
78+
log "Cloning Zulip repo ($REPO_URL) into $REPO_DIR"
79+
if [[ ! -d "$REPO_DIR/.git" ]]; then
80+
git clone --filter=blob:none "$REPO_URL" "$REPO_DIR"
81+
else
82+
log "Repository already exists at $REPO_DIR; reusing"
83+
fi
84+
85+
log "Checking out $REF"
86+
87+
git -C "$REPO_DIR" fetch origin "$REF" --depth=1 || true
88+
git -C "$REPO_DIR" checkout "$REF"
89+
90+
log "Provisioning Zulip (this may take several minutes)"
7291

73-
git -C "$REPO_DIR" fetch origin "$REF" --depth=1 || true
74-
git -C "$REPO_DIR" checkout "$REF"
92+
cd $REPO_DIR && ./tools/provision
93+
cd $REPO_DIR && ./tools/rebuild-dev-database
94+
}
95+
96+
run() {
97+
log "Starting Zulip dev server"
7598

76-
log "Provisioning Zulip (this may take several minutes)"
99+
cd $REPO_DIR
100+
source /srv/zulip-py3-venv/bin/activate || true # legacy Zulip uses a global venv
101+
source .venv/bin/activate || true # modern Zulip uses a local venv
77102

78-
cd $REPO_DIR && ./tools/provision
79-
cd $REPO_DIR && ./tools/rebuild-dev-database
103+
./tools/run-dev
104+
}
80105

81-
log "Starting Zulip dev server"
106+
if [ "$RUN_ONLY" = true ] && [ "$PROVISION_ONLY" = true ]; then
107+
die "Cannot specify both --run-only and --provision-only"
108+
fi
82109

83-
cd $REPO_DIR
84-
source /srv/zulip-py3-venv/bin/activate || true # legacy Zulip uses a global venv
85-
source .venv/bin/activate || true # modern Zulip uses a local venv
110+
if [ "$PROVISION_ONLY" = true ] || [ "$RUN_ONLY" = false ]; then
111+
provision
112+
log "Provisioning complete"
113+
fi
114+
115+
if [ "$RUN_ONLY" = true ] || [ "$PROVISION_ONLY" = false ]; then
116+
run
117+
fi
86118

87-
./tools/run-dev
119+
exit 0

0 commit comments

Comments
 (0)