Skip to content

Commit 11fd149

Browse files
improve docker dev defaults for LAN/public access (anomalyco#943)
1 parent 700f528 commit 11fd149

4 files changed

Lines changed: 117 additions & 6 deletions

File tree

‎packaging/docker/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Optional env vars (via `.env` or `export`):
3434
- `OPENWORK_PORT` — host port to map to container :8787
3535
- `WEB_PORT` — host port to map to container :5173
3636
- `SHARE_PORT` — host port to map to the local share service :3000
37+
- `OPENWORK_PUBLIC_HOST` — host name/IP used in printed LAN/public URLs (defaults to your machine hostname)
3738
- `OPENWORK_DOCKER_DEV_MOUNT_HOST_OPENCODE=1` — import host OpenCode config/auth into the isolated dev state
3839
- `OPENWORK_OPENCODE_CONFIG_DIR` — override the host OpenCode config source used for that optional import
3940
- `OPENWORK_OPENCODE_DATA_DIR` — override the host OpenCode data source used for that optional import
@@ -75,8 +76,9 @@ Optional env vars (via `.env` or `export`):
7576
- `DEN_API_PORT` — host port to map to the Den control plane :8788
7677
- `DEN_WEB_PORT` — host port to map to the cloud web app :3005
7778
- `DEN_BETTER_AUTH_SECRET` — Better Auth secret (auto-generated if unset)
78-
- `DEN_BETTER_AUTH_URL` — browser-facing auth base URL (defaults to the printed web URL)
79-
- `DEN_CORS_ORIGINS` — trusted origins for Better Auth + Express CORS
79+
- `DEN_PUBLIC_HOST` — host name/IP used for default auth URL + printed LAN/public URLs (defaults to your machine hostname)
80+
- `DEN_BETTER_AUTH_URL` — browser-facing auth base URL (defaults to `http://$DEN_PUBLIC_HOST:<DEN_WEB_PORT>`)
81+
- `DEN_CORS_ORIGINS` — trusted origins for Better Auth + Express CORS (defaults include hostname, localhost, loopback, and detected LAN IPv4)
8082
- `DEN_PROVISIONER_MODE` — `stub` or `render` (defaults to `stub`)
8183
- `DEN_WORKER_URL_TEMPLATE` — stub worker URL template with `{workerId}` placeholder
8284

‎packaging/docker/den-dev-up.sh‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@ random_hex() {
3737
node -e "console.log(require('crypto').randomBytes(${bytes}).toString('hex'))"
3838
}
3939

40+
detect_public_host() {
41+
if [ -n "${DEN_PUBLIC_HOST:-}" ]; then
42+
printf '%s\n' "$DEN_PUBLIC_HOST"
43+
return
44+
fi
45+
46+
local host
47+
host="$(hostname -s 2>/dev/null || hostname 2>/dev/null || true)"
48+
host="${host//$'\n'/}"
49+
host="${host// /}"
50+
if [ -n "$host" ]; then
51+
printf '%s\n' "$host"
52+
return
53+
fi
54+
55+
printf '%s\n' "localhost"
56+
}
57+
58+
detect_lan_ipv4() {
59+
node -e '
60+
const os = require("os");
61+
const nets = os.networkInterfaces();
62+
for (const entries of Object.values(nets)) {
63+
for (const entry of entries || []) {
64+
if (!entry || entry.internal || entry.family !== "IPv4") continue;
65+
if (entry.address.startsWith("127.")) continue;
66+
process.stdout.write(entry.address);
67+
process.exit(0);
68+
}
69+
}
70+
'
71+
}
72+
73+
join_csv_unique() {
74+
printf "%s\n" "$@" | awk 'NF && !seen[$0]++' | paste -sd, -
75+
}
76+
4077
DEV_ID="$(node -e "console.log(require('crypto').randomUUID().slice(0, 8))")"
4178
PROJECT="openwork-den-dev-$DEV_ID"
4279

@@ -46,11 +83,24 @@ if [ "$DEN_WEB_PORT" = "$DEN_API_PORT" ]; then
4683
DEN_WEB_PORT="$(pick_port)"
4784
fi
4885

86+
PUBLIC_HOST="$(detect_public_host)"
87+
LAN_IPV4="$(detect_lan_ipv4 || true)"
88+
4989
DEN_BETTER_AUTH_SECRET="${DEN_BETTER_AUTH_SECRET:-$(random_hex 32)}"
50-
DEN_BETTER_AUTH_URL="${DEN_BETTER_AUTH_URL:-http://localhost:$DEN_WEB_PORT}"
90+
DEN_BETTER_AUTH_URL="${DEN_BETTER_AUTH_URL:-http://$PUBLIC_HOST:$DEN_WEB_PORT}"
5191
DEN_PROVISIONER_MODE="${DEN_PROVISIONER_MODE:-stub}"
5292
DEN_WORKER_URL_TEMPLATE="${DEN_WORKER_URL_TEMPLATE:-https://workers.local/{workerId}}"
53-
DEN_CORS_ORIGINS="${DEN_CORS_ORIGINS:-http://localhost:$DEN_WEB_PORT,http://127.0.0.1:$DEN_WEB_PORT,http://localhost:$DEN_API_PORT,http://127.0.0.1:$DEN_API_PORT}"
93+
if [ -z "${DEN_CORS_ORIGINS:-}" ]; then
94+
DEN_CORS_ORIGINS="$(join_csv_unique \
95+
"http://$PUBLIC_HOST:$DEN_WEB_PORT" \
96+
"http://$PUBLIC_HOST:$DEN_API_PORT" \
97+
"http://localhost:$DEN_WEB_PORT" \
98+
"http://127.0.0.1:$DEN_WEB_PORT" \
99+
"http://localhost:$DEN_API_PORT" \
100+
"http://127.0.0.1:$DEN_API_PORT" \
101+
"${LAN_IPV4:+http://$LAN_IPV4:$DEN_WEB_PORT}" \
102+
"${LAN_IPV4:+http://$LAN_IPV4:$DEN_API_PORT}")"
103+
fi
54104

