80 lines
2.2 KiB
Docker
80 lines
2.2 KiB
Docker
# Multi-stage build per LLM Monitor
|
|
|
|
# Stage 1: Build CSS with Tailwind
|
|
FROM node:18-alpine AS css-builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copiare file di configurazione npm.
|
|
# Nota: package-lock.json puo non essere presente in alcuni deploy.
|
|
COPY package*.json tailwind.config.js ./
|
|
|
|
# Installare dipendenze Node
|
|
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
|
|
|
|
# Copiare input CSS e file usati dal content scan di Tailwind.
|
|
# Questo passaggio deve avvenire prima della build per invalidare cache quando cambiano template/js.
|
|
COPY app/web/static/css/input.css ./app/web/static/css/
|
|
COPY app/web/templates/ ./app/web/templates/
|
|
COPY app/web/static/js/ ./app/web/static/js/
|
|
|
|
# Compilare CSS Tailwind
|
|
RUN npm run tailwind:build
|
|
|
|
# Verifica bloccante: output.css deve essere compilato e non vuoto.
|
|
RUN test -s ./app/web/static/css/output.css && \
|
|
CSS_LINES=$(wc -l < ./app/web/static/css/output.css) && \
|
|
echo "[css-builder] output.css lines: ${CSS_LINES}" && \
|
|
test "${CSS_LINES}" -ge 100
|
|
|
|
# Stage 2: Build Python packages
|
|
FROM python:3.11-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Installare dipendenze di build
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copiare requirements
|
|
COPY requirements.txt .
|
|
|
|
# Installare Python packages in un virtualenv
|
|
RUN python -m venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Stage 3: Runtime
|
|
FROM python:3.11-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Installare dipendenze di runtime
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copiare il virtualenv dal builder
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
|
|
# Copiare codice dell'app
|
|
COPY --from=css-builder /app/app/web/static/css/output.css ./app/web/static/css/output.css
|
|
COPY app/ /app/app/
|
|
COPY main.py /app/
|
|
|
|
# Impostare PATH
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# Esporre la porta
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000/api/v1/health || exit 1
|
|
|
|
# Comando di avvio
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|