FROM python:3.11-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY ./requirements.txt .

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    protobuf-compiler \
    && rm -rf /var/lib/apt/lists/*

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

COPY ./protos ./protos
COPY ./src ./src

RUN python -m grpc_tools.protoc \
    --proto_path=./protos \
    --python_out=./src \
    --grpc_python_out=./src \
    ./protos/brunix.proto

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

EXPOSE 50051
EXPOSE 8000

ENTRYPOINT ["/entrypoint.sh"]