FROM node:24-bookworm-slim AS base RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/* RUN npm i -g pnpm@10.30.0 FROM base AS build WORKDIR /app COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./ COPY apps/backend/package.json apps/backend/ COPY packages/llmtxt/package.json packages/llmtxt/ COPY apps/frontend/package.json apps/frontend/ RUN pnpm install --no-frozen-lockfile COPY . . RUN pnpm --filter llmtxt --filter @llmtxt/backend --filter frontend build FROM base AS runtime WORKDIR /app COPY --from=build /app/node_modules ./node_modules COPY --from=build /app/packages/llmtxt ./packages/llmtxt COPY --from=build /app/apps/backend/node_modules ./apps/backend/node_modules COPY --from=build /app/apps/backend/dist ./apps/backend/dist COPY --from=build /app/apps/backend/package.json ./apps/backend/ COPY --from=build /app/apps/backend/public ./apps/backend/public COPY --from=build /app/apps/backend/src/db/migrations ./apps/backend/src/db/migrations COPY --from=build /app/apps/backend/src/db/migrations-pg ./apps/backend/src/db/migrations-pg COPY --from=build /app/apps/backend/drizzle.config.ts ./apps/backend/ COPY --from=build /app/apps/backend/drizzle-pg.config.ts ./apps/backend/ COPY --from=build /app/apps/backend/scripts/run-migrations.ts ./apps/backend/scripts/ COPY --from=build /app/apps/backend/openapi.json ./apps/backend/ # Pre-download the all-MiniLM-L6-v2 ONNX model at build time so the first # semantic search request doesn't incur a cold-start download (~23 MB). # LLMTXT_MODEL_CACHE_DIR places the model in the image layer; it is baked in. # Total image size delta: ~27 MB (model + tokenizer files). ENV LLMTXT_MODEL_CACHE_DIR=/app/.llmtxt-models RUN node --input-type=module --eval \ "import { embed } from './packages/llmtxt/dist/embeddings.js'; \ await embed('warmup').then(() => console.log('[docker] ONNX model pre-warmed')).catch(e => { console.warn('[docker] Model pre-warm skipped:', e.message); });" EXPOSE 8080 ENV PORT=8080 # Instruct the container runtime to send SIGTERM (not SIGKILL) on stop/restart. # The backend registers a SIGTERM handler that drains in-flight requests, # closes WS connections with code 1001, and sends SSE retry before exiting. # Railway honors STOPSIGNAL and waits up to its configured stop timeout (default 30s). STOPSIGNAL SIGTERM # run-migrations.ts exits 1 on any migration error — container will NOT start if migrations fail. CMD ["sh", "-c", "cd apps/backend && node --import tsx/esm scripts/run-migrations.ts && node --import ./dist/instrumentation.js dist/index.js"]