# Multi-stage build to create a minimal image
FROM python:3.13-slim AS builder

# Create working directory
WORKDIR /app

# poetry export -f requirements.txt --output requirements.txt --without-hashes
# Copy dependency files
COPY requirements.txt ./

# Install dependencies to a target directory
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install --no-cache-dir --no-deps --disable-pip-version-check --target=/app/site-packages -r requirements.txt

# Use Alpine as the base image for a much smaller footprint
FROM python:3.13-slim

# Copy installed packages from builder stage
COPY --from=builder /app/site-packages /app/site-packages

# Copy application code
COPY index.html favicon.ico /app/
COPY myice /app/myice

# Set PYTHONPATH so Python can find our installed packages
ENV PYTHONPATH=/app/site-packages

# Set working directory
WORKDIR /app

# Create a non-root user for security
RUN useradd --home-dir /app --no-create-home --uid 1000 myice
USER myice

# Expose port
EXPOSE 8000

# Run the application
ENTRYPOINT ["python", "-m", "uvicorn", "myice.webapi:app", "--host", "0.0.0.0", "--port", "8000"]
