49 lines
1.2 KiB
Docker
49 lines
1.2 KiB
Docker
# AI Orchestrator - Optimized Production Dockerfile
|
|
# Multi-stage build for minimal image size
|
|
|
|
FROM python:3.12-slim as builder
|
|
|
|
WORKDIR /build
|
|
|
|
# Install build dependencies
|
|
RUN pip install --no-cache-dir --upgrade pip wheel
|
|
|
|
# Copy and install Python dependencies
|
|
COPY requirements.txt .
|
|
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt
|
|
|
|
# Production stage
|
|
FROM python:3.12-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Create non-root user for security
|
|
RUN useradd --create-home --shell /bin/bash appuser
|
|
|
|
# Install wheels from builder stage
|
|
COPY --from=builder /wheels /wheels
|
|
RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels
|
|
|
|
# Copy application code
|
|
COPY server.py .
|
|
|
|
# Set ownership
|
|
RUN chown -R appuser:appuser /app
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Environment variables (can be overridden)
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
|
|
# Expose port
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/api/health')" || exit 1
|
|
|
|
# Run the application
|
|
CMD ["python", "-m", "uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8080"]
|