diff --git a/Dockerfile b/Dockerfile index bf1ffca..aa5774f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,22 +13,10 @@ WORKDIR / 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\ - openrc\ - dbus-x11\ - libx11\ - xorg-server\ - ttf-opensans\ - wait4ports\ - chromium +RUN echo "http://dl-2.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories +RUN echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories +RUN echo "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories +RUN echo "http://dl-2.alpinelinux.org/alpine/v3.2/main" >> /etc/apk/repositories #----------------- # Set ENV and change mode @@ -43,31 +31,43 @@ ENV SCREEN_HEIGHT 1334 ENV SCREEN_DEPTH 24 ENV DISPLAY :99.0 ENV PATH /lighthouse/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -#:99.0 + ENV GEOMETRY "$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH" RUN echo $TZ > /etc/timezone -RUN rc-update add dbus default - - -#RUN npm --global install yarn && yarn global add lighthouse - -# DEV -RUN apk add git libressl +#----------------- +# Add packages +#----------------- +RUN apk -U --no-cache update +RUN apk -U --no-cache add \ + zlib-dev \ + chromium \ + xvfb \ + wait4ports \ + xorg-server \ + dbus-x11 \ + dbus \ + ttf-freefont \ + mesa-dri-swrast \ + git + +# DEV Version of lighthouse + +RUN apk -U --no-cache add git RUN git clone https://github.com/GoogleChrome/lighthouse.git - WORKDIR /lighthouse +RUN npm -g install yarn +RUN yarn install +RUN cd ./lighthouse-core && yarn install +RUN cd ./lighthouse-cli && yarn install && tsc +RUN npm run install-all && npm run build-all && npm link -RUN npm install && npm run install-all && npm run build-all && npm link - - -RUN apk del --force git libressl # Minimize size -RUN apk del --force curl make gcc g++ python linux-headers binutils-gold gnupg +RUN apk del --force curl make gcc g++ python linux-headers binutils-gold gnupg git RUN rm -rf /var/lib/apt/lists/* \ /var/cache/apk/* \ @@ -79,15 +79,10 @@ RUN rm -rf /var/lib/apt/lists/* \ /usr/lib/node_modules/npm/scripts -ADD lighthouse-chromium-xvfb.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 +ADD lighthouse-chromium-xvfb.sh /lighthouse/lighthouse-chromium-xvfb.sh VOLUME /lighthouse/output ENTRYPOINT ["/lighthouse/lighthouse-chromium-xvfb.sh"] -CMD ["--skip-autolaunch","--disable-cpu-throttling=true","--output-path=/tmp/test-report.html", "--output=pretty", "https://matthi.coffee/2017/lighthouse-chromium-headless-docker"] +CMD ["test"] diff --git a/README.md b/README.md index b0eb296..accadff 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ docker run -v ./output/:/lighthouse/output/ lighthouse --output-path=/lighthouse ## Testing ```shell -docker run lighthouse +docker run lighthouse test ``` ## Links diff --git a/lighthouse-chromium-xvfb.sh b/lighthouse-chromium-xvfb.sh index 0ac2fc8..3317a90 100755 --- a/lighthouse-chromium-xvfb.sh +++ b/lighthouse-chromium-xvfb.sh @@ -7,16 +7,19 @@ _kill_procs() { } 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"; +parameters=$@ + +if [ $parameters == 'test' ]; then + testing=1; + parameters='--skip-autolaunch --disable-cpu-throttling --output-path=/tmp/test-report.html --output=html https://google.com"' + printf "\n\nRunning 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 [ ! -e /var/run/dbus ] && mkdir /var/run/dbus -start-stop-daemon --start --pidfile /var/run/dbus.pid --exec /usr/bin/dbus-daemon -- --system +/usr/bin/dbus-daemon --system # Setup a trap to catch SIGTERM and relay it to child processes trap _kill_procs SIGTERM @@ -25,9 +28,7 @@ TMP_PROFILE_DIR=`mktemp -d -t chromium.XXXXXX` export CHROME_DEBUGGING_PORT=9222 # Start Xvfb -Xvfb ${DISPLAY} -ac -screen 0 ${GEOMETRY} -nolisten tcp & - -xvfb=$! +Xvfb ${DISPLAY} -ac +iglx -screen 0 ${GEOMETRY} -nolisten tcp & xvfb=$! printf "Starting xvfb window server" @@ -37,10 +38,11 @@ printf "xvfb started" printf "Starting chromium, with debugger on port $CHROME_DEBUGGING_POST" +# --disable-webgl \ + $LIGHTHOUSE_CHROMIUM_PATH \ --no-sandbox \ --user-data-dir=${TMP_PROFILE_DIR} \ ---disable-webgl \ --start-maximized \ --remote-debugging-port=${CHROME_DEBUGGING_PORT} \ --no-first-run "about:blank" & @@ -52,9 +54,9 @@ wait4ports tcp://127.0.0.1:$CHROME_DEBUGGING_PORT printf "chromium started" printf "launching lighthouse run" -lighthouse $@ if [ "$testing" -eq "1" ]; then + lighthouse --skip-autolaunch --disable-cpu-throttling --output-path=/tmp/test-report.html --output=html https://google.com if grep -q -F "Best Practice" /tmp/test-report*; then printf "Test succeeded!"; return 0; @@ -62,4 +64,6 @@ if [ "$testing" -eq "1" ]; then printf "Test failed!"; return 1; +else + lighthouse $@ fi