FROM --platform=linux/amd64 ubuntu:22.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies including python3-pil
# Also install system libraries required by PIL's C extensions
# These libraries must persist even after python3-pil is removed
RUN apt-get update && apt-get install -y \
    blender \
    python3-pip \
    python3-pil \
    wget \
    xvfb \
    libjpeg8 \
    libjpeg-turbo8 \
    libpng16-16 \
    libtiff5 \
    libwebp7 \
    libwebpdemux2 \
    libwebpmux3 \
    libopenjp2-7 \
    liblcms2-2 \
    libfreetype6 \
    libimagequant0 \
    libraqm0 \
    libxcb1 \
    zlib1g \
    libxxf86vm1 \
    libxfixes3 \
    libxi6 \
    libxrender1 \
    libgl1 \
    libglu1-mesa \
    && rm -rf /var/lib/apt/lists/*

# Set up working directory
WORKDIR /addon-test

# Blender requires a display, use Xvfb for headless operation
ENV DISPLAY=:99

# Copy helper script to run Blender with virtual display
COPY run_blender.sh /usr/local/bin/run_blender.sh
RUN chmod +x /usr/local/bin/run_blender.sh

CMD ["/bin/bash"]