diff --git a/Dockerfile b/Dockerfile index 1a22960..abb32f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM mhart/alpine-node:latest LABEL description "Run Google Chrome's Lighthouse Audit in the background" -LABEL version="1.0.3" +LABEL version="1.0.5" LABEL author="Matthias Winkelmann " LABEL coffee.matthi.vcs-url="https://github.com/MatthiasWinkelmann/lighthouse-chromium-alpine-docker" @@ -27,7 +27,8 @@ RUN apk -U --no-cache upgrade && \ libx11\ xorg-server\ chromium\ - ttf-opensans + ttf-opensans\ + wait4ports #----------------- # Set ENV and change mode #----------------- @@ -45,6 +46,8 @@ ENV GEOMETRY "$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH" RUN echo $TZ > /etc/timezone +RUN rc-update add dbus default + ADD lighthouse-chromium-xvfb.sh . ADD test.sh . RUN npm --global install yarn && yarn global add lighthouse diff --git a/lighthouse-chromium-xvfb.sh b/lighthouse-chromium-xvfb.sh index 460f47b..53bc25c 100755 --- a/lighthouse-chromium-xvfb.sh +++ b/lighthouse-chromium-xvfb.sh @@ -6,16 +6,22 @@ _kill_procs() { kill -TERM $xvfb } -# Setup a trap to catch SIGTERM and relay it to child processes -trap _kill_procs SIGTERM +/usr/bin/dbus-uuidgen --ensure=/etc/machine-id -XVFB_WHD=${XVFB_WHD:-1280x720x16} +# We need to test if /var/run/dbus exists, since script will fail if it does not -export DISPLAY=:99 +[ ! -e /var/run/dbus ] && mkdir /var/run/dbus +start-stop-daemon --start --pidfile /var/run/dbus.pid --exec /usr/bin/dbus-daemon -- --system + +# Setup a trap to catch SIGTERM and relay it to child processes +trap _kill_procs SIGTERM + +TMP_PROFILE_DIR=`mktemp -d -t chromium.XXXXXX` +CHROME_DEBUGGING_PORT=9222 # Start Xvfb -dbus-run-session -- Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp & +Xvfb ${DISPLAY} -ac -screen 0 ${GEOMETRY} -nolisten tcp & xvfb=$! @@ -23,13 +29,21 @@ while [ 1 -gt $xvfb ]; do echo "waiting for Xvfb to start: $xvfb"; sleep 1; do echo "xvfb started" - -dbus-run-session -- /usr/bin/chromium-browser --no-sandbox --user-data-dir=$TMP_PROFILE_DIR --start-maximized --no-first-run --remote-debugging-port=9222 "about:blank" & +echo "Starting chromium, with debugger on port $CHROME_DEBUGGING_POST" +/usr/bin/chromium-browser \ +--no-sandbox \ +--user-data-dir=${TMP_PROFILE_DIR} \ +--disable-webgl \ +--start-maximized \ +--remote-debugging-port=${CHROME_DEBUGGING_PORT} \ +--no-first-run "about:blank" & chromium=$! -while [ 1 -gt $chromium ]; do echo "waiting for chromium to start"; sleep 1; done +wait4ports tcp://127.0.0.1:$CHROME_DEBUGGING_PORT echo "chromium started" -lighthouse --port=9222 --disable-webgl --skip-autolaunch --disable-cpu-throttling=true $@ +lighthouse --port=${CHROME_DEBUGGING_PORT} \ + --skip-autolaunch \ + --disable-cpu-throttling=true $@ diff --git a/test.sh b/test.sh index d9241bf..73fe281 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,5 @@ #!/bin/sh -/lighthouse/lighthouse-chromium-xvfb.sh --output-path=/tmp/test-report.html "https://matthi.coffee" +./lighthouse-chromium-xvfb.sh --output-path=/tmp/test-report.html https://matthi.coffee + grep -q "Best Practices" /tmp/test-report*