Skip to content

Commit 531bcce

Browse files
committed
chuggin along
1 parent 48f164c commit 531bcce

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎v4-cokapi/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ deps:
1212
docker:
1313
docker build -t="pgbovine/cokapi:v1" .
1414

15+
dockerbash:
16+
docker run -t -i --rm --user=netuser --net=none --cap-drop all pgbovine/cokapi:v1 bash
17+
1518
test:
1619
@echo 'Python'
1720
@time --portability docker run --rm pgbovine/cokapi:v1 python /tmp/python/generate_json_trace.py --code="x=1; y=2; z=x+y"
@@ -21,3 +24,6 @@ test:
2124
@echo
2225
@echo 'Java'
2326
@time --portability docker run -i --rm pgbovine/cokapi:v1 java -cp /tmp/java_jail/cp:/tmp/java_jail/cp/javax.json-1.0.jar:/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar traceprinter.InMemory < backends/java/java_jail/cp/traceprinter/test-input.txt
27+
@echo
28+
@echo 'Ruby'
29+
@time --portability docker run -i --rm pgbovine/cokapi:v1 /tmp/ruby/ruby /tmp/ruby/pg_logger.rb -c "x = 1; y = 2"

‎v4-cokapi/cokapi.js‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,39 @@ function exec_java_handler(useJSONP /* use bind first */, req, res) {
207207
postExecHandler.bind(null, res, useJSONP));
208208
}
209209

210+
app.get('/exec_ruby', exec_ruby_handler.bind(null, false));
211+
app.get('/exec_ruby_jsonp', exec_ruby_handler.bind(null, true));
212+
213+
function exec_ruby_handler(useJSONP /* use bind first */, req, res) {
214+
var usrCod = req.query.user_script;
215+
216+
var exeFile;
217+
var args = [];
218+
219+
if (USE_DOCKER_SANDBOX) {
220+
// this needs to match the docker setup in Dockerfile
221+
exeFile = '/usr/bin/docker'; // absolute path to docker executable
222+
args.push('run', '--rm', '--user=netuser', '--net=none', '--cap-drop', 'all', 'pgbovine/cokapi:v1',
223+
'/tmp/ruby/ruby',
224+
'/tmp/ruby/pg_logger.rb',
225+
'-c',
226+
usrCod);
227+
} else {
228+
assert(false);
229+
// must use Docker
230+
}
231+
232+
child_process.execFile(exeFile, args,
233+
{timeout: TIMEOUT_SECS * 1000 /* milliseconds */,
234+
maxBuffer: 5000 * 1024 /* 5MB data max */,
235+
// make SURE docker gets the kill signal;
236+
// this signal seems to allow docker to clean
237+
// up after itself to --rm the container, but
238+
// double-check with 'docker ps -a'
239+
killSignal: 'SIGINT'},
240+
postExecHandler.bind(null, res, useJSONP));
241+
}
242+
210243
function executePython(pyVer, req, res) {
211244
var parsedOptions = JSON.parse(req.query.options_json);
212245

0 commit comments

Comments
 (0)