55105
mkdir -p "$RUNTIME_DIR"
56106
RUNTIME_FILE="$ROOT_DIR/tmp/.den-dev-env-$DEV_ID"
@@ -61,6 +111,7 @@ DEN_API_PORT=$DEN_API_PORT
61111
DEN_WEB_PORT=$DEN_WEB_PORT
62112
DEN_API_URL=http://localhost:$DEN_API_PORT
63113
DEN_WEB_URL=http://localhost:$DEN_WEB_PORT
114+
DEN_WEB_URL_PUBLIC=http://$PUBLIC_HOST:$DEN_WEB_PORT
64115
DEN_BETTER_AUTH_URL=$DEN_BETTER_AUTH_URL
65116
COMPOSE_FILE=$COMPOSE_FILE
66117
EOF
@@ -69,6 +120,7 @@ echo "Starting Docker Compose project: $PROJECT" >&2
69120
echo "- DEN_API_PORT=$DEN_API_PORT" >&2
70121
echo "- DEN_WEB_PORT=$DEN_WEB_PORT" >&2
71122
echo "- DEN_BETTER_AUTH_URL=$DEN_BETTER_AUTH_URL" >&2
123+
echo "- DEN_CORS_ORIGINS=$DEN_CORS_ORIGINS" >&2
72124
echo "- DEN_PROVISIONER_MODE=$DEN_PROVISIONER_MODE" >&2
73125

74126
if ! DEN_API_PORT="$DEN_API_PORT" \
@@ -86,7 +138,15 @@ fi
86138

87139
echo "" >&2
88140
echo "OpenWork Cloud web UI: http://localhost:$DEN_WEB_PORT" >&2
141+
echo "OpenWork Cloud web UI (LAN/public): http://$PUBLIC_HOST:$DEN_WEB_PORT" >&2
142+
if [ -n "$LAN_IPV4" ]; then
143+
echo "OpenWork Cloud web UI (LAN IP): http://$LAN_IPV4:$DEN_WEB_PORT" >&2
144+
fi
89145
echo "Den demo/API: http://localhost:$DEN_API_PORT" >&2
146+
echo "Den demo/API (LAN/public): http://$PUBLIC_HOST:$DEN_API_PORT" >&2
147+
if [ -n "$LAN_IPV4" ]; then
148+
echo "Den demo/API (LAN IP): http://$LAN_IPV4:$DEN_API_PORT" >&2
149+
fi
90150
echo "Health check: http://localhost:$DEN_API_PORT/health" >&2
91151
echo "Runtime env file: $RUNTIME_FILE" >&2
92152
echo "" >&2

‎packaging/docker/dev-up.sh‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,39 @@ pick_port() {
111111
"
112112
}
113113

