From 7bd06f4f330e80ae9c09fff0d86145fbe2c28041 Mon Sep 17 00:00:00 2001 From: Matthias Winkelmann Date: Tue, 7 Mar 2017 21:54:07 +0100 Subject: [PATCH] 1.0.0 --- .gitignore | 2 ++ Dockerfile | 57 +++++++++++++++++++++++++++++++++++++ README.md | 20 +++++++++++-- lighthouse-chromium-xvfb.sh | 29 +++++++++++++++++++ output/.keep | 0 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100755 lighthouse-chromium-xvfb.sh create mode 100644 output/.keep 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