diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..273eba9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/output/* +!/output/.keep diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d44e1fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +FROM mhart/alpine-node:latest +LABEL version="1.0" +LABEL description="Run Google Chrome's Lighthouse Audit in the background" +WORKDIR /lighthouse + +USER root + +RUN echo "http://dl-2.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories && \ + echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \ + echo "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories + +#----------------- +# Add packages +#----------------- +RUN apk -U --no-cache upgrade && \ + apk --no-cache add xvfb\ + dbus-x11\ + libx11\ + xorg-server\ + chromium\ + ttf-opensans +#----------------- +# Set ENV and change mode +#----------------- +ENV LIGHTHOUSE_CHROMIUM_PATH /usr/bin/chromium-browser + +ENV TZ "Europe/Berlin" +ENV DEBIAN_FRONTEND noninteractive +ENV DEBCONF_NONINTERACTIVE_SEEN true +ENV SCREEN_WIDTH 1360 +ENV SCREEN_HEIGHT 1020 +ENV SCREEN_DEPTH 24 +ENV DISPLAY :99 +#:99.0 +ENV GEOMETRY "$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH" + +RUN echo $TZ > /etc/timezone + +ADD lighthouse-chromium-xvfb.sh . +RUN npm --global install yarn && yarn global add lighthouse +RUN mkdir output + +# Minimize size + +RUN apk del --force curl make gcc g++ python linux-headers binutils-gold gnupg + +RUN rm -rf /var/lib/apt/lists/* \ + /var/cache/* \ + /usr/share/man \ + /tmp/* \ + /usr/lib/node_modules/npm/man \ + /usr/lib/node_modules/npm/doc \ + /usr/lib/node_modules/npm/html \ + /usr/lib/node_modules/npm/scripts + + +ENTRYPOINT ["/lighthouse/lighthouse-chromium-xvfb.sh"] diff --git a/README.md b/README.md index 96b0b2a..2e9bb0c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ -# lighthouse-chrome-alpine-docker -Run Google's Lighthouse headless in the background +# lighthouse/chromium/alpine/docker image + +**Run Google's Lighthouse headless in the background** + +This image allows you to quickly run [lighthouse](https://github.com/GoogleChrome/lighthouse) in a headless container. That's useful if you want to run it from a CI server, or in the background of your workstation. + +To install: + +```shell + git clone git@github.com:MatthiasWinkelmann/lighthouse-chromium-alpine-docker.git + docker build -t lighthouse-chromium-alpine-docker +``` + +Processes within the container cannot easily access the host's file system. You can either print to STDOUT and redirect to a file, or mount a local folder in the container, as shown here: + +```shell + run -v ./output/:/lighthouse/output/ lighthouse-chromium-alpine-docker --output-path=/lighthouse/output/results.html --save-assets --save-artifacts --output=html https://google.com +``` diff --git a/lighthouse-chromium-xvfb.sh b/lighthouse-chromium-xvfb.sh new file mode 100755 index 0000000..630a01d --- /dev/null +++ b/lighthouse-chromium-xvfb.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +_kill_procs() { + kill -TERM $chromium + wait $chromium + kill -TERM $xvfb +} + +# Setup a trap to catch SIGTERM and relay it to child processes +trap _kill_procs SIGTERM + +XVFB_WHD=${XVFB_WHD:-1280x720x16} + +export DISPLAY=:99 + +# Start Xvfb +Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp & + +xvfb=$! + + + + +/usr/bin/chromium-browser --no-sandbox --user-data-dir=$TMP_PROFILE_DIR --start-maximized --no-first-run --remote-debugging-port=9222 "about:blank" & + +chromium=$! + +echo $@ +lighthouse $@ diff --git a/output/.keep b/output/.keep new file mode 100644 index 0000000..e69de29