I had been looking for some type of tool that would be similar to what the Google Mobile-Friendly Test web app does. For internal enterprise apps, the Google tool doesn’t help too much as it can’t see them. Eventually, I came across the W3C Mobile-Checker. This does most of what I’d need to do, but it’s deployment is a bit of a challenge. To simplify things, I thought it might be a fine idea to package it up using Docker.
The first thing to note is that the W3C Mobile-Checker has a bunch of dependencies such as:
- The Mobile Checker app node.js process
- Google Chrome
- browsermob-proxy running on port 8080
- ImageMagick
- XVFB
The number of processes violates the Docker best practice of running only a single-process per container and I am not a big fan of approaches like the ones advocated by the Phusion Baseimage-Docker container. But in the interest of simplifying deployment, I figured might be okay for this type of app. This of course means running something like supervisord.
The first big challenge was figuring out how to get XVFB running in Docker. Thankfully, Linuxmeerkat has an excellent post on running a GUI application in a Docker container, which was incredibly helpful in setting this up. One thing that was interesting was that it seems like Chrome has changed quite a bit as there was no need to run the container in privilaged mode. From there, the rest of the set was pretty straight forward and I hacked up supervisord config that looks a bit like this:
[supervisord]
nodaemon=true
[program:browsermob-proxy]
command=/opt/browsermob-proxy-2.1.0-beta-1/bin/browsermob-proxy --use-littleproxy true
[program:Xvfb]
command=/usr/bin/Xvfb :1 -screen 0 1920x1080x24
[program:node]
command=/usr/bin/node /opt/Mobile-Checker/app.js > /dev/stdout
The full code is up on GitHub here. It’s also published to Docker Hub and you can run it like so:
docker run -p 3000:3000 damnhandy/mobile-checker-docker
I’m still figuring out how best to package the Node.js app itself. Right now, the build on Docker hub contains a snapshot of the Mobile-Checker version at the time it was built. The one upside of using supervisord here is that it respawns the Mobile-Checker app each it crashes, which is quite often. But at any rate, this type of set up gives you can idea how one could do automated browser testing using Docker.