Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit da575d1

Browse files
committed
updated and fully working cli project
1 parent 670d921 commit da575d1

File tree

233 files changed

+81575
-1625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+81575
-1625
lines changed

.dockerignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ TestFixture.java
1111
.idea/
1212
target/*
1313
.lein-repl-history
14-
example.rb
15-
/setup
16-
/examples
17-
/test
1814
/pull.js
1915
/server.js
2016
/push.js
21-
/README.md
17+
/README.md
18+
node_modules/*
19+
docker/*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ example.rb
2121
Dockerfile
2222
*.o
2323
*.hi
24+
\#*

LICENSE

Lines changed: 19 additions & 662 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
HOSTNAME=codewars
2+
# func was removed due to issues compiling haskell using the latest base image.
3+
# We need to fix that image before we can ever update that image/codebase again :(
4+
#CONTAINERS=dotnet func jvm node python ruby systems
5+
CONTAINERS=dotnet jvm node python ruby systems alt func erlang
6+
7+
ALL_CONTAINERS=${CONTAINERS} base
8+
9+
.PHONY: ${ALL_CONTAINERS} clean docker_rm docker_rmi
10+
11+
all: ${CONTAINERS}
12+
13+
base:
14+
cp docker/$@.docker ./Dockerfile
15+
docker build -t $(HOSTNAME)/$@-runner .
16+
17+
${CONTAINERS}: base
18+
cp docker/$@.docker ./Dockerfile
19+
docker build -t $(HOSTNAME)/$@-runner .
20+
21+
# Push docker containers to registry
22+
push_to_registry:
23+
docker push $(HOSTNAME)/base-runner
24+
echo $(patsubst %, $(HOSTNAME)/%-runner, $(CONTAINERS)) | xargs -n 1 docker push
25+
26+
# Remove docker processes that have exited cleanly
27+
docker_rm_exited:
28+
[ ! -n "$(shell docker ps -a | grep Exit | cut -d ' ' -f 1)" ] || echo $(shell docker ps -a | grep Exit | cut -d ' ' -f 1) | xargs -n 1 docker rm -f
29+
30+
# Kill temporary built images might fail if not exited cleanly
31+
docker_rmi_temporary:
32+
[ ! -n "$(shell docker images --no-trunc | grep none | sed -e 's/\s\s*/\t/g' | cut -f3)" ] || docker images --no-trunc | grep none | sed -e 's/\s\s*/\t/g' | cut -f3 | xargs -n 1 docker rmi -f
33+
34+
# Kill all of the in-flight and exited docker containers
35+
docker_rm:
36+
docker ps -q | xargs docker stop
37+
[ ! -n "$(shell docker ps -a -q)" ] || echo $(shell docker ps -a -q) | xargs -n 1 docker rm -f
38+
39+
# Kill all docker images
40+
docker_rmi: docker_rm
41+
[ ! -n "$(shell docker images -q)" ] || docker images -q | xargs -n 1 docker rmi -f
42+
43+
clean: docker_rm_exited docker_rmi_temporary
44+
for i in $(shell for i in $(HOSTNAME)/base $(patsubst %, $(HOSTNAME)/%-runner, $(CONTAINERS)) ; do docker images | grep $$i | sed -e 's/\s\s*/\t/g' | cut -f1; done) ; do docker rmi -f $$i ; done
45+
46+
deep-clean: docker_rmi
47+
48+
pull:
49+
docker pull codewars/ruby-runner
50+
docker pull codewars/node-runner
51+
docker pull codewars/python-runner
52+
docker pull codewars/dotnet-runner
53+
docker pull codewars/jvm-runner
54+
docker pull codewars/systems-runner
55+
docker pull codewars/func-runner

README.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
1+
# runner
12

