59 lines
1.8 KiB
Docker
59 lines
1.8 KiB
Docker
# Dockerfile
|
|
# -----------
|
|
|
|
# Imagen base Python
|
|
FROM python:3.11-slim
|
|
|
|
# Construcción para CUDA 12.1 por defecto (usa --build-arg TORCH_CUDA=cpu para CPU)
|
|
ARG TORCH_CUDA=cu121
|
|
|
|
WORKDIR /app
|
|
|
|
# Paquetes del sistema necesarios
|
|
# - libpq-dev y gcc: para compilar dependencias que hablen con PostgreSQL (psycopg2)
|
|
# - git: algunos modelos/liberías pueden tirar de git
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libpq-dev \
|
|
gcc \
|
|
git \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Ajustes de pip / runtime
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
|
TOKENIZERS_PARALLELISM=false \
|
|
HF_HUB_DISABLE_SYMLINKS_WARNING=1
|
|
|
|
# Dependencias Python
|
|
COPY requirements.txt ./
|
|
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
|
|
|
|
# Instala PyTorch:
|
|
# - Con CUDA 12.1 si TORCH_CUDA=cu121 (requiere runtime nvidia al ejecutar)
|
|
# - Con ruedas CPU si TORCH_CUDA=cpu
|
|
RUN if [ "$TORCH_CUDA" = "cu121" ]; then \
|
|
pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cu121 \
|
|
torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 ; \
|
|
else \
|
|
pip install --no-cache-dir \
|
|
torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 ; \
|
|
fi
|
|
|
|
# Instala el resto de dependencias de tu app
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Descarga el modelo de spaCy (español) para NER
|
|
# Si el entorno de build no tiene red, no rompas la build: intenta en runtime.
|
|
RUN python -m spacy download es_core_news_md || true
|
|
|
|
# Copia el código de la app
|
|
COPY . .
|
|
|
|
# Descarga de recursos NLTK que usa newspaper3k (no crítico en build)
|
|
RUN python download_models.py || true
|
|
|
|
# Puerto que usa gunicorn en el servicio web
|
|
EXPOSE 8000
|
|
|
|
# El CMD/entrypoint se define en docker-compose.yml (web, scheduler, workers)
|
|
|