Skip to content

Commit 9aafa4d

Browse files
feat(deploy): add local production deploy and stop scripts
1 parent a367138 commit 9aafa4d

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ VENV ?= .venv
22
PYTHON ?= $(VENV)/bin/python
33
PIP ?= $(VENV)/bin/pip
44

5-
.PHONY: setup test lint demo paper
5+
.PHONY: setup test lint demo paper deploy stop
66

77
setup:
88
python3 -m venv $(VENV)
@@ -37,3 +37,9 @@ demo:
3737

3838
paper:
3939
$(MAKE) -C paper paper
40+
41+
deploy:
42+
./scripts/deploy_local.sh
43+
44+
stop:
45+
./scripts/stop_local.sh

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ Artifacts are written to `runs/<run_id>/`:
5252
make lint
5353
make test
5454
make paper
55+
make deploy
56+
make stop
5557
```

scripts/deploy_local.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
cd "$ROOT_DIR"
6+
7+
PYTHON="${PYTHON:-.venv/bin/python}"
8+
NEXT_CMD="${NEXT_CMD:-npm}"
9+
10+
mkdir -p .tmp
11+
12+
cleanup_pid() {
13+
local pid_file="$1"
14+
if [[ -f "$pid_file" ]]; then
15+
local pid
16+
pid="$(cat "$pid_file")"
17+
if kill -0 "$pid" >/dev/null 2>&1; then
18+
kill "$pid" >/dev/null 2>&1 || true
19+
fi
20+
rm -f "$pid_file"
21+
fi
22+
}
23+
24+
cleanup_pid ".tmp/server.pid"
25+
cleanup_pid ".tmp/web.pid"
26+
27+
echo "Starting API server on http://127.0.0.1:8000 ..."
28+
nohup "$PYTHON" -m uvicorn worldmodel_server.main:app --host 127.0.0.1 --port 8000 > .tmp/server.log 2>&1 &
29+
echo $! > .tmp/server.pid
30+
31+
for _ in {1..30}; do
32+
if curl -fsS "http://127.0.0.1:8000/healthz" >/dev/null 2>&1; then
33+
break
34+
fi
35+
sleep 1
36+
done
37+
38+
if ! curl -fsS "http://127.0.0.1:8000/healthz" >/dev/null 2>&1; then
39+
echo "API failed to start; check .tmp/server.log"
40+
exit 1
41+
fi
42+
43+
echo "Building web app..."
44+
(
45+
cd web
46+
"$NEXT_CMD" run build >/dev/null
47+
)
48+
49+
echo "Starting web app on http://127.0.0.1:3000 ..."
50+
(
51+
cd web
52+
nohup "$NEXT_CMD" run start -- --hostname 127.0.0.1 --port 3000 > ../.tmp/web.log 2>&1 &
53+
echo $! > ../.tmp/web.pid
54+
)
55+
56+
for _ in {1..30}; do
57+
if curl -fsS "http://127.0.0.1:3000" >/dev/null 2>&1; then
58+
break
59+
fi
60+
sleep 1
61+
done
62+
63+
if ! curl -fsS "http://127.0.0.1:3000" >/dev/null 2>&1; then
64+
echo "Web failed to start; check .tmp/web.log"
65+
exit 1
66+
fi
67+
68+
echo "Deployment complete."
69+
echo "API: http://127.0.0.1:8000"
70+
echo "Web: http://127.0.0.1:3000"
71+
echo "PIDs: server=$(cat .tmp/server.pid), web=$(cat .tmp/web.pid)"

scripts/stop_local.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
cd "$ROOT_DIR"
6+
7+
stop_pid() {
8+
local pid_file="$1"
9+
if [[ -f "$pid_file" ]]; then
10+
local pid
11+
pid="$(cat "$pid_file")"
12+
if kill -0 "$pid" >/dev/null 2>&1; then
13+
kill "$pid" >/dev/null 2>&1 || true
14+
echo "Stopped PID $pid"
15+
fi
16+
rm -f "$pid_file"
17+
fi
18+
}
19+
20+
stop_pid ".tmp/web.pid"
21+
stop_pid ".tmp/server.pid"

0 commit comments

Comments
 (0)