Sign inSign up

maddyonline/casperjs-docker

By maddyonline

•Updated over 10 years ago

Docker image (cloning casperbox) to run casperjs script

Image
0

411

maddyonline/casperjs-docker repository overview

⁠casperjs-docker

A Node.js module that runs CasperJS⁠ scripts in Docker containers.

It is a slightly modified version of the one used by the casperbox.com service (now shut down).

⁠Installation

Tested on Ubuntu 14.04.

  1. Install Docker⁠

  2. Build the Docker image used to run CasperJS scripts in:

    $ sudo docker build -t ubuntu/14.04:casperbox .
    
  3. Edit the run-script-in-docker--password.sh file to update the sudo password

⁠Usage

docker run -a stdout -u casperbox -h casperbox -m 192m --rm=true -v "$(pwd)":/home/casperbox/source_files -w="/home/casperbox" --env PHANTOMJS_EXECUTABLE=phantomjs/bin/phantomjs ubuntu/14.04:casperbox casperjs/bin/casperjs source_files/source.js arg1 arg2
⁠Original Usage follows
var casper = require('./casperjs-docker');
casper.runScript(
  "var casper = require('casper').create();\
  casper.start('http://casperjs.org', function() {\
    casper.echo('Hello, world!');\
  });\
  casper.run();",
  function(err, script) {
    console.log(script);
  }
);
{
  source: 'var casper = require(\'casper\').create();\ncasper.start(\'http://casperjs.org\', function() {\n  casper.echo(\'Hello, world!\');\n});\ncasper.run();\n',
  startedAt: 1434145107992,
  output: 'Hello, world!\n',
  finishedAt: 1434145111563
}

Scripts are run with CasperJS 1.1-beta3 and PhantomJS 1.9.7. If you'd like to use other versions feel free to modify the Dockerfile and rebuild the image.

Every script is automatically terminated after 30 seconds. If it's not enough for you feel free to modify the timeout in the casperjs-docker.js file (look for the maxScriptRunTime variable).

⁠Testing

There are a couple of Mocha⁠ tests. If you're curious you can run them like this (the -t option is the test case timeout):

$ mocha -t 35000

There's also a blog post⁠ on my blog.

Tag summary

Content type

Image

Digest

Size

278.5 MB

Last updated

over 10 years ago

docker pull maddyonline/casperjs-docker