Skip to content

Commit aab6663

Browse files
refactor(deploy): replace Fly.io flow with no-card public tunnel deploy
1 parent ea6f6ef commit aab6663

File tree

9 files changed

+181
-140
lines changed

9 files changed

+181
-140
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
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 deploy stop deploy-fly
5+
.PHONY: setup test lint demo paper deploy stop deploy-public stop-public
66

77
setup:
88
python3 -m venv $(VENV)
@@ -44,5 +44,8 @@ deploy:
4444
stop:
4545
./scripts/stop_local.sh
4646

47-
deploy-fly:
48-
./scripts/deploy_fly.sh
47+
deploy-public:
48+
./scripts/deploy_public.sh
49+
50+
stop-public:
51+
./scripts/stop_public.sh

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ make test
5454
make paper
5555
make deploy
5656
make stop
57-
make deploy-fly
57+
make deploy-public
58+
make stop-public
5859
```

docker/web.fly.Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/DEPLOYMENT.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
# Deployment
22

3-
## Fly.io
3+
## Local Production Mode
44

5-
This repo supports one-command Fly deployment for both API and web services.
5+
Run API + web on your machine:
66

77
```bash
8-
make deploy-fly
8+
make deploy
99
```
1010

11-
Default app names:
12-
- API: `worldmodel-gym-api-biru`
13-
- Web: `worldmodel-gym-web-biru`
11+
Stop local services:
1412

15-
Override names/region if needed:
13+
```bash
14+
make stop
15+
```
16+
17+
## Public No-Card Deployment (Quick Tunnel)
18+
19+
This mode does not require Fly.io, cloud billing, or credit card setup.
20+
It runs services locally and exposes temporary public URLs through `localtunnel`.
21+
22+
```bash
23+
make deploy-public
24+
```
25+
26+
The command will:
27+
- start API (`uvicorn`) on `127.0.0.1:8000`
28+
- create a public API tunnel URL
29+
- build web with `NEXT_PUBLIC_API_BASE=<public-api-url>`
30+
- start web on `127.0.0.1:3000`
31+
- create a public web tunnel URL
32+
33+
Stop public deployment:
1634

1735
```bash
18-
API_APP=my-api-name WEB_APP=my-web-name REGION=iad make deploy-fly
36+
make stop-public
1937
```
2038

21-
What the script does:
22-
- creates Fly apps if missing
23-
- creates a persistent volume (`data`) for API sqlite storage
24-
- sets a random `WMG_UPLOAD_TOKEN` secret on API app
25-
- deploys API using `docker/server.Dockerfile`
26-
- deploys web using `docker/web.fly.Dockerfile`
27-
28-
After deploy, it prints:
29-
- API URL
30-
- Web URL
31-
- upload token (store securely)
39+
Notes:
40+
- Public tunnel URLs are ephemeral and change when restarted.
41+
- Keep your machine running while the public URLs are in use.

fly/api.fly.toml.tmpl

Lines changed: 0 additions & 26 deletions
This file was deleted.

fly/web.fly.toml.tmpl

Lines changed: 0 additions & 21 deletions
This file was deleted.

scripts/deploy_fly.sh

Lines changed: 0 additions & 55 deletions
This file was deleted.

scripts/deploy_public.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
NPM="${NPM:-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/lt-web.pid"
25+
cleanup_pid ".tmp/lt-api.pid"
26+
cleanup_pid ".tmp/web.pid"
27+
cleanup_pid ".tmp/server.pid"
28+
29+
if [[ ! -x "$PYTHON" ]]; then
30+
echo "Python venv not found. Run: make setup"
31+
exit 1
32+
fi
33+
34+
echo "Starting API server on http://127.0.0.1:8000 ..."
35+
nohup "$PYTHON" -m uvicorn worldmodel_server.main:app --host 127.0.0.1 --port 8000 > .tmp/server.log 2>&1 &
36+
echo $! > .tmp/server.pid
37+
38+
for _ in {1..45}; do
39+
if curl -fsS "http://127.0.0.1:8000/healthz" >/dev/null 2>&1; then
40+
break
41+
fi
42+
sleep 1
43+
done
44+
45+
if ! curl -fsS "http://127.0.0.1:8000/healthz" >/dev/null 2>&1; then
46+
echo "API failed to start; check .tmp/server.log"
47+
exit 1
48+
fi
49+
50+
echo "Opening public tunnel for API (no account/card required) ..."
51+
nohup npx --yes localtunnel --port 8000 > .tmp/lt-api.log 2>&1 &
52+
echo $! > .tmp/lt-api.pid
53+
54+
API_URL=""
55+
for _ in {1..60}; do
56+
API_URL="$(grep -Eo 'https://[a-zA-Z0-9.-]+' .tmp/lt-api.log | head -n 1 || true)"
57+
if [[ -n "$API_URL" ]]; then
58+
break
59+
fi
60+
sleep 1
61+
done
62+
63+
if [[ -z "$API_URL" ]]; then
64+
echo "Could not get API tunnel URL; check .tmp/lt-api.log"
65+
exit 1
66+
fi
67+
68+
echo "Building web with NEXT_PUBLIC_API_BASE=${API_URL} ..."
69+
(
70+
cd web
71+
NEXT_PUBLIC_API_BASE="$API_URL" "$NPM" run build >/dev/null
72+
)
73+
74+
echo "Starting web app on http://127.0.0.1:3000 ..."
75+
(
76+
cd web
77+
nohup "$NPM" run start -- --hostname 127.0.0.1 --port 3000 > ../.tmp/web.log 2>&1 &
78+
echo $! > ../.tmp/web.pid
79+
)
80+
81+
for _ in {1..45}; do
82+
if curl -fsS "http://127.0.0.1:3000" >/dev/null 2>&1; then
83+
break
84+
fi
85+
sleep 1
86+
done
87+
88+
if ! curl -fsS "http://127.0.0.1:3000" >/dev/null 2>&1; then
89+
echo "Web failed to start; check .tmp/web.log"
90+
exit 1
91+
fi
92+
93+
echo "Opening public tunnel for web ..."
94+
nohup npx --yes localtunnel --port 3000 > .tmp/lt-web.log 2>&1 &
95+
echo $! > .tmp/lt-web.pid
96+
97+
WEB_URL=""
98+
for _ in {1..60}; do
99+
WEB_URL="$(grep -Eo 'https://[a-zA-Z0-9.-]+' .tmp/lt-web.log | head -n 1 || true)"
100+
if [[ -n "$WEB_URL" ]]; then
101+
break
102+
fi
103+
sleep 1
104+
done
105+
106+
if [[ -z "$WEB_URL" ]]; then
107+
echo "Could not get web tunnel URL; check .tmp/lt-web.log"
108+
exit 1
109+
fi
110+
111+
echo "${API_URL}" > .tmp/public-api-url.txt
112+
echo "${WEB_URL}" > .tmp/public-web-url.txt
113+
114+
echo
115+
echo "Public deployment complete (no paid platform required)."
116+
echo "Web URL: ${WEB_URL}"
117+
echo "API URL: ${API_URL}"
118+
echo "PIDs: api=$(cat .tmp/server.pid), web=$(cat .tmp/web.pid), lt-api=$(cat .tmp/lt-api.pid), lt-web=$(cat .tmp/lt-web.pid)"
119+
echo "Use: make stop-public"

scripts/stop_public.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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/lt-web.pid"
21+
stop_pid ".tmp/lt-api.pid"
22+
stop_pid ".tmp/web.pid"
23+
stop_pid ".tmp/server.pid"
24+
25+
rm -f .tmp/public-api-url.txt .tmp/public-web-url.txt

0 commit comments

Comments
 (0)