piston/docker/execute

47 lines
729 B
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
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")
bin=python2
;;
"python" | "python3")
bin=python3
;;
"ruby")
bin=ruby
;;
"javascript" | "js" | "node")
bin=nodejs
;;
*)
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 \
--cpus=".5" \
2018-09-20 04:58:50 +02:00
--rm \
-v $abs:/$file \
2018-09-20 07:49:02 +02:00
piston \
timeout -s HUP 3 $bin /$file 2>&1