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

Commit 1e1b755

Browse files
committed
Bug fixes, split haskell into its own image, added support for language versions
1 parent 04a97a6 commit 1e1b755

19 files changed

+582
-336
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ ${CONTAINERS}: base
1919
# Push docker containers to registry
2020
push_to_registry:
2121
docker push $(HOSTNAME)/base-runner
22-
echo $(patsubst %, $(HOSTNAME)/%-runner, $(CONTAINERS)) | xargs -n 1 docker push
22+
echo $(patsubst %, $(HOSTNAME)/%-runner, $(CONTAINERS)) | xargs -n 1 docker push
2323

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

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

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

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

4142
clean: docker_rm_exited docker_rmi_temporary
4243

README.md

Lines changed: 41 additions & 39 deletions
Large diffs are not rendered by default.

docker-compose.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
- ./examples:/runner/examples
88
- ./frameworks:/runner/frameworks
99
- ./test:/runner/test
10+
- ./tsconfig.json:/runner/tsconfig.json
1011
entrypoint: ''
1112
command: bash
1213

@@ -50,6 +51,16 @@ services:
5051
entrypoint: ''
5152
command: bash
5253

54+
haskell-runner:
55+
image: codewars/haskell-runner
56+
volumes:
57+
- ./lib:/runner/lib
58+
- ./examples:/runner/examples
59+
- ./frameworks:/runner/frameworks
60+
- ./test:/runner/test
61+
entrypoint: ''
62+
command: bash
63+
5364
systems-runner:
5465
image: codewars/systems-runner
5566
volumes:
@@ -81,7 +92,7 @@ services:
8192
command: bash
8293

8394
dotnet-runner:
84-
image: codewars/alt-runner
95+
image: codewars/dotnet-runner
8596
volumes:
8697
- ./lib:/runner/lib
8798
- ./examples:/runner/examples
@@ -134,6 +145,7 @@ services:
134145
- ./examples:/runner/examples
135146
- ./frameworks:/runner/frameworks
136147
- ./test:/runner/test
148+
- ./tsconfig.json:/runner/tsconfig.json
137149
entrypoint: 'node run -l typescript'
138150

139151
typescript_test:
@@ -200,7 +212,7 @@ services:
200212
entrypoint: 'mocha -t 5000 test/runners/ruby_spec.js'
201213

202214
haskell:
203-
image: codewars/func-runner
215+
image: codewars/haskell-runner
204216
volumes:
205217
- ./lib:/runner/lib
206218
- ./examples:/runner/examples
@@ -209,7 +221,7 @@ services:
209221
entrypoint: 'node run -l haskell'
210222

211223
haskell_test:
212-
image: codewars/func-runner
224+
image: codewars/haskell-runner
213225
volumes:
214226
- ./lib:/runner/lib
215227
- ./examples:/runner/examples

docker/func.docker

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,6 @@ RUN apt-get -y install sbcl
1414
# Install OCAML
1515
RUN apt-get -y install ocaml-nox
1616

