added a version of piston which uses lxc instead of docker, added tests for lxc
This commit is contained in:
parent
748f438718
commit
b26d1b5b45
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
dir="$( cd "$( dirname "$0" )" && pwd )"
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "invalid args"
|
||||
exit
|
||||
fi
|
||||
if [ -z "$2" ]; then
|
||||
echo "invalid args"
|
||||
exit
|
||||
fi
|
||||
|
||||
lang=$1
|
||||
epoch=$(date +%s%3N)
|
||||
basepath="/var/lib/lxc/piston/rootfs"
|
||||
filepath="/tmp/$epoch/code.code"
|
||||
file=$(basename $2)
|
||||
argpath="/tmp/$epoch/args.args"
|
||||
arg=$(basename $argpath)
|
||||
|
||||
# write arg file
|
||||
mkdir -p $basepath/tmp/$epoch
|
||||
chmod 777 $basepath/tmp/$epoch
|
||||
cat $file > $basepath$filepath
|
||||
echo "${@:3}" > $basepath$argpath
|
||||
|
||||
bin=
|
||||
case "$lang" in
|
||||
"python2")
|
||||
bin=python2
|
||||
;;
|
||||
"python" | "python3")
|
||||
bin=python3
|
||||
;;
|
||||
"ruby")
|
||||
bin=ruby
|
||||
;;
|
||||
"javascript" | "js" | "node")
|
||||
bin=node
|
||||
;;
|
||||
"c")
|
||||
bin=c
|
||||
;;
|
||||
"cpp" | "c++")
|
||||
bin=cpp
|
||||
;;
|
||||
"go")
|
||||
bin=go
|
||||
;;
|
||||
"c#" | "csharp" | "cs")
|
||||
bin=csharp
|
||||
;;
|
||||
"r")
|
||||
bin=r
|
||||
;;
|
||||
"php")
|
||||
bin=php
|
||||
;;
|
||||
"nasm" | "asm")
|
||||
bin=nasm
|
||||
;;
|
||||
"java")
|
||||
bin=java
|
||||
;;
|
||||
*)
|
||||
echo "invalid language"
|
||||
exit
|
||||
esac
|
||||
|
||||
lxc-attach -n piston -- \
|
||||
/bin/su ubuntu \
|
||||
-c "bash /home/ubuntu/$bin $epoch 2>&1 | head -c 65536"
|
||||
|
||||
#rm -f $basepath$filepath
|
||||
#rm -f $basepath$argpath
|
|
@ -0,0 +1,3 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 10 gcc -o binary -x c code.code
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' ./binary"
|
|
@ -0,0 +1,3 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 10 g++ -o binary -x c++ code.code
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' ./binary"
|
|
@ -0,0 +1,3 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 10 mcs $(echo code.code | sed 's/\///') -out:binary
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' mono binary"
|
|
@ -0,0 +1,6 @@
|
|||
cd /tmp/$1
|
||||
cp code.code interim.go
|
||||
file="interim.go"
|
||||
GOROOT=/usr/lib/go timeout -s KILL 10 go build $file
|
||||
file=${file%%.*}
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' ./$file"
|
|
@ -0,0 +1,6 @@
|
|||
cd /tmp/$1
|
||||
cp code.code interim.java
|
||||
name=$(cat interim.java | grep -Eo 'public\s+class\s+([A-Za-z0-9]+)' | sed -n 's/ */ /gp' | cut -d' ' -f3)
|
||||
mv interim.java $name.java
|
||||
timeout -s KILL 10 javac $name.java
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' java $name"
|
|
@ -0,0 +1,4 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 10 nasm -f elf64 -o binary.o code.code
|
||||
timeout -s KILL 10 ld binary.o -o binary
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' ./binary"
|
|
@ -0,0 +1,2 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' nodejs code.code"
|
|
@ -0,0 +1,2 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' php code.code"
|
|
@ -0,0 +1,2 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' python2 code.code"
|
|
@ -0,0 +1,2 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' python3.6 code.code"
|
|
@ -0,0 +1,2 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' Rscript code.code"
|
|
@ -0,0 +1,2 @@
|
|||
cd /tmp/$1
|
||||
timeout -s KILL 3 bash -c "cat args.args | xargs -d '\n' ruby code.code"
|
|
@ -0,0 +1,26 @@
|
|||
# install
|
||||
yum install lxc lxc-template debootstrap
|
||||
|
||||
# create container
|
||||
lxc-create -t download -n piston
|
||||
select ubuntu, bionic, amd64
|
||||
|
||||
# start container
|
||||
lxc-start -n piston -d
|
||||
|
||||
# shell in and install stuff
|
||||
lxc-attach -n piston
|
||||
export PATH=/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
|
||||
sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu/http:\/\/mirror.math.princeton.edu\/pub\/ubuntu/' /etc/apt/sources.list
|
||||
apt-get update
|
||||
apt-get -y install tzdata nano dpkg-dev build-essential python python3 ruby nodejs golang php7.2 r-base mono-complete nasm openjdk-8-jdk
|
||||
|
||||
# apply limits
|
||||
echo 'ubuntu soft nproc 128' >> /etc/security/limits.conf
|
||||
echo 'ubuntu hard nproc 128' >> /etc/security/limits.conf
|
||||
echo 'ubuntu soft nofile 1024' >> /etc/security/limits.conf
|
||||
echo 'ubuntu hard nofile 1024' >> /etc/security/limits.conf
|
||||
echo 'runner soft nproc 16' >> /etc/security/limits.conf
|
||||
echo 'runner hard nproc 16' >> /etc/security/limits.conf
|
||||
echo 'runner soft nofile 512' >> /etc/security/limits.conf
|
||||
echo 'runner hard nofile 512' >> /etc/security/limits.conf
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
rm -f /var/lib/lxc/piston/rootfs/home/ubuntu/*
|
||||
cp -f executors/* /var/lib/lxc/piston/rootfs/home/ubuntu
|
||||
|
||||
lxc-start -n piston -d
|
|
@ -0,0 +1,5 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void main(void) {
|
||||
printf("good\n");
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include <iostream>
|
||||
|
||||
int main(void) {
|
||||
printf("good\n");
|
||||
return 1;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace HelloWorld {
|
||||
class Hello {
|
||||
static void Main() {
|
||||
Console.WriteLine("good");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("good")
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("good");
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
console.log('good')
|
|
@ -0,0 +1,16 @@
|
|||
SECTION .DATA
|
||||
good: db 'good',10
|
||||
txtlen: equ $-good
|
||||
|
||||
SECTION .TEXT
|
||||
GLOBAL _start
|
||||
|
||||
_start:
|
||||
mov eax,4
|
||||
mov ebx,1
|
||||
mov ecx,good
|
||||
mov edx,txtlen
|
||||
int 80h
|
||||
mov eax,1
|
||||
mov ebx,0
|
||||
int 80h
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
echo 'good' . "\n";
|
|
@ -0,0 +1 @@
|
|||
print('good')
|
|
@ -0,0 +1 @@
|
|||
puts 'good'
|
|
@ -0,0 +1 @@
|
|||
print 'good'
|
|
@ -0,0 +1 @@
|
|||
print('good')
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo 'testing c'
|
||||
../lxc/execute c test.c
|
||||
echo 'testing cpp'
|
||||
../lxc/execute cpp test.cpp
|
||||
echo 'testing cs'
|
||||
../lxc/execute cs test.cs
|
||||
echo 'testing go'
|
||||
../lxc/execute go test.go
|
||||
echo 'testing java'
|
||||
../lxc/execute java test.java
|
||||
echo 'testing asm'
|
||||
../lxc/execute asm test.nasm
|
||||
echo 'testing js'
|
||||
../lxc/execute js test.js
|
||||
echo 'testing php'
|
||||
../lxc/execute php test.php
|
||||
echo 'testing python2'
|
||||
../lxc/execute python2 test2.py
|
||||
echo 'testing python3'
|
||||
../lxc/execute python3 test3.py
|
||||
echo 'testing r'
|
||||
../lxc/execute r test.r
|
||||
echo 'testing ruby'
|
||||
../lxc/execute ruby test.rb
|
Loading…
Reference in New Issue