refactor(worker): unify port environment variable usage and update deployment docs

Align compute worker to use PORT environment variable consistently across
Dockerfile, docker-compose, and server code, replacing COMPUTE_WORKER_PORT.
Update .env.example and deployment documentation to clarify platform-specific
behavior, especially for Railway and similar environments. This simplifies
configuration and reduces platform-specific issues.
This commit is contained in:
Richard R 2026-05-20 17:05:35 -06:00
parent 086329505f
commit 49d9735237
5 changed files with 18 additions and 9 deletions

View file

@ -1,6 +1,9 @@
# Compute worker bind
# Platform note:
# - Local/manual: keep PORT=8081
# - Railway/Render/Fly/etc: platform injects PORT
COMPUTE_WORKER_HOST=0.0.0.0
COMPUTE_WORKER_PORT=8081
PORT=8081
COMPUTE_LOG_FORMAT=pretty
# COMPUTE_LOG_LEVEL=info

View file

@ -22,7 +22,7 @@ WORKDIR /workspace
COPY --from=deploy-stage /opt/compute-worker ./
ENV COMPUTE_WORKER_HOST=0.0.0.0
ENV COMPUTE_WORKER_PORT=8081
ENV PORT=8081
EXPOSE 8081

View file

@ -21,7 +21,7 @@ services:
environment:
NATS_URL: ${NATS_URL:-nats://nats:4222}
COMPUTE_WORKER_HOST: ${COMPUTE_WORKER_HOST:-0.0.0.0}
COMPUTE_WORKER_PORT: ${COMPUTE_WORKER_PORT:-8081}
PORT: ${PORT:-8081}
COMPUTE_WORKER_TOKEN: ${COMPUTE_WORKER_TOKEN:-local-compute-token}
S3_PREFIX: ${S3_PREFIX:-openreader}
COMPUTE_PREWARM_MODELS: ${COMPUTE_PREWARM_MODELS:-true}

View file

@ -422,8 +422,7 @@ async function createWorkerLoop<TPayload, TResult>(input: {
}
async function main(): Promise<void> {
const platformPort = readIntEnv('PORT', 8081);
const port = readIntEnv('COMPUTE_WORKER_PORT', platformPort);
const port = readIntEnv('PORT', 8081);
const host = process.env.COMPUTE_WORKER_HOST?.trim() || '0.0.0.0';
const workerToken = requireEnv('COMPUTE_WORKER_TOKEN');
const natsUrl = requireEnv('NATS_URL');

View file

@ -42,7 +42,7 @@ Common optional:
- `S3_FORCE_PATH_STYLE=true` (for many S3-compatible providers)
- `S3_PREFIX=openreader`
- `COMPUTE_WORKER_HOST=0.0.0.0`
- `COMPUTE_WORKER_PORT=8081`
- `PORT=8081` (local/manual; on Railway platform injects this)
- `COMPUTE_LOG_FORMAT=pretty` (default) or `json`
- `COMPUTE_PREWARM_MODELS=true`
- `COMPUTE_JOBS_STREAM_MAX_BYTES=268435456` (256MB JetStream jobs stream cap)
@ -54,7 +54,10 @@ Set on the Next.js app server:
```env
COMPUTE_MODE=worker
COMPUTE_WORKER_URL=http://<worker-host>:8081
# Local worker example:
# COMPUTE_WORKER_URL=http://localhost:8081
# Cloud worker example (Railway):
COMPUTE_WORKER_URL=https://<railway-worker-domain>
COMPUTE_WORKER_TOKEN=<same-token-as-worker>
```
@ -94,7 +97,8 @@ Create a Railway service from:
ghcr.io/richardr1126/openreader-compute-worker:refactor-ppdoclayoutv3-onnx-layout-parsing
```
Set the container port to `8081`, then enable public networking to get a worker URL.
Railway injects a dynamic `PORT` env var and routes traffic there.
Do not hardcode Railway ingress to `8081`; keep service networking enabled and use the public Railway URL.
### 3. Configure Railway worker environment variables
@ -102,7 +106,9 @@ Set these in the Railway worker service:
```env
COMPUTE_WORKER_HOST=0.0.0.0
COMPUTE_WORKER_PORT=8081
# Local/manual only:
# PORT=8081
# Railway: rely on injected PORT
COMPUTE_WORKER_TOKEN=<long-random-shared-token>
COMPUTE_JOBS_STREAM_MAX_BYTES=268435456
COMPUTE_JOB_STATES_MAX_BYTES=67108864
@ -125,6 +131,7 @@ Notes:
- `NATS_CREDS` should be the full Synadia `.creds` file content, including begin/end markers.
- Keep `COMPUTE_WORKER_TOKEN` identical between app server and worker.
- On Railway, leave `PORT` managed by the platform.
- If your platform supports mounted files, you can use `NATS_CREDS_FILE` instead of `NATS_CREDS`.
- `COMPUTE_JOBS_STREAM_MAX_BYTES` and `COMPUTE_JOB_STATES_MAX_BYTES` are optional; defaults are `268435456` (256MiB) and `67108864` (64MiB).