|
| 1 | +FROM mcr.microsoft.com/playwright:v1.58.2-jammy AS builder |
| 2 | + |
| 3 | +WORKDIR /e2e |
| 4 | + |
| 5 | +COPY test/e2e/package.json test/e2e/package-lock.json ./ |
| 6 | + |
| 7 | +# Install dependencies |
| 8 | +RUN npm install \ |
| 9 | + # Install only the Chromium browser, as it is the only browser needed for the project. \ |
| 10 | + && npx playwright install chromium |
| 11 | + |
| 12 | +# Copy over remaining e2e files |
| 13 | +COPY test/e2e/ . |
| 14 | + |
| 15 | +FROM node:26-bookworm |
| 16 | + |
| 17 | +ENV INSTALL_PATH /app |
| 18 | + |
| 19 | +COPY src/js/config.mjs $INSTALL_PATH/src/js/ |
| 20 | + |
| 21 | +RUN apt-get update -y && apt-get install -y curl |
| 22 | + |
| 23 | +WORKDIR $INSTALL_PATH/test/e2e |
| 24 | + |
| 25 | +# Install Chromium dependencies using the Playwright CLI |
| 26 | +# Separation of concerns: The build stage is primarily focused on building and preparing the application, |
| 27 | +# including installing dependencies required for the application to run. |
| 28 | +# Installing Chromium dependencies in the production stage ensures that only the necessary dependencies |
| 29 | +# for running the application are included in the final image, reducing the overall image size |
| 30 | +RUN npx playwright install-deps chromium |
| 31 | + |
| 32 | +# Copy dependencies and the app |
| 33 | +COPY --from=builder /e2e . |
| 34 | + |
| 35 | +# Copy the browser binaries |
| 36 | +# https://github.com/microsoft/playwright/blob/1f209204cd18bce7d1bfae50f5af105dec752df8/utils/docker/Dockerfile.focal#L33 |
| 37 | +COPY --from=builder /ms-playwright /ms-playwright |
| 38 | + |
| 39 | +ENV CONTAINER_MODE true |
| 40 | +# Set the PLAYWRIGHT_BROWSERS_PATH environment variable to tell Playwright where to look for the browser binaries |
| 41 | +# https://github.com/microsoft/playwright/blob/1f209204cd18bce7d1bfae50f5af105dec752df8/utils/docker/Dockerfile.focal#L24 |
| 42 | +ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright |
| 43 | + |
| 44 | +# Entrypoint ensures $PLAYWRIGHT_BASE_URL has started |
| 45 | +ENTRYPOINT [ "./scripts/docker-entrypoint.sh" ] |
| 46 | + |
| 47 | +# Run playwright tests |
| 48 | +CMD ["npm", "run", "test"] |
0 commit comments