2-
TODO: update documentation
3+
This project is both a command-line utility and server, used by [Codewars](http://www.codewars.com) to execute small sets of code within various languages, using various testing frameworks.
4+
5+
You can run `node run --help` to view information about which arguments are supported.
6+
7+
## Purpose
8+
9+
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.
10+
11+
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.
12+
13+
## Language Support Status
14+
15+
Many languages are currently supported in various states of completeness. This list tries to keep track of each.
16+
17+
**Legend:** `!!!` = Failing Specs, `???` = Status is unknown, `*` = Any
18+
19+
| Language | solutionOnly | testSuite | Codewars | Strive | Docker Image | Examples | Notes |
20+
|--------------|--------------|----------------|--------------|----------------|----------------|--------------|-------------------------------------------------------------------------|
21+
| Bash || | Kumite | | * | | |
22+
| C || Failing | ? | | systems-runner | | |
23+
| Clojure || clojure.test | clojure.test | clojure.test | func-runner | clojure.test | |
24+
| CoffeeScript || cw-2, mocha | cw-2 | cw-2, mocha | node-runner | cw-2 | |
25+
| CPP || | | | systems-runner | | |
26+
| C# || nunit | nunit | nunit | dotnet-runner | nunit | |
27+
| Elixir || | | | erlang-runner | | |
28+
| Erlang || | | | erlang-runner | | |
29+
| F# || | Kumite Only | | dotnet-runner | | |
30+
| Go || | Kumite Only | | alt-runner | | |
31+
| Groovy || | Kumite Only | | jvm-runner | | |
32+
| Haskell || hspec!!! | hspec | hspec | func-runner | hspec | An older version is running on CW & Strive that is fully functional |
33+
| Java || junit | Yes | Yes | jvm-runner | junit | |
34+
| JavaScript || cw-2, mocha | cw-2 | cw-2, mocha | node-runner | cw-2 | |
35+
| Julia | ✓!!! | Failing | | | | | |
36+
| Lisp || | Kumite Only | | func-runner | | |
37+
| Lua || | Kumite Only | | alt-runner | | |
38+
| ObjC | ??? | ??? | | | | | |
39+
| OCAML || | Kumite Only | | func-runner | | |
40+
| Perl || | Kumite Only | | * | | |
41+
| Php || | Kumite Only | | alt-runner | | |
42+
| Python 2 || cw-2, unittest | cw-2 | cw-2, unittest | python-runner | cw-2 | |
43+
| Python 3 || cw-2, unittest | | cw-2, unittest | python-runner | cw-2 | |
44+
| R || | | | alt-runner | | |
45+
| Racket || | Kumite Only | | func-runner | | |
46+
| Ruby || cw-2, rspec | cw-2 | cw-2, rspec | ruby-runner | cw-2 | |
47+
| Rust || | | | | | |
48+
| Scala || | Kumite Only | | jvm-runner | | |
49+
| Swift | ??? | ??? | | | | | Current contribution designed for OSX, need to move to OS linux version |
50+
| TypeScript || mocha | Kumite Only | | node-runner | | TypeScript utilizes `require` instead of concatenating files |
51+
52+
53+
## Setup
54+
55+
You should have Docker installed, if not do that first. Before you can run any of the code
56+
environments you will need to build the proper Docker image. To get started lets work with the
57+
node image.
58+
59+
Run `make base node` to build the base and node images. This will take a few minutes.
60+
61+
Once you image is built, you can create a container to work within it. Doing this means you do not
62+
have to worry about having any of the project dependencies loaded directly on your machine.
63+
64+
Run the following command:
65+
66+
```
67+
docker run -it --rm --entrypoint bash -v $(pwd)/lib:/runner/lib -v $(pwd)/frameworks:/runner/frameworks -v $(pwd)/test:/runner/test codewars/node-runner
68+
```
69+
70+
This will create a new container and send you into the instance with your project's lib and test directories mounted
71+
as volumes. Mounting as a volume allows you to change files on your local machine and have those changes available to you
72+
from within the container.
73+
74+
> We do not mount the entire directory because that would overwrite things such as your node_modules directory. If you need
75+
to update these you should `make node` the image to ensure you are always testing against the correct packages.

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '2'
2+
services:
3+
base:
4+
build:
5+
context: .
6+
dockerfile: base.docker
7+
image: codewars/base-runner
8+
9+
ruby:
10+
build:
11+
context: .
12+
dockerfile: ruby.docker
13+
image: codewars/ruby-runner
14+
15+
node:
16+
build:
17+
context: .
18+
dockerfile: node.docker
19+
image: codewars/node-runner

docker/alt.docker

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
1-
# BUILD-USING: docker build -t codewars/runner-julia .
2-
# TEST-USING: docker run --rm -i -t --name=test-runner-julia --entrypoint=/bin/bash codewars/runner-julia -s
3-
# RUN-USING: docker run --rm --name=runner-julia codewars/runner-julia --help
4-
51
# Pull base image.
6-
FROM codewars/runner-base
7-
8-
# Install Julia
9-
# Julia is really slow, but v0.3 is okay (see http://stackoverflow.com/a/20566032)
10-
# In the future, don't use nightly builds, use releases
11-
RUN add-apt-repository ppa:staticfloat/julianightlies
12-
RUN add-apt-repository ppa:staticfloat/julia-deps
13-
RUN apt-get update
14-
RUN apt-get -y install julia
15-
# Nightly builds have a noisy OpenBLAS error, workaround
16-
RUN mv /usr/bin/julia /usr/bin/julia-noisy
17-
RUN printf '#!/bin/bash\njulia-noisy "$@" 2> >(grep -v "OpenBLAS : Your OS does not support AVX instructions." 1>&2)' > /usr/bin/julia
18-
RUN chmod a+x /usr/bin/julia
19-
20-
# Install erlang
21-
RUN echo "deb http://packages.erlang-solutions.com/ubuntu trusty contrib" >> /etc/apt/sources.list
22-
RUN curl http://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | apt-key add -
23-
RUN apt-get update
24-
RUN apt-get -y install erlang-nox erlang-dev
2+
FROM codewars/base-runner
253

264
# Install PHP
275
RUN apt-get -y install php-pear php5-dev libcurl3-openssl-dev
286

29-
307
# Install GoLang
318
WORKDIR /tmp
329
# http://blog.labix.org/2013/06/15/in-flight-deb-packages-of-go
@@ -36,12 +13,6 @@ RUN ./godeb install 1.3.1
3613
RUN rm godeb
3714
#RUN apt-get install -y golang
3815

39-
# Install Rust 0.11
40-
# Workaround since the author of this PPA is Scandanavian, with a unicode name, and the tools hate this
41-
RUN add-apt-repository "deb http://ppa.launchpad.net/hansjorg/rust/ubuntu trusty main"
42-
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BD6B6386
43-
RUN apt-get update
44-
RUN apt-get -y install rust-0.11
4516

4617
# Install Lua
4718
RUN apt-get install -y lua5.2
@@ -51,30 +22,13 @@ RUN apt-get install -y luarocks
5122
#RUN apt-add-repository ppa:swi-prolog/stable && apt-get update
5223
#RUN apt-get install -y swi-prolog
5324

54-
# Install ZMQ
55-
#RUN luarocks install https://raw.github.com/Neopallium/lua-zmq/master/rockspecs/lua-zmq-scm-1.rockspec
56-
RUN pecl install zmq-beta #php
57-
RUN apt-get install -y libzeromq-perl #perl
58-
59-
# Install Elixir
60-
# Elixir needs a UTF-8 locale
61-
RUN apt-get install -y locales && dpkg-reconfigure locales && locale-gen en_US.UTF-8
62-
WORKDIR /tmp
63-
RUN git clone https://github.com/elixir-lang/elixir.git
64-
WORKDIR /tmp/elixir
65-
RUN git checkout tags/v1.0.0
66-
RUN make install
67-
RUN rm -rf /tmp/elixir
68-
69-
70-
7125
# Install GNU R
7226
RUN apt-get install -y r-base
7327

7428
# ADD cli-runner and install node deps
75-
ADD . /codewars
29+
ADD . /runner
7630

77-
WORKDIR /codewars
31+
WORKDIR /runner
7832
RUN npm install
7933

8034
# Run the test suite to make sure this thing works
@@ -83,10 +37,7 @@ USER codewarrior
8337
# Set environment variables
8438
ENV USER codewarrior
8539
ENV HOME /home/codewarrior
86-
ENV LANG en_US.UTF-8
87-
ENV LANGUAGE en_US:en
88-
ENV LC_ALL en_US.UTF-8
89-
RUN mocha -t 5000 test/runners/{go,php,erlang,elixir,julia,rust,go,lua,perl,r}_spec.js
40+
RUN mocha -t 3000 test/runners/{php,go,r,lua}_spec.js
9041

9142
#timeout is a fallback in case an error with node
9243
#prevents it from exiting properly

docker/base.docker

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,35 @@
33
# RUN-USING: docker run --rm --name=runner-base codewars/runner-base --help
44

55
# Pull base image.
6-
FROM dockerfile/ubuntu
6+
FROM buildpack-deps:trusty
7+
8+
RUN apt-get update -qq
9+
10+
# gpg keys listed at https://github.com/nodejs/node
11+
RUN set -ex \
12+
&& for key in \
13+
9554F04D7259F04124DE6B476D5A82AC7E37093B \
14+
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
15+
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
16+
FD3A5288F042B6850C66B31F09FE44734EB7990E \
17+
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
18+
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
19+
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
20+
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
21+
; do \
22+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
23+
done
24+
25+
ENV NPM_CONFIG_LOGLEVEL info
26+
ENV NODE_VERSION 5.8.0
27+
28+
# Install NodeJS
29+
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
30+
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
31+
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
32+
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
33+
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
34+
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt
735

836
# Set the env variables to non-interactive
937
ENV DEBIAN_FRONTEND noninteractive
@@ -21,42 +49,28 @@ CMD ["bash"]
2149

2250
# Append any relevant run args as per the help
2351

24-
RUN apt-get update
25-
52+
ENV NODE_ENV production
2653
ENTRYPOINT ["timeout", "15", "node"]
2754

28-
# Install Node.js (needed to run actual runner)
29-
RUN add-apt-repository ppa:chris-lea/node.js
30-
RUN apt-get update
31-
RUN apt-get install -y nodejs
32-
RUN su codewarrior -c "echo '\n# Node.js\nexport PATH=\"/codewars/node_modules/.bin:$PATH\"' >> ~codewarrior/.bash_profile"
33-
3455
# Install Redis
3556
RUN apt-get install -y redis-server
3657

37-
# Install MongoDB
38-
RUN apt-get install -y mongodb-server && \
39-
mkdir -p /data/db && \
40-
chown codewarrior:codewarrior /data/db
41-
4258
# Install SQLITE
4359
RUN apt-get install -y sqlite libsqlite3-dev
4460

45-
# Install ElasticSearch
46-
RUN wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.deb && \
47-
dpkg -i elasticsearch-1.1.1.deb
61+
# Install MongoDB
62+
RUN apt-get install -y mongodb
4863

49-
# Install RabitMQ
50-
RUN apt-get install -y rabbitmq-server
64+
RUN mkdir /.npm-global
65+
RUN npm config set prefix '/.npm-global'
66+
RUN su codewarrior -c "echo 'export PATH=\"/.npm-global/bin:$PATH\"' >> ~/.profile"
67+
ENV PATH /.npm-global/bin:$PATH
5168

52-
# Install ZMQ
53-
RUN apt-get install -y libzmq3-dev
69+
# Install Node testing frameworks & additional frameworks
70+
RUN npm install -g chai mocha
5471

5572
# Install Python Basics
56-
RUN apt-get install -y python-software-properties
57-
58-
# Install Node testing frameworks & additional frameworks
59-
RUN npm -g install chai mocha
73+
RUN apt-get install -y python-minimal
6074

61-
# Install pkg-config for things that need to compile from source
62-
RUN apt-get install -y pkg-config
75+
# Install Git
76+
RUN apt-get -y install git

0 commit comments

Comments
 (0)