17-
# Needed to run add-apt-repository
18-
RUN apt-get -y install software-properties-common
19-
20-
# Install Haskell
21-
## ensure locale is set during build
22-
ENV LANG C.UTF-8
23-
24-
RUN apt-get -y install libghc-zlib-dev happy
25-
26-
RUN echo 'deb http://ppa.launchpad.net/hvr/ghc/ubuntu trusty main' > /etc/apt/sources.list.d/ghc.list && \
27-
echo 'deb http://download.fpcomplete.com/debian/jessie stable main'| tee /etc/apt/sources.list.d/fpco.list && \
28-
# hvr keys
29-
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6F88286 && \
30-
# fpco keys
31-
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C5705533DA4F78D8664B5DC0575159689BEFB442 && \
32-
apt-get update && \
33-
apt-get install -y --no-install-recommends cabal-install-1.22 ghc-7.10.3 happy-1.19.5 alex-3.1.4 \
34-
stack zlib1g-dev libtinfo-dev libsqlite3-0 libsqlite3-dev ca-certificates g++ && \
35-
rm -rf /var/lib/apt/lists/*
36-
37-
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
38-
39-
# Install Haskell Packages
40-
RUN apt-get -y install libghc-zlib-dev pkg-config happy
41-
RUN cabal update
42-
RUN cabal install hspec
43-
RUN cabal install haskell-src-exts lens
44-
RUN cabal install esqueleto persistent-sqlite persistent-template
45-
RUN cabal install split ifelse
46-
4717
# ADD cli-runner and install node deps
4818
ADD . /runner
4919

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

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

docker/haskell.docker

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# BUILD-USING: docker build -t codewars/runner-func .
2+
# TEST-USING: docker run --rm -i -t --name=test-runner-func --entrypoint=/bin/bash codewars/runner-haskell -s
3+
# RUN-USING: docker run --rm --name=runner-func codewars/runner-func --help
4+
5+
# Pull base image.
6+
FROM codewars/base-runner
7+
8+
# Install Haskell
9+
## ensure locale is set during build
10+
ENV LANG C.UTF-8
11+
12+
RUN apt-get -y install libghc-zlib-dev happy
13+
14+
# Needed to run add-apt-repository
15+
RUN apt-get -y install software-properties-common
16+
17+
# Install Haskell
18+
RUN add-apt-repository ppa:hvr/ghc
19+
RUN apt-get update
20+
RUN apt-get install -y ghc-7.6.3 cabal-install
21+
RUN su codewarrior -c "cd ; cabal update"
22+
RUN su codewarrior -c "cd ; cabal install cabal"
23+
RUN echo 'remote-repo: stackage:http://www.stackage.org/lts-1.15' >> /home/codewarrior/.cabal/config
24+
RUN su codewarrior -c "cd ; cabal update"
25+
RUN su codewarrior -c "cd ; cabal install cabal"
26+
27+
# Install Haskell Packages
28+
RUN apt-get -y install libghc-zlib-dev pkg-config happy
29+
RUN su codewarrior -c "cd ; cabal install split ifelse"
30+
RUN su codewarrior -c "cd ; cabal install esqueleto persistent-sqlite persistent-template"
31+
RUN su codewarrior -c "cd ; cabal install haskell-src-exts lens"
32+
RUN su codewarrior -c "cd ; cabal install hspec-2.1.0 hspec-core-2.1.0 hspec-discover-2.1.0"
33+
# ADD cli-runner and install node deps
34+
ADD . /runner
35+
36+
WORKDIR /runner
37+
RUN npm install --production
38+
39+
# Run the test suite to make sure this thing works
40+
41+
USER codewarrior
42+
# Set environment variables
43+
ENV USER codewarrior
44+
ENV HOME /home/codewarrior
45+
RUN mocha -t 5000 test/runners/haskell_spec.js
46+
47+
#timeout is a fallback in case an error with node
48+
#prevents it from exiting properly
49+
ENTRYPOINT ["timeout", "15", "node"]

docker/node.docker

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,29 @@
44
# Pull base image.
55
FROM codewars/base-runner
66

7-
# Install additional libraries
8-
# HACK: installing globallying and then linking has a less buggy experience.
9-
# NOTE: we dont configure these via package.json in order to prevent having to re-install them on each code change
10-
RUN npm link chai
11-
RUN npm install immutable -gq; npm link immutable
12-
RUN npm install deku -gq; npm link deku
13-
RUN npm install quickcheck -gq; npm link quickcheck
14-
RUN npm install should -gq; npm link should
15-
RUN npm install expect -gq; npm link expect
16-
RUN npm install chai-spies -gq; npm link chai-spies
17-
RUN npm install chai-stats -gq; npm link chai-stats
18-
RUN npm install chai-factories -gq; npm link chai-factories
19-
RUN npm install chai-things -gq; npm link chai-things
20-
RUN npm install chai-fuzzy -gq; npm link chai-fuzzy
21-
RUN npm install chai-interface -gq; npm link chai-interface
22-
RUN npm install chai-change -gq; npm link chai-change
23-
RUN npm install chai-subset -gq; npm link chai-subset
24-
RUN npm install rx -gq; npm link rx
25-
RUN npm install baconjs -gq; npm link baconjs
26-
RUN npm install lodash -gq; npm link lodash
27-
RUN npm install react -gq; npm link react
28-
RUN npm install react-dom -gq; npm link react-dom
29-
RUN npm install mongoose -gq; npm link mongoose
30-
RUN npm install mongodb -gq; npm link mongodb
31-
RUN npm install redis -gq; npm link redis
32-
RUN npm install sqlite3 -gq; npm link sqlite3
33-
RUN npm install elasticsearch -gq; npm link elasticsearch
7+
# Install Node manager so that we can have multiple versions of node
8+
RUN npm -g install n
9+
RUN n 0.10.33
10+
RUN n 6.0.0
3411

3512
# Install Coffeescript
3613
RUN npm -g install coffee-script
3714

3815
# Install TypeScript
3916
RUN npm -g install typescript
4017

18+
COPY package.json package.json
19+
RUN npm install
20+
RUN npm install --only=dev
21+
22+
23+
# Install additional libraries
24+
# NOTE: due to this issue https://github.com/npm/npm/issues/9863 we need to install everything at once, which sucks
25+
# because we lose the ability to quickly add new ones as a new layer
26+
# NOTE: we dont configure these via package.json in order to prevent having to re-install them on each code change
27+
4128
# install TypeScript type definitions
42-
RUN npm install -gq typings; npm link typings
29+
RUN npm install -gq typings
4330

4431
RUN typings install node --ambient
4532
RUN typings install mocha --ambient
@@ -59,15 +46,15 @@ WORKDIR /runner
5946
RUN npm install
6047
RUN npm install --only=dev
6148
RUN npm dedupe # needed to fix slow babeljs performance
62-
ENV NODE_PATH /usr/lib/node_modules
49+
ENV NODE_PATH /usr/lib/node_modules:/runner/node_modules
6350

6451
# Set environment variables
6552
USER codewarrior
6653
ENV USER codewarrior
6754
ENV HOME /home/codewarrior
6855

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

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

docker/python.docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ USER codewarrior
3131

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

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

lib/runners/javascript.js

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports.run = function run(opts, cb)
1414
if (opts.setup)
1515
code = opts.setup + ';\n' + code;
1616

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

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

@@ -94,39 +95,79 @@ function prepareCw2(opts, run)
9495
code += opts.fixture;
9596
code += config.snippets.javascript.inlineTestFixture.end;
9697
code += config.snippets.javascript.end;
97-
run({name: 'node', 'args': ['-e', transform(code)]});
98+
99+
runNode(opts, code, run);
100+
}
101+
102+
function runNode(opts, code, run) {
103+
var version = (opts.languageVersion || '6.x').split('/')[0]
104+
105+
// support 6.x/babel
106+
if (opts.languageVersion && opts.languageVersion.split('/')[1] == 'babel') {
107+
code = transform(code);
108+
}
109+
run({name: `/usr/local/n/versions/node/${nodeVersion(version)}/bin/node`, 'args': ['-e', code]});
98110
}
99111

100-
function transform(code) {
112+
function nodeVersion(version) {
113+
switch(version) {
114+
case "6.x":
115+
return "6.0.0";
116+
case "0.10.x":
117+
return "0.10.33"
118+
default:
119+
return version;
120+
}
121+
}
122+
123+
function transform(code, version) {
101124
try {
102-
return require('babel-core').transform(code, {
103-
presets: ["stage-1", "react"],
104-
plugins: [
105-
"transform-runtime",
106-
"check-es2015-constants",
107-
"transform-es2015-arrow-functions",
108-
"transform-es2015-block-scoped-functions",
109-
"transform-es2015-block-scoping",
110-
"transform-es2015-classes",
111-
"transform-es2015-computed-properties",
112-
"transform-es2015-destructuring",
113-
"transform-es2015-duplicate-keys",
114-
"transform-es2015-for-of",
115-
"transform-es2015-function-name",
116-
"transform-es2015-literals",
117-
"transform-es2015-object-super",
118-
"transform-es2015-parameters",
119-
"transform-es2015-shorthand-properties",
120-
"transform-es2015-spread",
121-
"transform-es2015-sticky-regex",
122-
"transform-es2015-template-literals",
123-
"transform-es2015-typeof-symbol",
124-
"transform-es2015-unicode-regex",
125-
"transform-regenerator",
126-
],
127-
ast: false,
128-
filename: 'kata'
129-
}).code;
125+
if (version == '0.10.x') {
126+
return require('babel-core').transform(code, {
127+
presets: ["stage-1", "react"],
128+
plugins: [
129+
"transform-runtime",
130+
"check-es2015-constants",
131+
"angular2-annotations",
132+
"transform-decorators-legacy",
133+
"transform-class-properties",
134+
"transform-flow-strip-types",
135+
"transform-es2015-arrow-functions",
136+
"transform-es2015-block-scoped-functions",
137+
"transform-es2015-block-scoping",
138+
"transform-es2015-classes",
139+
"transform-es2015-computed-properties",
140+
"transform-es2015-destructuring",
141+
"transform-es2015-duplicate-keys",
142+
"transform-es2015-for-of",
143+
"transform-es2015-function-name",
144+
"transform-es2015-literals",
145+
"transform-es2015-object-super",
146+
"transform-es2015-parameters",
147+
"transform-es2015-shorthand-properties",
148+
"transform-es2015-spread",
149+
"transform-es2015-sticky-regex",
150+
"transform-es2015-template-literals",
151+
"transform-es2015-typeof-symbol",
152+
"transform-es2015-unicode-regex",
153+
"transform-regenerator",
154+
],
155+
ast: false,
156+
filename: 'kata'
157+
}).code;
158+
} else {
159+
return require('babel-core').transform(code, {
160+
presets: ["stage-1", "node5", "react"],
161+
plugins: [
162+
"angular2-annotations",
163+
"transform-decorators-legacy",
164+
"transform-class-properties",
165+
"transform-flow-strip-types",
166+
],
167+
ast: false,
168+
filename: 'kata'
169+
}).code;
170+
}
130171
}
131172
catch(ex) {
132173
var msg = ex.message;

0 commit comments

Comments
 (0)