piston/docker/execute

95 lines
1.8 KiB
Plaintext
Raw Normal View History

2018-09-20 04:58:50 +02:00
#!/usr/bin/env bash
2018-09-20 19:04:34 +02:00
dir="$( cd "$( dirname "$0" )" && pwd )"
2018-09-20 07:49:02 +02:00
if [ -z "$1" ]; then
echo "invalid args"
exit
fi
if [ -z "$2" ]; then
echo "invalid args"
exit
fi
lang=$1
2018-09-21 20:45:09 +02:00
filepath=$(realpath $2)
file=$(basename $2)
2018-10-06 18:48:10 +02:00
argpath="/tmp/$(date +%s%N).args"
arg=$(basename $argpath)
2018-10-08 00:54:29 +02:00
socket=${SOCKET:-unix:///var/run/docker.sock}
2018-10-06 18:48:10 +02:00
# write arg file
echo "${@:3}" > $argpath
2018-09-20 04:58:50 +02:00
2018-09-20 07:49:02 +02:00
bin=
case "$lang" in
"python2")
2018-09-20 19:04:34 +02:00
bin=executor_python2
2018-09-20 07:49:02 +02:00
;;
"python" | "python3")
2018-09-20 19:04:34 +02:00
bin=executor_python3
2018-09-20 07:49:02 +02:00
;;
"ruby")
2018-09-21 04:36:21 +02:00
bin=executor_ruby
2018-09-20 07:49:02 +02:00
;;
"javascript" | "js" | "node")
2018-09-21 04:36:21 +02:00
bin=executor_node
2018-09-20 07:49:02 +02:00
;;
2018-09-20 19:04:34 +02:00
"c")
bin=executor_c
;;
"cpp" | "c++")
bin=executor_cpp
;;
2018-09-21 04:36:21 +02:00
"go")
bin=executor_go
;;
2018-09-22 08:11:53 +02:00
"c#" | "csharp" | "cs")
bin=executor_csharp
;;
"r")
bin=executor_r
;;
"php")
bin=executor_php
;;
2018-09-28 22:24:24 +02:00
"nasm" | "asm")
bin=executor_nasm
;;
2018-10-06 04:11:12 +02:00
"java")
bin=executor_java
;;
2018-09-20 07:49:02 +02:00
*)
echo "invalid language"
exit
esac
2018-10-08 00:54:29 +02:00
docker \
-H $socket \
run \
2018-09-21 05:31:40 +02:00
-m 64m \
2018-09-21 01:12:53 +02:00
--network none \
2018-09-20 04:58:50 +02:00
--rm \
2018-09-22 05:00:01 +02:00
--log-driver none \
2018-09-22 08:41:35 +02:00
-v $filepath:/$file:ro \
2018-10-06 18:48:10 +02:00
-v $argpath:/$arg:ro \
2018-09-21 05:45:40 +02:00
-v $dir/executors/python2:/executor_python2:ro \
-v $dir/executors/python3:/executor_python3:ro \
-v $dir/executors/ruby:/executor_ruby:ro \
-v $dir/executors/node:/executor_node:ro \
-v $dir/executors/c:/executor_c:ro \
-v $dir/executors/cpp:/executor_cpp:ro \
-v $dir/executors/go:/executor_go:ro \
2018-09-22 08:11:53 +02:00
-v $dir/executors/csharp:/executor_csharp:ro \
-v $dir/executors/r:/executor_r:ro \
-v $dir/executors/php:/executor_php:ro \
2018-09-28 22:24:24 +02:00
-v $dir/executors/nasm:/executor_nasm:ro \
2018-10-06 04:11:12 +02:00
-v $dir/executors/java:/executor_java:ro \
2018-09-20 07:49:02 +02:00
piston \
2018-09-21 20:45:09 +02:00
runuser \
-l runner \
2018-10-06 18:48:10 +02:00
-c "bash /$bin /$file $file 2>&1 | head -c 65536"
2018-09-21 01:22:47 +02:00
rm -f /tmp/$file
2018-10-06 18:48:10 +02:00
rm -f /tmp/$arg