ARG JAVA_VERSION=17

FROM eclipse-temurin:${JAVA_VERSION}-jdk

WORKDIR /app

RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \
    DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
    locales \
    wget \
    maven \
    ttf-mscorefonts-installer \
    fontconfig \
    unzip \
    libnspr4 \
    libnss3 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libx11-6 \
    libxcomposite1 \
    libxdamage1 \
    libxext6 \
    libxfixes3 \
    libxrandr2 \
    libgbm1 \
    libxcb1 \
    libxkbcommon0 \
    libasound2t64 \
    libatspi2.0-0 \
    libicu78 \
    && rm -rf /var/lib/apt/lists/* \
    && CHROME_VERSION=$(wget -qO- "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json" | grep -o '"Stable":{"channel":"Stable","version":"[^"]*"' | grep -o '"version":"[^"]*"' | sed 's/"version":"//;s/"//') \
    && wget -q "https://storage.googleapis.com/chrome-for-testing-public/${CHROME_VERSION}/linux64/chrome-headless-shell-linux64.zip" -O /tmp/chrome.zip \
    && unzip /tmp/chrome.zip -d /tmp/chrome \
    && mv /tmp/chrome/chrome-headless-shell-linux64 /opt/chrome-headless-shell \
    && ln -s /opt/chrome-headless-shell/chrome-headless-shell /usr/local/bin/chrome-headless-shell \
    && rm /tmp/chrome.zip

RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen en_US.UTF-8

RUN groupadd -r appuser && useradd -r -g appuser -m -d /home/appuser appuser
