Skip to content

Commit 1ead456

Browse files
committed
Use multi-stage builds to keep the image smaller. Clean up unnecessary files after install to reduce image size.
1 parent 43635a6 commit 1ead456

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

Dockerfile.playwright

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
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
23

3-
# Install Java 11 (required for Allure)
4+
# Install Java & Allure
45
RUN apt-get update && apt-get install -y wget gnupg2 && \
56
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /usr/share/keyrings/adoptium.gpg && \
67
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 && \
78
apt-get update && apt-get install -y temurin-11-jdk && \
9+
npm install -g allure-commandline --force && \
810
rm -rf /var/lib/apt/lists/*
911

10-
# Install Allure CLI globally
11-
RUN npm install -g allure-commandline --force
12-
13-
# Set JAVA_HOME for Allure
12+
# Set up env
1413
ENV JAVA_HOME=/usr/lib/jvm/temurin-11-jdk-amd64
1514
ENV PATH=$JAVA_HOME/bin:$PATH
1615

17-
# Set working directory
1816
WORKDIR /app
19-
20-
# Copy only package files first to cache layer
2117
COPY package*.json ./
18+
RUN npm install
19+
20+
# === Stage 2: Final image ===
21+
FROM mcr.microsoft.com/playwright:v1.53.1-jammy
2222

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
2529

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
2735
COPY . .
36+
COPY env ./env
37+
38+
# Clean unnecessary files
39+
RUN rm -rf /root/.cache /root/.npm /tmp/*
2840

29-
# Default CMD is overridden by GitHub Action's docker run step
3041
CMD ["npm", "run", "test:allure"]

0 commit comments

Comments
 (0)