FROM registry.access.redhat.com/ubi9/ubi

WORKDIR /app
RUN mkdir -p /data/
ENV DB_PATH=/data/kai_solutions.db

RUN dnf --refresh -y update \
 && dnf -y install python3.12-devel python3.12-pip libpq-devel \
 && dnf -y clean all

# Copy project files
COPY src/ src/
COPY pyproject.toml .
COPY README.md .

# Install Python dependencies
RUN pip3.12 install --no-cache-dir .

# Create a non-root user
RUN useradd -m mcp
# Set permissions for the data directory
RUN chown -R mcp:0 /data

#allow access to write logs (this is a hack)
RUN chown -R mcp:0 /app
RUN chmod g+rwX /app

USER mcp

# Default to SSE transport on port 8000
EXPOSE 8000

CMD ["sh", "-c", "python3.12 -m kai_mcp_solution_server --transport streamable-http --host 0.0.0.0 --port 8000 --mount-path=${MOUNT_PATH:-/}"]
