diff --git a/compute/worker/.env.example b/compute/worker/.env.example index 36a9939..766f0ce 100644 --- a/compute/worker/.env.example +++ b/compute/worker/.env.example @@ -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 diff --git a/compute/worker/Dockerfile b/compute/worker/Dockerfile index 9872e70..7ee779f 100644 --- a/compute/worker/Dockerfile +++ b/compute/worker/Dockerfile @@ -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 diff --git a/compute/worker/docker-compose.yml b/compute/worker/docker-compose.yml index be053e7..dde5a73 100644 --- a/compute/worker/docker-compose.yml +++ b/compute/worker/docker-compose.yml @@ -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} diff --git a/compute/worker/src/server.ts b/compute/worker/src/server.ts index cc19593..4d3cbdd 100644 --- a/compute/worker/src/server.ts +++ b/compute/worker/src/server.ts @@ -422,8 +422,7 @@ async function createWorkerLoop(input: { } async function main(): Promise { - 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'); diff --git a/docs-site/docs/deploy/compute-worker.md b/docs-site/docs/deploy/compute-worker.md index f5b0885..50bdfd4 100644 --- a/docs-site/docs/deploy/compute-worker.md +++ b/docs-site/docs/deploy/compute-worker.md @@ -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://:8081 +# Local worker example: +# COMPUTE_WORKER_URL=http://localhost:8081 +# Cloud worker example (Railway): +COMPUTE_WORKER_URL=https:// COMPUTE_WORKER_TOKEN= ``` @@ -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= 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).