114+
detect_public_host() {
115+
if [ -n "${OPENWORK_PUBLIC_HOST:-}" ]; then
116+
printf '%s\n' "$OPENWORK_PUBLIC_HOST"
117+
return
118+
fi
119+
120+
local host
121+
host="$(hostname -s 2>/dev/null || hostname 2>/dev/null || true)"
122+
host="${host//$'\n'/}"
123+
host="${host// /}"
124+
if [ -n "$host" ]; then
125+
printf '%s\n' "$host"
126+
return
127+
fi
128+
129+
printf '%s\n' "localhost"
130+
}
131+
132+
detect_lan_ipv4() {
133+
node -e '
134+
const os = require("os");
135+
const nets = os.networkInterfaces();
136+
for (const entries of Object.values(nets)) {
137+
for (const entry of entries || []) {
138+
if (!entry || entry.internal || entry.family !== "IPv4") continue;
139+
if (entry.address.startsWith("127.")) continue;
140+
process.stdout.write(entry.address);
141+
process.exit(0);
142+
}
143+
}
144+
'
145+
}
146+
114147
DEV_ID="$(node -e "console.log(require('crypto').randomUUID().slice(0, 8))")"
115148
PROJECT="openwork-dev-$DEV_ID"
116149

@@ -146,6 +179,9 @@ if [ "$SHARE_PORT" = "$OPENWORK_PORT" ] || [ "$SHARE_PORT" = "$WEB_PORT" ]; then
146179
SHARE_PORT="$(pick_port)"
147180
fi
148181

182+
PUBLIC_HOST="$(detect_public_host)"
183+
LAN_IPV4="$(detect_lan_ipv4 || true)"
184+
149185
echo "Starting Docker Compose project: $PROJECT" >&2
150186
echo "- OPENWORK_PORT=$OPENWORK_PORT" >&2
151187
echo "- WEB_PORT=$WEB_PORT" >&2
@@ -189,8 +225,20 @@ fi
189225

190226
echo "" >&2
191227
echo "OpenWork web UI: http://localhost:$WEB_PORT" >&2
228+
echo "OpenWork web UI (LAN/public): http://$PUBLIC_HOST:$WEB_PORT" >&2
229+
if [ -n "$LAN_IPV4" ]; then
230+
echo "OpenWork web UI (LAN IP): http://$LAN_IPV4:$WEB_PORT" >&2
231+
fi
192232
echo "OpenWork server: http://localhost:$OPENWORK_PORT" >&2
233+
echo "OpenWork server (LAN/public): http://$PUBLIC_HOST:$OPENWORK_PORT" >&2
234+
if [ -n "$LAN_IPV4" ]; then
235+
echo "OpenWork server (LAN IP): http://$LAN_IPV4:$OPENWORK_PORT" >&2
236+
fi
193237
echo "Share service: http://localhost:$SHARE_PORT" >&2
238+
echo "Share service (LAN/public): http://$PUBLIC_HOST:$SHARE_PORT" >&2
239+
if [ -n "$LAN_IPV4" ]; then
240+
echo "Share service (LAN IP): http://$LAN_IPV4:$SHARE_PORT" >&2
241+
fi
194242
echo "Token file: $ROOT_DIR/tmp/.dev-env-$DEV_ID" >&2
195243
echo "" >&2
196244
echo "To stop this stack:" >&2

‎packaging/docker/docker-compose.den-dev.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
# DEN_API_PORT — host port to map to Den control plane :8788
1010
# DEN_WEB_PORT — host port to map to the cloud web app :3005
1111
# DEN_BETTER_AUTH_SECRET — Better Auth secret (auto-generated by den-dev-up.sh)
12-
# DEN_BETTER_AUTH_URL — browser-facing auth origin (default: http://localhost:<DEN_WEB_PORT>)
13-
# DEN_CORS_ORIGINS — comma-separated trusted origins for Better Auth + CORS
12+
# DEN_PUBLIC_HOST — host used to build default auth origin + LAN/public URLs
13+
# DEN_BETTER_AUTH_URL — browser-facing auth origin (default: http://<DEN_PUBLIC_HOST>:<DEN_WEB_PORT>)
14+
# DEN_CORS_ORIGINS — comma-separated trusted origins for Better Auth + CORS (auto-populated by den-dev-up.sh)
1415
# DEN_PROVISIONER_MODE — stub or render (default: stub)
1516
# DEN_WORKER_URL_TEMPLATE — worker URL template used by stub provisioning
1617

0 commit comments

Comments
 (0)