piston/docker/execute

69 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-09-20 04:58:50 +02:00
#!/usr/bin/env bash
2018-09-20 07:49:02 +02:00
#docker run --rm -it piston /usr/bin/python -V
#docker run --rm -it piston /usr/bin/python3 -V
#docker run --rm -it piston /usr/bin/ruby --version
#docker run --rm -it piston /usr/bin/nodejs --version
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
abs=$2
2018-09-20 04:58:50 +02:00
file=$(basename $abs)
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-20 07:49:02 +02:00
*)
echo "invalid language"
exit
esac
2018-09-20 04:58:50 +02:00
docker run \
2018-09-20 07:49:02 +02:00
-m 16m \
2018-09-21 01:12:53 +02:00
--network none \
2018-09-20 07:49:02 +02:00
--cpus=".5" \
2018-09-21 05:17:46 +02:00
--ulimit nproc=8:16 \
2018-09-20 04:58:50 +02:00
--rm \
-v $abs:/$file \
2018-09-20 19:04:34 +02:00
-v $dir/executors/python2:/executor_python2 \
-v $dir/executors/python3:/executor_python3 \
2018-09-21 04:40:48 +02:00
-v $dir/executors/ruby:/executor_ruby \
-v $dir/executors/node:/executor_node \
2018-09-20 19:04:34 +02:00
-v $dir/executors/c:/executor_c \
-v $dir/executors/cpp:/executor_cpp \
2018-09-21 04:40:48 +02:00
-v $dir/executors/go:/executor_go \
2018-09-20 07:49:02 +02:00
piston \
2018-09-20 19:04:34 +02:00
timeout -s HUP 3 /$bin /$file $file 2>&1
2018-09-21 01:22:47 +02:00
rm -f /tmp/$file