|
1 | | -FROM mcr.microsoft.com/playwright:v1.53.1-jammy |
| 1 | +# === Stage 1: Build and install dependencies === |
| 2 | +FROM mcr.microsoft.com/playwright:v1.53.1-jammy AS builder |
2 | 3 |
|
3 | | -# Install Java 11 (required for Allure) |
| 4 | +# Install Java & Allure |
4 | 5 | RUN apt-get update && apt-get install -y wget gnupg2 && \ |
5 | 6 | wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \ |
6 | 7 | echo "deb [signed-by=/usr/share/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb focal main" | tee /etc/apt/sources.list.d/adoptium.list && \ |
7 | 8 | apt-get update && apt-get install -y temurin-11-jdk && \ |
| 9 | + npm install -g allure-commandline --force && \ |
8 | 10 | rm -rf /var/lib/apt/lists/* |
9 | 11 |
|
10 | | -# Install Allure CLI globally |
11 | | -RUN npm install -g allure-commandline --force |
12 | | - |
13 | | -# Set JAVA_HOME for Allure |
| 12 | +# Set up env |
14 | 13 | ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 |
15 | 14 | ENV PATH=$JAVA_HOME/bin:$PATH |
16 | 15 |
|
17 | | -# Set working directory |
18 | 16 | WORKDIR /app |
19 | | - |
20 | | -# Copy only package files first to cache layer |
21 | 17 | COPY package*.json ./ |
| 18 | +RUN npm install |
| 19 | + |
| 20 | +# === Stage 2: Final image === |
| 21 | +FROM mcr.microsoft.com/playwright:v1.53.1-jammy |
22 | 22 |
|
23 | | -# Install Node dependencies |
24 | | -RUN npm ci |
| 23 | +# Copy Java, Allure, and installed node_modules from builder |
| 24 | +COPY --from=builder /usr/lib/jvm/temurin-11-jdk-amd64 /usr/lib/jvm/temurin-11-jdk-amd64 |
| 25 | +COPY --from=builder /usr/share/keyrings/adoptium.gpg /usr/share/keyrings/adoptium.gpg |
| 26 | +COPY --from=builder /usr/local/lib/node_modules /usr/local/lib/node_modules |
| 27 | +COPY --from=builder /usr/local/bin/allure /usr/local/bin/allure |
| 28 | +COPY --from=builder /app/node_modules /app/node_modules |
25 | 29 |
|
26 | | -# Copy the rest of the application |
| 30 | +# Set up env again |
| 31 | +ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64 |
| 32 | +ENV PATH=$JAVA_HOME/bin:$PATH |
| 33 | + |
| 34 | +WORKDIR /app |
27 | 35 | COPY . . |
| 36 | +COPY env ./env |
| 37 | + |
| 38 | +# Clean unnecessary files |
| 39 | +RUN rm -rf /root/.cache /root/.npm /tmp/* |
28 | 40 |
|
29 | | -# Default CMD is overridden by GitHub Action's docker run step |
30 | 41 | CMD ["npm", "run", "test:allure"] |
0 commit comments