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

Commit

Permalink
Bug fixes, split haskell into its own image, added support for langua…
Browse files Browse the repository at this point in the history
…ge versions
  • Loading branch information
jhoffner committed May 3, 2016
1 parent 04a97a6 commit 1e1b755
Show file tree
Hide file tree
Showing 19 changed files with 582 additions and 336 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ ${CONTAINERS}: base
# Push docker containers to registry
push_to_registry:
docker push $(HOSTNAME)/base-runner
echo $(patsubst %, $(HOSTNAME)/%-runner, $(CONTAINERS)) | xargs -n 1 docker push
echo $(patsubst %, $(HOSTNAME)/%-runner, $(CONTAINERS)) | xargs -n 1 docker push

# Remove docker processes that have exited cleanly
docker_rm_exited:
[ ! -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

# Cleanup temporary images that are no longer used
docker_rmi_temporary:
docker rm $(docker ps -a)
docker rmi $(docker images -q -f dangling=true)

# Kill all of the in-flight and exited docker containers
Expand All @@ -36,7 +37,7 @@ docker_rm:

# Kill all docker images
docker_rmi: docker_rm
[ ! -n "$(shell docker images -q)" ] || docker images -q | xargs -n 1 docker rmi -f
[ ! -n "$(shell docker images -q)" ] || docker images -q | xargs -n 1 docker rmi -f

clean: docker_rm_exited docker_rmi_temporary

Expand Down
80 changes: 41 additions & 39 deletions README.md

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- ./examples:/runner/examples
- ./frameworks:/runner/frameworks
- ./test:/runner/test
- ./tsconfig.json:/runner/tsconfig.json
entrypoint: ''
command: bash

Expand Down Expand Up @@ -50,6 +51,16 @@ services:
entrypoint: ''
command: bash

haskell-runner:
image: codewars/haskell-runner
volumes:
- ./lib:/runner/lib
- ./examples:/runner/examples
- ./frameworks:/runner/frameworks
- ./test:/runner/test
entrypoint: ''
command: bash

systems-runner:
image: codewars/systems-runner
volumes:
Expand Down Expand Up @@ -81,7 +92,7 @@ services:
command: bash

dotnet-runner:
image: codewars/alt-runner
image: codewars/dotnet-runner
volumes:
- ./lib:/runner/lib
- ./examples:/runner/examples
Expand Down Expand Up @@ -134,6 +145,7 @@ services:
- ./examples:/runner/examples
- ./frameworks:/runner/frameworks
- ./test:/runner/test
- ./tsconfig.json:/runner/tsconfig.json
entrypoint: 'node run -l typescript'

typescript_test:
Expand Down Expand Up @@ -200,7 +212,7 @@ services:
entrypoint: 'mocha -t 5000 test/runners/ruby_spec.js'

haskell:
image: codewars/func-runner
image: codewars/haskell-runner
volumes:
- ./lib:/runner/lib
- ./examples:/runner/examples
Expand All @@ -209,7 +221,7 @@ services:
entrypoint: 'node run -l haskell'

haskell_test:
image: codewars/func-runner
image: codewars/haskell-runner
volumes:
- ./lib:/runner/lib
- ./examples:/runner/examples
Expand Down
32 changes: 1 addition & 31 deletions docker/func.docker
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,6 @@ RUN apt-get -y install sbcl
# Install OCAML
RUN apt-get -y install ocaml-nox

# Needed to run add-apt-repository
RUN apt-get -y install software-properties-common

# Install Haskell
## ensure locale is set during build
ENV LANG C.UTF-8

RUN apt-get -y install libghc-zlib-dev happy

RUN echo 'deb http://ppa.launchpad.net/hvr/ghc/ubuntu trusty main' > /etc/apt/sources.list.d/ghc.list && \
echo 'deb http://download.fpcomplete.com/debian/jessie stable main'| tee /etc/apt/sources.list.d/fpco.list && \
# hvr keys
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6F88286 && \
# fpco keys
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C5705533DA4F78D8664B5DC0575159689BEFB442 && \
apt-get update && \
apt-get install -y --no-install-recommends cabal-install-1.22 ghc-7.10.3 happy-1.19.5 alex-3.1.4 \
stack zlib1g-dev libtinfo-dev libsqlite3-0 libsqlite3-dev ca-certificates g++ && \
rm -rf /var/lib/apt/lists/*

ENV PATH /root/.cabal/bin:/root/.local/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:/opt/happy/1.19.5/bin:/opt/alex/3.1.4/bin:$PATH

# Install Haskell Packages
RUN apt-get -y install libghc-zlib-dev pkg-config happy
RUN cabal update
RUN cabal install hspec
RUN cabal install haskell-src-exts lens
RUN cabal install esqueleto persistent-sqlite persistent-template
RUN cabal install split ifelse

# ADD cli-runner and install node deps
ADD . /runner

Expand All @@ -56,7 +26,7 @@ USER codewarrior
# Set environment variables
ENV USER codewarrior
ENV HOME /home/codewarrior
#RUN mocha -t 5000 test/runners/{haskell,ocaml,lisp,racket}_spec.js
RUN mocha -t 5000 test/runners/{ocaml,racket}_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
Expand Down
49 changes: 49 additions & 0 deletions docker/haskell.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# BUILD-USING: docker build -t codewars/runner-func .
# TEST-USING: docker run --rm -i -t --name=test-runner-func --entrypoint=/bin/bash codewars/runner-haskell -s
# RUN-USING: docker run --rm --name=runner-func codewars/runner-func --help

# Pull base image.
FROM codewars/base-runner

# Install Haskell
## ensure locale is set during build
ENV LANG C.UTF-8

RUN apt-get -y install libghc-zlib-dev happy

# Needed to run add-apt-repository
RUN apt-get -y install software-properties-common

# Install Haskell
RUN add-apt-repository ppa:hvr/ghc
RUN apt-get update
RUN apt-get install -y ghc-7.6.3 cabal-install
RUN su codewarrior -c "cd ; cabal update"
RUN su codewarrior -c "cd ; cabal install cabal"
RUN echo 'remote-repo: stackage:http://www.stackage.org/lts-1.15' >> /home/codewarrior/.cabal/config
RUN su codewarrior -c "cd ; cabal update"
RUN su codewarrior -c "cd ; cabal install cabal"

# Install Haskell Packages
RUN apt-get -y install libghc-zlib-dev pkg-config happy
RUN su codewarrior -c "cd ; cabal install split ifelse"
RUN su codewarrior -c "cd ; cabal install esqueleto persistent-sqlite persistent-template"
RUN su codewarrior -c "cd ; cabal install haskell-src-exts lens"
RUN su codewarrior -c "cd ; cabal install hspec-2.1.0 hspec-core-2.1.0 hspec-discover-2.1.0"
# ADD cli-runner and install node deps
ADD . /runner

WORKDIR /runner
RUN npm install --production

# Run the test suite to make sure this thing works

USER codewarrior
# Set environment variables
ENV USER codewarrior
ENV HOME /home/codewarrior
RUN mocha -t 5000 test/runners/haskell_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
ENTRYPOINT ["timeout", "15", "node"]
47 changes: 17 additions & 30 deletions docker/node.docker
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,29 @@
# Pull base image.
FROM codewars/base-runner

# Install additional libraries
# HACK: installing globallying and then linking has a less buggy experience.
# NOTE: we dont configure these via package.json in order to prevent having to re-install them on each code change
RUN npm link chai
RUN npm install immutable -gq; npm link immutable
RUN npm install deku -gq; npm link deku
RUN npm install quickcheck -gq; npm link quickcheck
RUN npm install should -gq; npm link should
RUN npm install expect -gq; npm link expect
RUN npm install chai-spies -gq; npm link chai-spies
RUN npm install chai-stats -gq; npm link chai-stats
RUN npm install chai-factories -gq; npm link chai-factories
RUN npm install chai-things -gq; npm link chai-things
RUN npm install chai-fuzzy -gq; npm link chai-fuzzy
RUN npm install chai-interface -gq; npm link chai-interface
RUN npm install chai-change -gq; npm link chai-change
RUN npm install chai-subset -gq; npm link chai-subset
RUN npm install rx -gq; npm link rx
RUN npm install baconjs -gq; npm link baconjs
RUN npm install lodash -gq; npm link lodash
RUN npm install react -gq; npm link react
RUN npm install react-dom -gq; npm link react-dom
RUN npm install mongoose -gq; npm link mongoose
RUN npm install mongodb -gq; npm link mongodb
RUN npm install redis -gq; npm link redis
RUN npm install sqlite3 -gq; npm link sqlite3
RUN npm install elasticsearch -gq; npm link elasticsearch
# Install Node manager so that we can have multiple versions of node
RUN npm -g install n
RUN n 0.10.33
RUN n 6.0.0

# Install Coffeescript
RUN npm -g install coffee-script

# Install TypeScript
RUN npm -g install typescript

COPY package.json package.json
RUN npm install
RUN npm install --only=dev


# Install additional libraries
# NOTE: due to this issue https://github.com/npm/npm/issues/9863 we need to install everything at once, which sucks
# because we lose the ability to quickly add new ones as a new layer
# NOTE: we dont configure these via package.json in order to prevent having to re-install them on each code change

# install TypeScript type definitions
RUN npm install -gq typings; npm link typings
RUN npm install -gq typings

RUN typings install node --ambient
RUN typings install mocha --ambient
Expand All @@ -59,15 +46,15 @@ WORKDIR /runner
RUN npm install
RUN npm install --only=dev
RUN npm dedupe # needed to fix slow babeljs performance
ENV NODE_PATH /usr/lib/node_modules
ENV NODE_PATH /usr/lib/node_modules:/runner/node_modules

# Set environment variables
USER codewarrior
ENV USER codewarrior
ENV HOME /home/codewarrior

# Run the test suite to make sure this thing works
#RUN mocha -t 5000 test/runners/{javascript,coffeescript,typescript}_spec.js
RUN mocha -t 5000 test/runners/{javascript,coffeescript,typescript}_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
Expand Down
2 changes: 1 addition & 1 deletion docker/python.docker
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ USER codewarrior

ENV USER codewarrior
ENV HOME /home/codewarrior
RUN mocha -t 5000 test/runners/{python,python3}_spec.js
RUN mocha -t 5000 test/runners/python_spec.js

#timeout is a fallback in case an error with node
#prevents it from exiting properly
Expand Down
103 changes: 72 additions & 31 deletions lib/runners/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports.run = function run(opts, cb)
if (opts.setup)
code = opts.setup + ';\n' + code;

run({name: 'node', 'args': ['-e', transform(code)]});
runNode(opts, code, run);
},
testIntegration: function (run)
{
Expand Down Expand Up @@ -71,6 +71,7 @@ function prepareMocha(opts, interfaceType, run) {
code += config.snippets.javascript.closure.end;

var solutionFile = util.codeWriteSync('javascript', transform(code), dir, 'mocha', true);
// NOTE: Mocha based testing currently does not support Node versioning
run({name: 'mocha', 'args': ['--harmony', '-u', interfaceType, '-R', 'mocha-reporter', solutionFile]});
}

Expand All @@ -94,39 +95,79 @@ function prepareCw2(opts, run)
code += opts.fixture;
code += config.snippets.javascript.inlineTestFixture.end;
code += config.snippets.javascript.end;
run({name: 'node', 'args': ['-e', transform(code)]});

runNode(opts, code, run);
}

function runNode(opts, code, run) {
var version = (opts.languageVersion || '6.x').split('/')[0]

// support 6.x/babel
if (opts.languageVersion && opts.languageVersion.split('/')[1] == 'babel') {
code = transform(code);
}
run({name: `/usr/local/n/versions/node/${nodeVersion(version)}/bin/node`, 'args': ['-e', code]});
}

function transform(code) {
function nodeVersion(version) {
switch(version) {
case "6.x":
return "6.0.0";
case "0.10.x":
return "0.10.33"
default:
return version;
}
}

function transform(code, version) {
try {
return require('babel-core').transform(code, {
presets: ["stage-1", "react"],
plugins: [
"transform-runtime",
"check-es2015-constants",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
"transform-es2015-block-scoping",
"transform-es2015-classes",
"transform-es2015-computed-properties",
"transform-es2015-destructuring",
"transform-es2015-duplicate-keys",
"transform-es2015-for-of",
"transform-es2015-function-name",
"transform-es2015-literals",
"transform-es2015-object-super",
"transform-es2015-parameters",
"transform-es2015-shorthand-properties",
"transform-es2015-spread",
"transform-es2015-sticky-regex",
"transform-es2015-template-literals",
"transform-es2015-typeof-symbol",
"transform-es2015-unicode-regex",
"transform-regenerator",
],
ast: false,
filename: 'kata'
}).code;
if (version == '0.10.x') {
return require('babel-core').transform(code, {
presets: ["stage-1", "react"],
plugins: [
"transform-runtime",
"check-es2015-constants",
"angular2-annotations",
"transform-decorators-legacy",
"transform-class-properties",
"transform-flow-strip-types",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
"transform-es2015-block-scoping",
"transform-es2015-classes",
"transform-es2015-computed-properties",
"transform-es2015-destructuring",
"transform-es2015-duplicate-keys",
"transform-es2015-for-of",
"transform-es2015-function-name",
"transform-es2015-literals",
"transform-es2015-object-super",
"transform-es2015-parameters",
"transform-es2015-shorthand-properties",
"transform-es2015-spread",
"transform-es2015-sticky-regex",
"transform-es2015-template-literals",
"transform-es2015-typeof-symbol",
"transform-es2015-unicode-regex",
"transform-regenerator",
],
ast: false,
filename: 'kata'
}).code;
} else {
return require('babel-core').transform(code, {
presets: ["stage-1", "node5", "react"],
plugins: [
"angular2-annotations",
"transform-decorators-legacy",
"transform-class-properties",
"transform-flow-strip-types",
],
ast: false,
filename: 'kata'
}).code;
}
}
catch(ex) {
var msg = ex.message;
Expand Down
Loading

0 comments on commit 1e1b755

Please sign in to comment.