1- # Download Playwright and its dependencies
1+ # Use a specific Playwright base image for reproducibility
22FROM mcr.microsoft.com/playwright:v1.48.1-noble
3- ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
3+ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD= true
44
5- RUN apt-get update --allow-releaseinfo-change
6-
7- # Installing the pre-required packages and libraries
8- RUN apt-get update && \
9- apt-get install -y libgtk2.0-0 \
10- libxtst6 libxss1 libnss3 xvfb
11-
12- # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
13- # Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
14- # installs, work.
15- RUN apt-get update && apt-get install -y gnupg wget && \
16- wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
17- echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
18- apt-get update && \
19- apt-get install -y google-chrome-stable --no-install-recommends && \
20- rm -rf /var/lib/apt/lists/*
21-
22-
23- # Add pptr user.
5+ # Set non-root user early for security
246RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
25- && mkdir -p /home/pptruser/Downloads \
26- && chown -R pptruser:pptruser /home/pptruser \
27- && chown -R pptruser:pptruser /home/pptruser
28-
29- # RUN mkdir /home/codecept
30-
31- COPY . /codecept
32-
33- RUN chown -R pptruser:pptruser /codecept
34- RUN runuser -l pptruser -c 'npm i --loglevel=warn --prefix /codecept'
35-
36- RUN ln -s /codecept/bin/codecept.js /usr/local/bin/codeceptjs
37- RUN mkdir /tests
38- WORKDIR /tests
39- # Install puppeteer so it's available in the container.
40- RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
7+ && mkdir -p /home/pptruser/Downloads /codecept /tests \
8+ && chown -R pptruser:pptruser /home/pptruser /codecept /tests
9+
10+ # Install dependencies in a single layer to reduce image size
11+ RUN apt-get update --allow-releaseinfo-change && apt-get install -y --no-install-recommends \
12+ libgtk2.0-0 \
13+ libxtst6 \
14+ libxss1 \
15+ libnss3 \
16+ xvfb \
17+ gnupg \
18+ wget \
19+ google-chrome-stable \
20+ fonts-noto \
21+ fonts-freefont-ttf \
22+ && wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg \
23+ && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
24+ && apt-get update \
25+ && apt-get install -y google-chrome-stable --no-install-recommends \
26+ && apt-get clean \
27+ && rm -rf /var/lib/apt/lists/*
28+
29+ # Set working directory
30+ WORKDIR /codecept
31+
32+ # Copy project files
33+ COPY . .
34+
35+ # Install Node.js dependencies as non-root user
36+ RUN runuser -u pptruser -- npm install --loglevel=warn --prefix /codecept \
37+ && npm install puppeteer@$(npm view puppeteer version) \
38+ && npx puppeteer browsers install chrome \
39+ && npx playwright install \
40+ && ln -s /codecept/bin/codecept.js /usr/local/bin/codeceptjs
41+
42+ # Verify Chrome installation
4143RUN google-chrome --version
4244
43- # Install playwright browsers
44- RUN npx playwright install
45-
46- # Allow to pass argument to codecept run via env variable
45+ # Environment variables
4746ENV CODECEPT_ARGS=""
4847ENV RUN_MULTIPLE=false
4948ENV NO_OF_WORKERS=""
50-
51- # Set HOST ENV variable for Selenium Server
5249ENV HOST=selenium
50+ ENV NODE_ENV=production
5351
54- # Run user as non privileged.
55- # USER pptruser
52+ # Switch to non-root user
53+ USER pptruser
5654
57- # Set the entrypoint
55+ # Set entrypoint and command
5856ENTRYPOINT ["/codecept/docker/entrypoint" ]
59-
60- # Run tests
61- CMD ["bash" , "/codecept/docker/run.sh" ]
57+ CMD ["bash" , "/codecept/docker/run.sh" ]
0 commit comments