GithubHelp home page GithubHelp logo

jpatel531 / codewars-runner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codewars/codewars-runner-cli

0.0 1.0 0.0 4.66 MB

The ability to execute sandboxed code as both a CLI tool and a server.

Home Page: www.codewars.com

License: MIT License

codewars-runner's Introduction

codewars-runner

This project is both a command-line utility and server, used by Codewars to execute small sets of code within various languages, using various testing frameworks.

You can run node run --help to view information about which arguments are supported.

Purpose

The purpose of this project is to provide a low level ability to run 'Kata'. It provides a mechanism for executing different configurations of code using various languages and testing frameworks.

Docker can be utilized in order to sandbox code execution. A server is provided that can accept 'run' requests and execute them within a Docker container.

Supported Languages and Testing Frameworks

  • JavaScript

    • mocha (coming soon...)
    • codewars
  • CoffeeScript

    • mocha (coming soon...)
    • codewars
  • Ruby

    • rspec
    • codewars
  • Python

    • unittest
    • codewars
  • Java

    • junit
  • C#

    • nunit (coming soon...)
    • codewars
  • Haskell

  • Clojure

  • Julia

  • Erlang

    • (coming soon...)

Examples:

Basic Usage

The CLI capabilities can be used without having to run Docker. As long as you have the language and frameworks installed on your host machine, you will be able to run the CLI tool standalone.

If you just wanted to execute some code and return its output, you can do so like the following:

Ruby

node run -l ruby -c 'puts 123'

JavaScript

node run -l js -c 'console.log(123)'

Python

node run -l py -c 'print 123'

Haskell

node run -l hs -c 'main = putStrLn "123"'

Clojure

node run -l clj -c '(println 123)'`

Julia

node run -l jl -c 'println(123)'

Erlang

node run -l erl -c 'io:fwrite("123\n"), init:stop().'

Kata Usage

You can also provide a test fixture to be run along with the code. The output returned is the same output that is parsed by Codewars to render its kata output.

Ruby

node run -l ruby -c 'a = 1' -f 'Test.expect a == 1'

JavaScript

node run -l js -c 'a = 1' -f 'Test.expect(a == 1)'

Python

node run -l py -c 'a = 1' -f 'test.expect(a == 1)'

Docker

Build

docker build -t codewars/cli-runner .

Unit testing

docker run -i --entrypoint mocha codewars/cli-runner test/*

Run Help

docker run --rm codewars/cli-runner --help

Run Ruby Kata

docker run --rm codewars/cli-runner run -l ruby -c 'a = 1' -f 'Test.expect a == 1'

Run JavaScript Kata

docker run --rm codewars/cli-runner run -l js -c 'a = 1' -f 'Test.expect(a == 1)'

Run Python Kata

docker run --rm codewars/cli-runner run -l py -c 'a = 1' -f 'test.expect(a == 1)'

Server

You can run a server which wraps the CLI and runs it within a Docker container. If you have Docker installed on your machine and the Codewars image built, all you need to do to start the server is run node server. You can then make posts requests to localhost:8080/run and provide the same arguments that you would for the CLI tool.

Vagrant

Version 1.6.3 or higher is required.

A fully working environment is provided via Vagrant. These steps will get a working server running:

vagrant up
vagrant ssh
cd /vagrant
node build
supervisor server.js

You should now have a fully working server with Docker support. You can access the server using localhost:8080. You can post requests to /run with the same arguments that the CLI accepts.

Notes about image versioning

The Docker images used by server.js are tagged within a version number. Some utilities have been provided to make it easier to manage versioned images.

build.js

Simply run node build to build the latest versioned image

Droplet setup

  • Grab the files

    cd /
    
    git clone https://github.com/entrefuse/codewars-runner
    cd /codewars-runner/setup
    
  • Create a non-root user and give it permissions

    sh create-user.sh
    
  • Provision the machine

    sh provision.sh
    
  • Set up the production environment

    sh prod.sh
    
  • Set up the hourly docker restart

    bash restarer.sh
    

codewars-runner's People

Contributors

azhao12345 avatar funkymonkeymonk avatar jhoffner avatar ssineriz avatar xcthulhu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.