diff --git a/Dockerfile b/Dockerfile index abb32f7..d25f758 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.5" +LABEL version="1.0.7" LABEL author="Matthias Winkelmann " LABEL coffee.matthi.vcs-url="https://github.com/MatthiasWinkelmann/lighthouse-chromium-alpine-docker" @@ -37,8 +37,8 @@ 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_WIDTH 750 +ENV SCREEN_HEIGHT 1334 ENV SCREEN_DEPTH 24 ENV DISPLAY :99 #:99.0 @@ -48,8 +48,6 @@ 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 RUN mkdir output @@ -66,8 +64,15 @@ RUN rm -rf /var/lib/apt/lists/* \ /usr/lib/node_modules/npm/html \ /usr/lib/node_modules/npm/scripts + +ADD lighthouse-chromium-xvfb.sh . +ADD test.sh . + # Alpine's grep is a BusyBox binary which doesn't provide # the -R (recursive, following symlinks) switch. #ADD grep ./grep # RUN alias grep=/lighthouse/grep + ENTRYPOINT ["/lighthouse/lighthouse-chromium-xvfb.sh"] + +CMD ["--skip-autolaunch","--disable-cpu-throttling=true","--output-path=/tmp/test-report.html", "--output=pretty", "https://matthi.coffee/lighthouse-chromium-headless-docker"] diff --git a/README.md b/README.md index 496bfb1..99bc6c9 100644 --- a/README.md +++ b/README.md @@ -4,21 +4,47 @@ 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: +## Installation + +### From Github + +Github URL: ```shell git clone git@github.com:MatthiasWinkelmann/lighthouse-chromium-alpine-docker.git - docker build -t lighthouse-chromium-alpine-docker + docker build -t lighthouse lighthouse-chromium-alpine-docker +``` + +### From Docker Hub + +Docker Hub URL: + +```shell +docker pull matthiaswinkelmann/lighthouse-chromium-alpine ``` +## Usage + 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: +### Quickstart: Print to STDOUT + ```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 +docker run lighthouse --output-path=stdout https://google.com ``` -Run the tesT: +### Saving to file ```shell -docker run -it --rm --entrypoint=sh lighthouse test.sh +docker run -v ./output/:/lighthouse/output/ lighthouse --output-path=/lighthouse/output/results.html --save-assets --save-artifacts https://google.com ``` + +## Testing + +```shell +docker run lighthouse +``` + +## Links + +Canonical URL: diff --git a/lighthouse-chromium-xvfb.sh b/lighthouse-chromium-xvfb.sh index 53bc25c..5ee7933 100755 --- a/lighthouse-chromium-xvfb.sh +++ b/lighthouse-chromium-xvfb.sh @@ -6,7 +6,11 @@ _kill_procs() { kill -TERM $xvfb } -/usr/bin/dbus-uuidgen --ensure=/etc/machine-id +testing=0 +echo $@ | grep -q -F 'matthi.coffee' && testing=1; +if [ "$testing" -eq "1" ]; then + printf "\n\nNo options given, running test...\n\nRun with an URL, or '--help' to see options\n\n"; +fi # We need to test if /var/run/dbus exists, since script will fail if it does not @@ -25,11 +29,14 @@ Xvfb ${DISPLAY} -ac -screen 0 ${GEOMETRY} -nolisten tcp & xvfb=$! -while [ 1 -gt $xvfb ]; do echo "waiting for Xvfb to start: $xvfb"; sleep 1; done +printf "Starting xvfb window server" -echo "xvfb started" +while [ 1 -gt $xvfb ]; do printf "waiting for Xvfb to start: $xvfb"; sleep 1; done + +printf "xvfb started" + +printf "Starting chromium, with debugger on port $CHROME_DEBUGGING_POST" -echo "Starting chromium, with debugger on port $CHROME_DEBUGGING_POST" /usr/bin/chromium-browser \ --no-sandbox \ --user-data-dir=${TMP_PROFILE_DIR} \ @@ -42,8 +49,17 @@ chromium=$! wait4ports tcp://127.0.0.1:$CHROME_DEBUGGING_PORT -echo "chromium started" +printf "chromium started" + +printf "launching lighthouse run" +lighthouse $@ + +if [ "$testing" -eq "1" ]; then + if grep -q -F "Best Practice" /tmp/test-report*; then + printf "Test succeeded!"; + return 0; + fi -lighthouse --port=${CHROME_DEBUGGING_PORT} \ - --skip-autolaunch \ - --disable-cpu-throttling=true $@ + printf "Test failed!"; + return 1; +fi diff --git a/lighthouse.test.yml b/lighthouse.test.yml index e1aef22..ebb5e74 100644 --- a/lighthouse.test.yml +++ b/lighthouse.test.yml @@ -1,3 +1,2 @@ sut: build: . - command: /lighthouse/test.sh diff --git a/test.sh b/test.sh deleted file mode 100755 index 73fe281..0000000 --- a/test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -./lighthouse-chromium-xvfb.sh --output-path=/tmp/test-report.html https://matthi.coffee - -grep -q "Best Practices" /tmp/test-report*