FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

# Install libolm C library, CMake, C++ compiler, and Python headers for E2E crypto bindings
RUN apt-get update && apt-get install -y --no-install-recommends \
    libolm-dev \
    gcc \
    g++ \
    cmake \
    python3-dev \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY matrix_keycloak_bot.py .

# Create the store directory for Olm/Megolm key databases
RUN useradd -m -u 10001 botuser && \
    mkdir -p /app/store && \
    chown -R botuser:botuser /app

USER botuser

CMD ["python", "matrix_keycloak_bot.py"]
