# Use Ubuntu base image (24.04)
FROM ubuntu:24.04

# Noninteractive frontend for apt
ENV DEBIAN_FRONTEND=noninteractive
# Set license server environment variable
ENV QT_LICENSE_SERVER=<QLS_SERVER_URL>
# Set the Installer file version
ENV SQUISH_INSTALLER=squish-9.2.2-qt68x-linux64.run

# Update and install required packages (minimal runtime + tools)
RUN apt-get update && apt-get install -y \
    libfontconfig1 \
    libfreetype6 \
    libice6 \
    libsm6 \
    libstdc++6 \
    libx11-6 \
    libx11-xcb1 \
    libxcb-icccm4 \
    libxcb-image0 \
    libxcb-keysyms1 \
    libxcb-randr0 \
    libxcb-render-util0 \
    libxcb-render0 \
    libxcb-shape0 \
    libxcb-shm0 \
    libxcb-sync1 \
    libxcb-xfixes0 \
    libxcb-xinerama0 \
    libxcb-xkb1 \
    libxcb1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxft2 \
    libxkbcommon-x11-0 \
    libxkbcommon0 \
    libxrandr2 \
    libxtst6 \
    zlib1g \
    libegl1 \
    libxcb-cursor0 \
    libglib2.0-0 \
    # GTK3 — required by Squish IDE (Eclipse/SWT)
    libgtk-3-0 \
    # Mesa / OpenGL software rendering for Qt
    libgl1 \
    libgl1-mesa-dri \
    libgles2 \
    # DBus — required for Qt file dialogs, notifications, system tray
    dbus \
    libdbus-1-3 \
    # Additional xcb plugins Qt may need
    libxcb-util1 \
    libxcb-ewmh2 \
    && apt-get clean

# Set working directory
WORKDIR /app
RUN mkdir -p /app/squish/

# Set DISPLAY environment variable
ENV DISPLAY=:0

# Force Qt to use X11/XCB with software rendering
ENV QT_QPA_PLATFORM=xcb \
    QT_AUTO_SCREEN_SCALE_FACTOR=1 \
    QT_XCB_GL_INTEGRATION=none \
    LIBGL_ALWAYS_SOFTWARE=1

# Copy application files
COPY ${SQUISH_INSTALLER} /app/
COPY install_squish.sh /app/
COPY start.sh /app/
RUN chmod +x /app/start.sh /app/install_squish.sh

# Run Squish installer, then remove the .run file. Note this doesn't
# actually shrink the image: the earlier COPY layer already baked the
# installer's bytes into the image permanently, so deleting it here only
# keeps it out of the *running* container's filesystem, not out of the
# image's stored layers/history. This trade-off is intentional, since it
# keeps the installer swappable per customer rather than pinned/verified
# ahead of time — see README for details.
RUN bash /app/install_squish.sh && rm -f "/app/${SQUISH_INSTALLER}"

# Expose ports for Squish server and AUT
# EXPOSE 4322 9999

# Default command
CMD ["bash", "/app/start.sh"]
