Skip to content

Commit 4994cfc

Browse files
committed
added /exec_pyanaconda* endpoint
1 parent 3a35152 commit 4994cfc

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎v4-cokapi/cokapi.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,33 @@ function exec_js_handler(useJSONP /* use bind first */, isTypescript /* use bind
174174
postExecHandler.bind(null, res, useJSONP));
175175
}
176176

177+
app.get('/exec_pyanaconda', exec_pyanaconda_handler.bind(null, false));
178+
app.get('/exec_pyanaconda_jsonp', exec_pyanaconda_handler.bind(null, true));
179+
180+
function exec_pyanaconda_handler(useJSONP /* use bind first */, req, res) {
181+
var usrCod = req.query.user_script;
182+
183+
var exeFile;
184+
var args = [];
185+
186+
// must match the docker setup in backends/javascript/Dockerfile
187+
exeFile = '/usr/bin/docker'; // absolute path to docker executable
188+
args.push('run', '-m', MEM_LIMIT, '--rm', '--user=netuser', '--net=none', '--cap-drop', 'all', 'pgbovine/cokapi-python-anaconda:v1',
189+
'python',
190+
'/tmp/python/generate_json_trace.py',
191+
'--nosandbox',
192+
'--code=' + usrCod);
193+
194+
child_process.execFile(exeFile, args,
195+
{timeout: TIMEOUT_SECS * 1000 /* milliseconds */,
196+
maxBuffer: MAX_BUFFER_SIZE,
197+
// make SURE docker gets the kill signal;
198+
// this signal seems to allow docker to clean
199+
// up after itself to --rm the container, but
200+
// double-check with 'docker ps -a'
201+
killSignal: 'SIGINT'},
202+
postExecHandler.bind(null, res, useJSONP));
203+
}
177204

178205
// for running *natively* on localhost my Mac (must customize for Linux):
179206
if (local) {

0 commit comments

Comments
 (0)