52 lines
1.8 KiB
Docker
52 lines
1.8 KiB
Docker
FROM node:20-bullseye
|
|
|
|
# Allow host UID/GID to be provided so test artifacts are created with
|
|
# matching ownership when the workspace volume is mounted.
|
|
ARG HOST_UID=1000
|
|
ARG HOST_GID=1000
|
|
|
|
# Install Chromium and related deps at image build time so test runs are fast
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends chromium ca-certificates fonts-liberation curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Avoid puppeteer downloading its own Chromium when using puppeteer-core
|
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
|
|
|
# Copy only the puppeteer test folder so we can install deps into the image
|
|
WORKDIR /opt/puppeteer-test
|
|
# Copy package files (package-lock.json may not exist in workspace)
|
|
COPY tools/puppeteer-test/package.json ./
|
|
COPY tools/puppeteer-test/package-lock.json ./
|
|
|
|
# Install dependencies (if package-lock.json missing, npm ci will fail; fall back to npm i)
|
|
RUN set -eux; \
|
|
if [ -f package-lock.json ]; then npm ci --no-audit --no-fund --silent; else npm i --no-audit --no-fund --silent; fi
|
|
|
|
# Copy the rest of the test files
|
|
COPY tools/puppeteer-test/ /opt/puppeteer-test/
|
|
|
|
WORKDIR /opt/puppeteer-test
|
|
|
|
## Create a host user so files created during test runs have the host UID/GID
|
|
RUN if ! getent group ${HOST_GID} >/dev/null 2>&1; then \
|
|
groupadd -g ${HOST_GID} hostgroup; \
|
|
else \
|
|
echo "group for GID ${HOST_GID} already exists"; \
|
|
fi
|
|
|
|
RUN if ! getent passwd ${HOST_UID} >/dev/null 2>&1; then \
|
|
useradd -m -u ${HOST_UID} -g ${HOST_GID} -s /bin/bash hostuser; \
|
|
else \
|
|
echo "user for UID ${HOST_UID} already exists"; \
|
|
mkdir -p /home/hostuser || true; \
|
|
fi
|
|
|
|
RUN chown -R ${HOST_UID}:${HOST_GID} /opt/puppeteer-test || true
|
|
|
|
ENV HOME=/home/hostuser
|
|
USER ${HOST_UID}:${HOST_GID}
|
|
|
|
# Default entrypoint runs the test; the workspace is mounted by docker-compose
|
|
ENTRYPOINT ["node", "test.js"]
|