adding a new language and unit-test-framework to cyber-dojo


0. make sure docker is installed.

  • For Linux see the first step here.
  • For Mac see the first step here.
  • For Windows see the first step here.


1. create a docker-image for just the language

Make this docker-image unit-test-framework agnostic.
If you are adding a new unit-test-framework to an existing language skip this step.
For example, suppose you were building Lisp
  • create a new folder for your language
    eg.
    $ md lisp
  • in your language's folder, create a file called Dockerfile
    $ cd Lisp $ touch Dockerfile
    If you can, base your new image on Alpine-linux as this will help keep images small. To do this make the first line of Dockerfile as follows
    FROM cyberdojofoundation/language-base
    Here's one based on Alpine-linux (95 MB: C, assert) C (gcc)/assert/Dockerfile
    Here's one not based on Alpine (Ubuntu 845 MB: C#, NUnit) C#/NUnit/Dockerfile
  • use the Dockerfile to try and build your docker-image.
    For example
    $ docker build -t cyberdojofoundation/lisp .
    which, if it completes, creates a new docker-image called cyberdojofoundation/lisp using the Dockerfile (and build context) in . (the current folder).


2. create a docker-image for the language and unit-test-framework

Repeat the same process, building FROM the docker-image you created in the previous step.
For example, suppose your Lisp unit-test framework is called lunit
  • create a new folder underneath your language folder
    $ cd lisp $ md lunit
  • in your new test folder, create a file called Dockerfile
    $ cd lisp/lunit $ touch Dockerfile
    The first line of this file must name the docker image you built for your language in the previous step.
    Add lines for all the commands needed to install your unit-test framework prefixed with RUN.
    FROM cyberdojofoundation/lisp RUN apt-get install -y lispy-lunit RUN apt-get install -y ...
    If you do not need any commands you should still create a Dockerfile with the single FROM line.
  • use the Dockerfile to try and build your image.
    The name of an image takes the form hub-name/image-name. Do not include a version number in the image-name. For example
    $ docker build -t cyberdojofoundation/lisp_lunit .
    which, if it completes, creates a new docker image called cyberdojofoundation/lisp_lunit using the Dockerfile in . (the current folder).


3. add a red_amber_green.rb file

  • Create a file called red_amber_green.rb containing a Ruby lambda accepting three arguments. cyber-dojo uses this to determine the test's traffic-light colour by passing it the stdout, stderr, and status outcomes of the test run. For example, here is the C#-NUnit red_amber_green.rb:
    lambda { |stdout,stderr,status| output = stdout + stderr return :red if /^Errors and Failures:/.match(output) return :green if /^Tests run: (\d+), Errors: 0, Failures: 0/.match(output) return :amber }
  • The Dockerfile for your language+testFramework must COPY red_amber_green.rb into the /usr/local/bin folder of your image. For example:
    FROM cyberdojofoundation/lisp RUN apt-get install -y lispy-lunit RUN apt-get install -y ... COPY red_amber_green.rb /usr/local/bin
  • I usually start with a red_amber_green.rb that simply returns :red. Then I use cyber-dojo to gather outputs which I use to build up a complete red_amber_green.rb


4. use the image in a new start-point

Use the new image name (eg cyberdojofoundation/lisp_lunit) in a new manifest.json file in a new start-point.

No comments:

Post a Comment