Create new workspace for every eval

This commit is contained in:
1computer1 2019-06-15 21:22:43 -04:00
parent bc67dbbfd7
commit 700b66c183
23 changed files with 17 additions and 99 deletions

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.apl
apl --OFF -s -f program.apl || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.sh
bash program.sh || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.c
gcc program.c -o program && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.clj
clojure program.clj || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.cpp
g++ program.cpp -o program && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,10 +1,6 @@
if [ "$EVAL_EXPR" = "true" ]; then
printf %s "$1" | csharp -e
else
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.cs
csc program.cs >/dev/null && mono program.exe || true
cd .. && rm -rf "$CODEDIR"
fi

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.exs
elixir program.exs || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.fs
fsharpc --optimize- program.fs >/dev/null && mono program.exe || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,7 +1,3 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
export GOCACHE=/tmp/"$CODEDIR"/cache
printf %s "$1" > program.go
go run program.go || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,10 +1,6 @@
if [ "$EVAL_EXPR" = "true" ]; then
ghc -e "$1" || true
else
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.hs
ghc -e main program.hs || true
cd .. && rm -rf "$CODEDIR"
fi

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > Main.java
javac Main.java && java Main || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.lua
lua5.3 program.lua || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.ml
ocamlopt -cclib --static -o program program.ml && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,5 +1,3 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.pas
# fpc does not use stderr, ld however does, capture both
@ -10,5 +8,3 @@ if [ $? -eq 0 ]; then
else
printf %s "$res"
fi
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.pl
perl program.pl || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.php
php program.php || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.pl
swipl --quiet program.pl || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.py
python program.py || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.py
python program.py || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.rkt
racket program.rkt || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.rb
ruby program.rb || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,2 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.rs
rustc -C opt-level=0 --color never program.rs && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -6,6 +6,8 @@ const childProcess = require('child_process');
const util = require('util');
const path = require('path');
const exec = util.promisify(childProcess.exec);
class LanguageHandler extends AkairoHandler {
constructor(client, {
directory,
@ -93,15 +95,16 @@ class LanguageHandler extends AkairoHandler {
const cpus = this.getCompilerConfig(dockerID, 'cpus', 'string');
const memory = this.getCompilerConfig(dockerID, 'memory', 'string');
const name = `comp_iler-${dockerID}-${Date.now()}`;
const proc = childProcess.spawn('docker', [
'run', '--rm', `--name=${name}`, '-u1000', '-w/tmp/', '-dt',
'--net=none', `--cpus=${cpus}`,
`-m=${memory}`, `--memory-swap=${memory}`,
`1computer1/comp_iler:${dockerID}`, '/bin/sh'
]);
try {
await this.handleSpawn(proc);
await exec([
`docker run --rm --name=${name}`,
'-u1000:1000 -w/tmp/ -dt',
`--net=none --cpus=${cpus} -m=${memory} --memory-swap=${memory}`,
`1computer1/comp_iler:${dockerID} /bin/sh`
].join(' '));
await exec(`docker exec ${name} mkdir eval`);
await exec(`docker exec ${name} chmod 711 eval`);
this.containers.set(dockerID, { name });
// eslint-disable-next-line no-console
console.log(`Started container ${name}.`);
@ -116,9 +119,11 @@ class LanguageHandler extends AkairoHandler {
const { evalQueue, setupQueue } = this.queues.get(dockerID);
return evalQueue.enqueue(async () => {
const { name } = await setupQueue.enqueue(() => this.setupContainer(dockerID));
const now = Date.now();
await exec(`docker exec ${name} mkdir eval/${now}`);
await exec(`docker exec ${name} chmod 777 eval/${now}`);
const proc = childProcess.spawn('docker', [
'exec',
`-eCODEDIR=${Date.now()}`,
'exec', '-u1001:1001', `-w/tmp/eval/${now}`,
...Object.entries(env).map(([k, v]) => `-e${k}=${v}`),
name, '/bin/sh', '/var/run/run.sh', code
]);
@ -126,6 +131,7 @@ class LanguageHandler extends AkairoHandler {
const timeout = this.getCompilerConfig(dockerID, 'timeout', 'number');
try {
const result = await this.handleSpawn(proc, timeout);
await exec(`docker exec ${name} rm -rf eval/${now}`);
return result;
} catch (err) {
this.containers.delete(dockerID);
@ -196,7 +202,7 @@ class LanguageHandler extends AkairoHandler {
cmd = `docker kill --signal=9 ${name} >/dev/null 2>/dev/null`;
}
await util.promisify(childProcess.exec)(cmd);
await exec(cmd);
// eslint-disable-next-line no-console
console.log(`Killed container ${name}.`);
}