Skip to content
This repository has been archived by the owner on Apr 12, 2018. It is now read-only.

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWinkelmann committed Mar 9, 2017
1 parent 78e74af commit b1850fa
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 24 deletions.
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <m@matthi.coffee>"
LABEL coffee.matthi.vcs-url="https://github.com/MatthiasWinkelmann/lighthouse-chromium-alpine-docker"
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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"]
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://github.com/MatthiasWinkelmann/lighthouse-chromium-alpine-docker>

```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: <https://hub.docker.com/r/matthiaswinkelmann/lighthouse-chromium-alpine/>

```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: <https://matthi.coffee/lighthouse-chromium-headless-docker>
32 changes: 24 additions & 8 deletions lighthouse-chromium-xvfb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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} \
Expand All @@ -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
1 change: 0 additions & 1 deletion lighthouse.test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
sut:
build: .
command: /lighthouse/test.sh
5 changes: 0 additions & 5 deletions test.sh

This file was deleted.

0 comments on commit b1850fa

Please sign in to comment.