eval: limit docker output to not run out of memory

This commit is contained in:
1computer1 2020-06-07 03:43:41 -04:00
parent c57a563ea3
commit 1996ab90ca
27 changed files with 29 additions and 28 deletions

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.apl
cat > program.apl
apl --OFF -s -f program.apl || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.sh
cat > program.sh
bash program.sh || true

View File

@ -1 +1 @@
printf %s "$1" | bf || true
cat | bf || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.c
cat > program.c
gcc program.c -o program && ./program || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.clj
cat > program.clj
clojure program.clj || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.cpp
cat > program.cpp
g++ program.cpp -o program && ./program || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.cs
cat > program.cs
csc program.cs >/dev/null && mono program.exe || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.exs
cat > program.exs
elixir program.exs || true

View File

@ -1,3 +1,3 @@
echo "%% -*- erlang -*-" > program.erl
printf %s "$1" >> program.erl
cat >> program.erl
escript program.erl || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.fs
cat > program.fs
fsharpc --optimize- program.fs >/dev/null && mono program.exe || true

View File

@ -1,3 +1,3 @@
export GOCACHE=/tmp/"$CODEDIR"/cache
printf %s "$1" > program.go
cat > program.go
go run program.go || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.hs
cat > program.hs
ghc -e main program.hs || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > Main.idr
cat > Main.idr
idris --execute ./Main.idr || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > Main.java
cat > Main.java
javac Main.java && java Main || true

View File

@ -1 +1 @@
printf %s "$1" | node -p || true
cat | node -p || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.jl
cat > program.jl
julia program.jl || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.lua
cat > program.lua
lua5.3 program.lua || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.ml
cat > program.ml
ocamlopt -cclib --static -o program program.ml && ./program || true

View File

@ -1,4 +1,4 @@
printf %s "$1" > program.pas
cat > program.pas
# fpc does not use stderr, ld however does, capture both
res="$(fpc program.pas 2>&1)"

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.pl
cat > program.pl
perl program.pl || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.php
cat > program.php
php program.php || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.pl
cat > program.pl
swipl --quiet program.pl || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.py
cat > program.py
python program.py || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.rkt
cat > program.rkt
racket program.rkt || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.rb
cat > program.rb
ruby program.rb || true

View File

@ -1,2 +1,2 @@
printf %s "$1" > program.rs
cat > program.rs
rustc -C opt-level=0 --color never program.rs && ./program || true

View File

@ -179,8 +179,9 @@ evalCode lang@LanguageConfig { name, timeout, retries } numRetries code = withCo
exec_ ["docker exec ", cs cnt, " mkdir eval/", show snowflake]
exec_ ["docker exec ", cs cnt, " chmod 777 eval/", show snowflake]
-- User 1001 will be used for the actual execution so that they can't access `eval` itself
let args = ["exec", "-u1001:1001", "-w/tmp/eval/" <> show snowflake, cnt, "/bin/sh", "/var/run/run.sh", code]
output <- readProcessInterleaved_ $ proc "docker" args
let cmd = concat ["docker exec -i -u1001:1001 -w/tmp/eval/", show snowflake, " ", cnt, " /bin/sh /var/run/run.sh | head -c 4K"]
pr = setStdin (byteStringInput $ cs code) $ shell cmd
output <- readProcessInterleaved_ pr
exec_ ["docker exec ", cnt, " rm -rf eval/", show snowflake]
logInfo ["Ran code in container ", cs cnt, ", evaluation ", cs $ show snowflake]
pure $ EvalOk output