FROM mcr.microsoft.com/playwright/python:v1.42.0-jammy

WORKDIR /app

ENV PYTHONPATH=/app/src
ENV DBUS_SESSION_BUS_ADDRESS=/dev/null

# Install gRPC and dependencies
RUN pip install --no-cache-dir grpcio grpcio-tools playwright playwright-stealth beautifulsoup4 aiohttp

# Copy only the necessary files
COPY main.py .
COPY src/ ./src/
COPY protos/ ./protos/

# Generate gRPC stubs
RUN python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. protos/browser.proto

# Initialize Playwright
RUN playwright install chromium

EXPOSE 50052

CMD ["python3", "main.py"]
