Basics
Okay, what I am doing here? I want to use phantomjs as part of an application that spiders my servers for tests. This testing environment is thought to be executed on raspberry instances. Why? It’s cheap, it’s silent, it’s perfect for me.
So, how do I deploy it? The easiest way is to use docker. Why? It enables me to simply to docker-compose for my instances and to start phantomjs-docker as standalone container with an interface to run it via selenium (see phantomjs –webdriver=<PORT>).
First tries were very promising. I simply built up a phnatomjs-docker version. It’s amazing: docker can automatically build your image via Github Dockerfiles. See github.com/ollihoo/phantomjs-docker for more information.
Well, there is one problem: raspberry is not a x86 architecture, it bases on ARM. Luckily there are lots of linux packages, that run on this platform. This also suits to docker that has been built by Hypriot. This is where you will find more information: Hypriot – getting started.
So, there is only one question left. Is there an ARM-based, raspberry-compatible docker package for raspberry? Well, yeaooooo…. No:
- is it really for raspberry? github.com/sconnelley/docker-phantomjs2 – no, it’s x86 (see Dockerfile there)
- github.com/yannickcr/docker-rpi-phantomas – better, unfortunately it has too much compontents onboard (phantomas)
- hub.docker.com/r/siuying/rpi-phantomjs – ah there is no image… (status: 25.3.2016)
Okay, so I should try to build it for myself…
Build phantomjs on raspberry in a docker container
I don’t want to re-invent the wheel. There are lots of instructions in the web. This one is the most promising: how to compile phantomjs on the raspberry pi 2.
Okay, some remarks to the article. Of course, you should use the most current branch. Ariya Hidayat, the founder of phantomjs, works on branches for every new version. When I tried out (26.3.2016), I used 2.0 which threw – very late – an error and stopped. This bug is solved, fortunately. So, my finding: it makes sense to use the most recent branch.
Another remark: the instructions recommend to use a hdd or ssd to build. Do that!! It really speeds up compiling. The second thing is: use this f***ing –jobs 2 parameter. Without it, it gets a nightmare, because it builds and builds and… stops, because of full RAM.
Nerd TV – today: build phantomjs in Docker on a raspberry. Amusement factor: feels like ‚2001 – Space Odyssey’… pic.twitter.com/N7K3G4pXNy
— OlliHoo (@ollihoog) 25. März 2016
To avoid more problems, I also decided to build phantomjs in a docker container. The image I used was hypriot/rpi-node:latest. Just start it with this command:
docker run -ti hypriot/rpi-node:latest /bin/bash
And voilà: 6 hours later, the build was perfectly done.
It works! What’s next?
I really tried to save the development state into a docker container. I doesn’t make sense. The building job produces changes of more than 1.5 GB. That’s nothing, you would like to get into a repository.
So, there is an alternative. In fact, the only thing we want to get, is this phantomjs binary. So copy it, and simply put it in this hypriot/rpi-node:latest container via a normal Dockerfile. This is it. You’ll find the project with this binary here:
https://github.com/ollihoo/phantomjs-docker-rpi
Ah and of course, you also can download it from hub.docker.com:
https://hub.docker.com/r/ollihoo/phantomjs-docker-rpi/
Any questions, comments? Don’t hesitate to write me.