# Reproducible CI image: JDK 17 + Maven + Chrome (headless). Selenium Manager auto-fetches the
# matching chromedriver at runtime, so no driver is baked in.
#
#   docker build -t healing-tests .
#   docker run --rm healing-tests                                  # run all tests
#   docker run --rm healing-tests mvn -B test -Dcucumber.filter.tags="@myTest"   # by tag
#   docker run --rm -e HEALING_DB_URL=... healing-tests            # point at a DB (optional)
#
# For a big cross-browser grid instead, leave this out and set healing.remote.url / HEALING_REMOTE_URL.

FROM maven:3.9-eclipse-temurin-17

# Install Google Chrome (stable). chromedriver is provided by Selenium Manager at test time.
RUN apt-get update \
 && apt-get install -y --no-install-recommends wget gnupg ca-certificates \
 && wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg \
 && echo "deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
 && apt-get update \
 && apt-get install -y --no-install-recommends google-chrome-stable \
 && rm -rf /var/lib/apt/lists/*

ENV HEALING_HEADLESS=true \
    HEALING_BROWSER=chrome

WORKDIR /work
# Warm the dependency cache first for faster rebuilds.
COPY pom.xml .
RUN mvn -B -q dependency:go-offline || true
COPY . .

# Default: run the whole suite. Override the command to filter by tag (see header).
CMD ["mvn", "-B", "test"]
