Files
LLM-infa/Dockerfile.api
2026-03-01 21:42:05 +05:00

51 lines
1.8 KiB
Docker

# syntax=docker/dockerfile:1.5
# Builder: install build deps and build wheels
FROM python:3.14-slim AS builder
WORKDIR /app
#RUN apt-get update && apt-get install -y --no-install-recommends \
# build-essential \
# ca-certificates \
# && rm -rf /var/lib/apt/lists/*
#
COPY requirements.txt ./
# Build wheels into /wheels (use cache for pip downloads)
RUN --mount=type=cache,target=/root/.cache/pip \
pip wheel --no-cache-dir -r requirements.txt -w /wheels
# Final image: small and without build tools
FROM python:3.14-slim AS final
WORKDIR /app
## minimal runtime deps (use static ffmpeg to avoid many apt deps)
#RUN apt-get update && apt-get install -y --no-install-recommends \
# ca-certificates \
# curl \
# && rm -rf /var/lib/apt/lists/*
# Copy wheels from builder and install
COPY --from=builder /wheels /wheels
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-cache-dir /wheels/* || pip install --no-cache-dir /wheels/* --no-deps
# Download a static ffmpeg build (faster than installing via apt and avoids many deps)
RUN set -eux; \
arch="$(dpkg --print-architecture)"; \
if [ "$arch" = "amd64" ]; then \
FFMPEG_URL="https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz"; \
else \
echo "Unsupported arch $arch"; exit 1; \
fi; \
curl -fsSL "$FFMPEG_URL" -o /tmp/ffmpeg.tar.xz; \
tar -xJf /tmp/ffmpeg.tar.xz -C /tmp; \
cp /tmp/ffmpeg-*-amd64-static/ffmpeg /usr/local/bin/; \
cp /tmp/ffmpeg-*-amd64-static/ffprobe /usr/local/bin/; \
chmod +x /usr/local/bin/ffmpeg /usr/local/bin/ffprobe; \
rm -rf /tmp/ffmpeg*
# Copy application code (exclude models/data via .dockerignore)
COPY . ./api
CMD ["python", "-m", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"]