Files
bakery-ia/services/training/Dockerfile

71 lines
2.2 KiB
Docker
Raw Normal View History

2026-01-19 16:31:11 +01:00
# =============================================================================
# Training Service Dockerfile - Environment-Configurable Base Images
# =============================================================================
# Build arguments for registry configuration:
# - BASE_REGISTRY: Registry URL (default: docker.io for Docker Hub)
# - PYTHON_IMAGE: Python image name and tag (default: python:3.11-slim)
# =============================================================================
ARG BASE_REGISTRY=docker.io
ARG PYTHON_IMAGE=python:3.11-slim
FROM ${BASE_REGISTRY}/${PYTHON_IMAGE} AS shared
2025-07-17 15:55:23 +02:00
WORKDIR /shared
COPY shared/ /shared/
2026-01-19 16:31:11 +01:00
ARG BASE_REGISTRY=docker.io
ARG PYTHON_IMAGE=python:3.11-slim
FROM ${BASE_REGISTRY}/${PYTHON_IMAGE}
2025-07-17 13:54:51 +02:00
WORKDIR /app
2025-11-05 13:34:56 +01:00
# Install system dependencies including cmdstan requirements
2025-07-17 13:54:51 +02:00
RUN apt-get update && apt-get install -y \
gcc \
2025-11-05 13:34:56 +01:00
g++ \
make \
2025-07-17 13:54:51 +02:00
curl \
2025-11-05 13:34:56 +01:00
build-essential \
2025-07-17 13:54:51 +02:00
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
COPY shared/requirements-tracing.txt /tmp/
2025-07-17 15:55:23 +02:00
COPY services/training/requirements.txt .
2025-07-17 13:54:51 +02:00
# Install Python dependencies
RUN pip install --no-cache-dir -r /tmp/requirements-tracing.txt
2025-07-17 13:54:51 +02:00
RUN pip install --no-cache-dir -r requirements.txt
2025-07-17 15:55:23 +02:00
# Copy shared libraries from the shared stage
COPY --from=shared /shared /app/shared
2025-07-17 13:54:51 +02:00
# Copy application code
2025-07-17 15:55:23 +02:00
COPY services/training/ .
2025-07-17 13:54:51 +02:00
2025-09-30 13:32:51 +02:00
2025-07-17 13:54:51 +02:00
# Add shared libraries to Python path
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"
2025-07-17 13:54:51 +02:00
2025-11-05 13:34:56 +01:00
# Set TMPDIR for cmdstan (directory will be created at runtime)
ENV TMPDIR=/tmp/cmdstan
# Install cmdstan for Prophet (required for model optimization)
# Suppress verbose output to reduce log noise
RUN python -m pip install --no-cache-dir cmdstanpy && \
python -m cmdstanpy.install_cmdstan
2025-09-30 21:58:10 +02:00
2025-07-17 13:54:51 +02:00
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Run application with increased WebSocket ping timeout to handle long training operations
# Default uvicorn ws-ping-timeout is 20s, increasing to 300s (5 minutes) to prevent
# premature disconnections during CPU-intensive ML training (typically 2-3 minutes)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--ws-ping-timeout", "300"]