-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (55 loc) · 2.27 KB
/
Dockerfile
File metadata and controls
77 lines (55 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# syntax=docker/dockerfile:1.7
FROM node:22-alpine AS web-builder
WORKDIR /app/web
COPY web/package.json web/package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY web/ ./
# Build frontend so FastAPI can serve it from /web/static.
RUN npm run build -- --base=/web/static/
FROM python:3.11-slim AS py-builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_LINK_MODE=copy
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential && \
rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir uv
COPY pyproject.toml uv.lock README.md ./
# Install only API runtime dependencies; the training stack (torch/cuda) is not
# needed for the web service and was causing Railway build timeouts.
RUN uv sync --frozen --no-install-project --only-group api
# The API can run model bots from `.pt` checkpoints; install CPU-only torch in
# the API venv so Railway does not need CUDA runtimes.
RUN uv pip install --python /app/.venv/bin/python --index-url https://download.pytorch.org/whl/cpu torch
FROM python:3.11-slim AS runtime
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:${PATH}" \
APP_HOST=0.0.0.0 \
APP_PORT=8000 \
MODEL_CHECKPOINT_PATH=/app/checkpoints/last.ckpt
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends libgomp1 tini && \
rm -rf /var/lib/apt/lists/*
COPY --from=py-builder /app/.venv /app/.venv
COPY src ./src
COPY alembic.ini ./alembic.ini
COPY alembic ./alembic
COPY .env.example ./.env.example
# Replace legacy static bundle with current React build output.
COPY --from=web-builder /app/web/dist/ ./src/api/modules/web/static/
RUN mkdir -p /app/checkpoints
EXPOSE 8000
ENTRYPOINT ["tini", "--"]
CMD ["sh", "-c", "uvicorn api.app:app --app-dir src --host 0.0.0.0 --port ${PORT:-8000}"]
# Optional target that bakes a local torch checkpoint into the image.
# Requires checkpoints/last.ckpt in build context.
FROM runtime AS runtime-with-model
COPY checkpoints/last.ckpt /app/checkpoints/last.ckpt
# Optional target for future ONNX runtime integration.
FROM runtime AS runtime-with-onnx
COPY checkpoints/last.onnx /app/checkpoints/last.onnx
# Default/final stage used by platforms that don't set --target (e.g. Railway).
FROM runtime AS final