File size: 2,371 Bytes
fdfe81a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d03058
 
 
 
 
 
 
 
 
fdfe81a
 
 
 
 
5d03058
 
fdfe81a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# syntax=docker/dockerfile:1.7
# Build container for the Farient Brand Review API.
#
# Includes LibreOffice + Poppler + a font bundle so the headless slide
# rendering pipeline (task fn-1-sya.4) has everything it needs at runtime.
# Python deps are managed reproducibly via `uv` and the committed `uv.lock`.

FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    UV_LINK_MODE=copy \
    UV_COMPILE_BYTECODE=1 \
    UV_PROJECT_ENVIRONMENT=/app/.venv \
    PATH="/app/.venv/bin:/root/.local/bin:${PATH}"

# System deps:
#   libreoffice-impress     -> soffice headless for .pptx -> .pdf
#   poppler-utils           -> pdf2image (PDF -> PNG)
#   fonts-liberation        -> Arial / Times / Courier metric-compatibles
#   fonts-crosextra-carlito -> Calibri metric-compatible (PowerPoint body font)
#   fonts-crosextra-caladea -> Cambria metric-compatible (PowerPoint heading)
#   fonts-dejavu            -> broad latin coverage
#   fonts-noto-cjk          -> prevents silent glyph substitution (visual
#                              fidelity for fn-1-sya.4)
#   ca-certificates+curl    -> needed to fetch the uv installer
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libreoffice-impress \
        poppler-utils \
        fonts-liberation \
        fonts-crosextra-carlito \
        fonts-crosextra-caladea \
        fonts-dejavu \
        fonts-noto-cjk \
        ca-certificates \
        curl \
    && rm -rf /var/lib/apt/lists/*

# Install uv via the official installer.
RUN curl -LsSf https://astral.sh/uv/install.sh | sh

WORKDIR /app

# Copy lockfile + project metadata first so the dep layer caches.
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev

# Pre-warm soffice once at build time so the first runtime invocation is fast
# and any font / profile init failures surface during `docker build`, not in
# production.
RUN mkdir -p /tmp/prewarm \
    && printf "Pre-warm" > /tmp/prewarm/seed.txt \
    && soffice --headless \
        -env:UserInstallation=file:///tmp/lo_prewarm \
        --convert-to pdf \
        --outdir /tmp/prewarm \
        /tmp/prewarm/seed.txt \
    && rm -rf /tmp/prewarm /tmp/lo_prewarm

# Now copy the rest of the source.
COPY . .

EXPOSE 8000

CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]