# Use a slim Python image
FROM python:3.11-slim as builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
    curl \
    build-essential \
    libssl-dev \
    pkg-config \
    && rm -rf /var/lib/apt/lists/*

# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Set up workspace
WORKDIR /app

# Copy files
COPY . .

# Install maturin and build the package
RUN pip install maturin fastapi uvicorn
RUN maturin build --release --out dist --features python

# Runtime stage
FROM python:3.11-slim

WORKDIR /app

# Copy the built wheel and install it
COPY --from=builder /app/dist/*.whl .
RUN pip install *.whl fastapi uvicorn slowapi

# Copy server code
COPY jyotishcore_py/jyotishcore/server.py .

# Expose the API port
EXPOSE 8000

# Run the server
CMD ["python", "server.py"]
