FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

# Install libolm C library and build dependencies for E2E crypto bindings
RUN apt-get update && apt-get install -y --no-install-recommends \
    libolm-dev \
    gcc \
    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"]
