# Use a lightweight Debian-based image
FROM python:3.10-slim

# Set the working directory
WORKDIR /app

# Install required system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    chromium \
    chromium-driver \
    xvfb \
    x11-utils \
    xauth \
    bash \
    tzdata \
    gcc \
    musl-dev \
    libffi-dev \
    python3-dev \
    python3-tk\
    git \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Pipenv globally
RUN pip install --no-cache-dir pipenv



# Copy the remaining project files
COPY . /app/
# Ensure Pipenv uses the correct Python version
RUN pipenv --python /usr/local/bin/python3.10

# Install dependencies inside Pipenv environment
RUN pipenv install 
# --deploy --ignore-pipfile

# Set environment variables
ENV DISPLAY=:99
ENV XAUTHORITY=/root/.Xauthority

# Generate Xauthority file and start Xvfb
CMD ["sh", "-c", "xauth add $DISPLAY . $(mcookie) && Xvfb $DISPLAY -screen 0 1920x1080x24 & pipenv run python server.py"]
