Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Dockerfiles #254

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 4 additions & 52 deletions Dockerfile.a11y-regression
Original file line number Diff line number Diff line change
@@ -1,59 +1,11 @@
FROM node:18.19.1-bullseye
FROM --platform=linux/amd64 pixel-base-regression:latest

ARG PA11Y_VERSION

ENV \
PA11Y_VERSION=$PA11Y_VERSION

# Base packages
RUN apt-get update && \
apt-get install -y git sudo software-properties-common
ENV PA11Y_VERSION=$PA11Y_VERSION

RUN set -ex && \
DEBIAN_VERSION=$(cat /etc/os-release | grep VERSION_ID | cut -d '=' -f2 | tr -d '"') && \
export DEBIAN_VERSION=$DEBIAN_VERSION && \
ARCH=`uname -m` && \
if [ "$ARCH" = "x86_64" ]; then \
sudo npm install -g --unsafe-perm=true --allow-root pa11y@${PA11Y_VERSION}; \
else \
sudo PUPPETEER_SKIP_DOWNLOAD=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install -g --unsafe-perm=true --allow-root pa11y@${PA11Y_VERSION} puppeteer@21.7.0 puppeteer-chromium-version-finder@^1.0.1 chromium-version-deb-finder@^2.0.1 && \
NODE_PATH="$(npm root -g):$(npm root -g)/puppeteer/node_modules" node -e " \
const versionFinder = require('puppeteer-chromium-version-finder'); \
const debFinder = require('chromium-version-deb-finder'); \
(async () => { \
const version = await versionFinder.getPuppeteerChromiumVersion(); \
const debUrls = await debFinder.getDebUrlsForVersionAndArch(version.MAJOR, version.MINOR, process.env.DEBIAN_VERSION, 'arm64'); \
console.log(debUrls.join('\n')); \
})(); \
" | \
xargs -I % sh -c 'set -x; echo "Downloading: %"; wget -c -t 10 -w 10 -T 120 %; echo "Downloaded: %"' && \
apt install -y ./*.deb && \
rm -f ./*.deb && \
sudo test -f /usr/bin/chromium && sudo ln -s /usr/bin/chromium /usr/bin/chromium-browser && sudo ln -s /usr/bin/chromium /usr/bin/chrome; \
fi

RUN wget https://dl-ssl.google.com/linux/linux_signing_key.pub && sudo apt-key add linux_signing_key.pub
RUN sudo add-apt-repository "deb http://dl.google.com/linux/chrome/deb/ stable main"

RUN apt-get -qqy update \
&& apt-get -qqy --no-install-recommends install \
libxshmfence-dev \
libfontconfig \
libfreetype6 \
xfonts-cyrillic \
xfonts-scalable \
fonts-liberation \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
libgbm-dev \
gconf-service libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 libatk1.0-0 libc6 ca-certificates fonts-liberation lsb-release xdg-utils wget \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get -qyy clean

RUN sudo npm install -g mustache
RUN sudo npm install -g node-fetch@2

ENV NODE_PATH=/usr/local/lib/node_modules
sudo npm install -g --unsafe-perm=true --allow-root pa11y@${PA11Y_VERSION} \
mustache node-fetch@2;

#ENTRYPOINT ["tail", "-f", "/dev/null"]
ENTRYPOINT ["node", "src/a11y/runA11yTests.js"]
71 changes: 71 additions & 0 deletions Dockerfile.base-regression
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
FROM --platform=linux/amd64 node:18.19.1-bullseye-slim

# Base packages and Chrome dependencies
RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends \
git \
sudo \
software-properties-common \
libfontconfig \
libfreetype6 \
xfonts-cyrillic \
xfonts-scalable \
fonts-dejavu \
fonts-dejavu-core \
fonts-dejavu-extra \
fonts-linex \
fonts-texgyre \
fonts-noto \
fonts-liberation \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
libgbm-dev \
gconf-service \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxss1 \
libxtst6 \
libappindicator1 \
libnss3 \
libasound2 \
libatk1.0-0 \
libc6 \
ca-certificates \
lsb-release \
xdg-utils \
wget \
libatk-bridge2.0-0 \
libdrm2 \
libgbm1 \
libxkbcommon0 \
procps \
tree \
&& apt-get clean -qy \
&& rm -rf /var/lib/apt/lists/* \
&& echo "Installed fonts:" \
&& fc-list

ENV NODE_PATH=/usr/local/lib/node_modules
24 changes: 9 additions & 15 deletions Dockerfile.mediawiki
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
FROM docker-registry.wikimedia.org/dev/buster-php74-fpm:1.0.0-s3

COPY node-preparation.sh /node-preparation.sh

RUN /node-preparation.sh ensure_node_major_version_installed 18 || \
(echo "Failed to install Node" && exit 1)

WORKDIR /var/www/html/w

RUN git config --global user.email "app@example.com" && git config --global user.name "app"

# IMPORTANT: Any local dependency that `setupRepos.sh` needs MUST have a `COPY`
# statement here before `setupRepos.sh` is executed. We copy individual files
# instead of copying the entire `src` directory so that Docker's build cache
# isn't unnecessarily busted each time a file in the `src` directory changes.
# See:
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache
# See: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache
COPY node-preparation.sh /node-preparation.sh
COPY src/BatchSpawn.js /src/BatchSpawn.js
COPY src/setupRepos.sh /src/setupRepos.sh
COPY repositories.json /repositories.json
COPY composer.local.json composer.local.json

RUN /src/setupRepos.sh "$( cat /repositories.json )"
WORKDIR /var/www/html/w

# Needed to install WikiLambda's dependencies
COPY composer.local.json composer.local.json
RUN /node-preparation.sh ensure_node_major_version_installed 18 || \
(echo "Failed to install Node" && exit 1) && \
git config --global user.email "app@example.com" && \
git config --global user.name "app" && \
/src/setupRepos.sh "$( cat /repositories.json )"

# Now we can copy the entire src directory since setupRepos.sh has executed.
COPY src /src
54 changes: 3 additions & 51 deletions Dockerfile.visual-regression
Original file line number Diff line number Diff line change
@@ -1,59 +1,11 @@
FROM node:18.19.1-bullseye
FROM --platform=linux/amd64 pixel-base-regression:latest

ARG BACKSTOPJS_VERSION

ENV \
BACKSTOPJS_VERSION=$BACKSTOPJS_VERSION

# Base packages
RUN apt-get update && \
apt-get install -y git sudo software-properties-common
ENV BACKSTOPJS_VERSION=$BACKSTOPJS_VERSION

RUN set -ex && \
DEBIAN_VERSION=$(cat /etc/os-release | grep VERSION_ID | cut -d '=' -f2 | tr -d '"') && \
export DEBIAN_VERSION=$DEBIAN_VERSION && \
ARCH=`uname -m` && \
if [ "$ARCH" = "x86_64" ]; then \
sudo npm install -g --unsafe-perm=true --allow-root backstopjs@${BACKSTOPJS_VERSION}; \
else \
sudo PUPPETEER_SKIP_DOWNLOAD=true PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install -g --unsafe-perm=true --allow-root backstopjs@${BACKSTOPJS_VERSION} puppeteer-chromium-version-finder@^1.0.1 chromium-version-deb-finder@^2.0.1 && \
NODE_PATH="$(npm root -g):$(npm root -g)/backstopjs/node_modules" node -e " \
const versionFinder = require('puppeteer-chromium-version-finder'); \
const debFinder = require('chromium-version-deb-finder'); \
(async () => { \
const version = await versionFinder.getPuppeteerChromiumVersion(); \
const debUrls = await debFinder.getDebUrlsForVersionAndArch(version.MAJOR, version.MINOR, process.env.DEBIAN_VERSION, 'arm64'); \
console.log(debUrls.join('\n')); \
})(); \
" | \
xargs -I % sh -c 'set -x; echo "Downloading: %"; wget -c -t 10 -w 10 -T 120 %; echo "Downloaded: %"' && \
apt install -y ./*.deb && \
rm -f ./*.deb && \
sudo test -f /usr/bin/chromium && sudo ln -s /usr/bin/chromium /usr/bin/chromium-browser && sudo ln -s /usr/bin/chromium /usr/bin/chrome; \
fi

RUN wget https://dl-ssl.google.com/linux/linux_signing_key.pub && sudo apt-key add linux_signing_key.pub
RUN sudo add-apt-repository "deb http://dl.google.com/linux/chrome/deb/ stable main"

# RUN apt-get -y update && apt-get -y install google-chrome-stable

# RUN apt-get install -y firefox-esr

# gconf-service libxext6.... added for https://github.com/garris/BackstopJS/issues/1225

RUN apt-get -qqy update \
&& apt-get -qqy --no-install-recommends install \
libfontconfig \
libfreetype6 \
xfonts-cyrillic \
xfonts-scalable \
fonts-liberation \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
libgbm-dev \
gconf-service libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 libatk1.0-0 libc6 ca-certificates fonts-liberation lsb-release xdg-utils wget \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get -qyy clean
sudo npm install -g --unsafe-perm=true --allow-root backstopjs@${BACKSTOPJS_VERSION};

WORKDIR /src

Expand Down
5 changes: 5 additions & 0 deletions pixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ async function processCommand( type, opts, runSilently = false ) {
// store details of this run.
fs.writeFileSync( `${__dirname}/context.json`, JSON.stringify( context ) );

await batchSpawn.spawn(
'docker',
[ 'build', '--progress', 'plain', '-f', 'Dockerfile.base-regression', '-t', 'pixel-base-regression:latest', '.' ]
);

// Start docker containers.
await batchSpawn.spawn(
'docker',
Expand Down