From 309706765ca405c938305d274df081505923f666 Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Fri, 27 Jul 2018 00:43:11 +0530 Subject: [PATCH 1/4] php support --- containers/php7/Dockerfile | 9 +++++++++ containers/php7/compile.sh | 1 + containers/php7/run.sh | 3 +++ test.sh | 10 +++++++--- tests/php7/run.stdin | 1 + tests/php7/script.php | 6 ++++++ tests/php7/test_worker.sh | 41 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 containers/php7/Dockerfile create mode 100644 containers/php7/compile.sh create mode 100644 containers/php7/run.sh create mode 100644 tests/php7/run.stdin create mode 100644 tests/php7/script.php create mode 100644 tests/php7/test_worker.sh diff --git a/containers/php7/Dockerfile b/containers/php7/Dockerfile new file mode 100644 index 0000000..d0f81de --- /dev/null +++ b/containers/php7/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.6 + +RUN apk add --no-cache musl-dev php7="7.1.17-r0" bash + +COPY ./compile.sh /bin/compile.sh +COPY ./run.sh /bin/run.sh + +RUN chmod 777 /bin/compile.sh; \ + chmod 777 /bin/run.sh diff --git a/containers/php7/compile.sh b/containers/php7/compile.sh new file mode 100644 index 0000000..f1f641a --- /dev/null +++ b/containers/php7/compile.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/containers/php7/run.sh b/containers/php7/run.sh new file mode 100644 index 0000000..6f8228a --- /dev/null +++ b/containers/php7/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +php script.php < run.stdin 1> run.stdout 2> run.stderr diff --git a/test.sh b/test.sh index 32ff951..10dbb18 100755 --- a/test.sh +++ b/test.sh @@ -4,9 +4,9 @@ bash tests/c/test_worker.sh } -#@test "test cpp" { -# bash tests/cpp/test_worker.sh -#} +@test "test cpp" { + bash tests/cpp/test_worker.sh +} @test "test csharp" { bash tests/csharp/test_worker.sh @@ -28,6 +28,10 @@ bash tests/nodejs8/test_worker.sh } +@test "test php7" { + bash tests/php7/test_worker.sh +} + @test "test py2" { bash tests/py2/test_worker.sh } diff --git a/tests/php7/run.stdin b/tests/php7/run.stdin new file mode 100644 index 0000000..216e97c --- /dev/null +++ b/tests/php7/run.stdin @@ -0,0 +1 @@ +World diff --git a/tests/php7/script.php b/tests/php7/script.php new file mode 100644 index 0000000..03f6068 --- /dev/null +++ b/tests/php7/script.php @@ -0,0 +1,6 @@ + diff --git a/tests/php7/test_worker.sh b/tests/php7/test_worker.sh new file mode 100644 index 0000000..fb27e66 --- /dev/null +++ b/tests/php7/test_worker.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +pushd $(dirname "$0") +DIR=$(pwd) +RUNBOX="${DIR}/runbox" + +echo $RUNBOX +# Remove RUNBOX +rm -rf $RUNBOX + +# Create runbox +mkdir -p $RUNBOX + +# Copy source to runbox +cp -fv $DIR/script.php $RUNBOX/script.php +cp -fv $DIR/run.stdin $RUNBOX/run.stdin + +# Test Compile +docker run \ + --cpus="1" \ + --memory="100m" \ + --ulimit nofile=64:64 \ + --rm \ + --read-only \ + -v "$RUNBOX":/usr/src/runbox \ + -v "$RUNBOX":/tmp \ + -w /usr/src/runbox codingblocks/judge-worker-php7 \ + bash -c "/bin/compile.sh && /bin/run.sh" + +ls -lh ${RUNBOX} + +expected="Hello World" +actual="$(cat ${RUNBOX}/run.stdout)" +if [ "$expected" == "$actual" ] ;then + : +else + echo "MISMATCH: Expected = $expected; Actual = $actual" + exit 1 +fi + +# Delete runbox +rm -rf $RUNBOX From e6afaeb322505b18d8496f2341d325e517de13bf Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Fri, 27 Jul 2018 00:50:19 +0530 Subject: [PATCH 2/4] memory usage --- tests/php7/test_worker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/php7/test_worker.sh b/tests/php7/test_worker.sh index fb27e66..26ea292 100644 --- a/tests/php7/test_worker.sh +++ b/tests/php7/test_worker.sh @@ -16,8 +16,8 @@ cp -fv $DIR/run.stdin $RUNBOX/run.stdin # Test Compile docker run \ - --cpus="1" \ - --memory="100m" \ + --cpus="0.5" \ + --memory="20m" \ --ulimit nofile=64:64 \ --rm \ --read-only \ From 8286ae7df01352af278b3ec4d9beba2425c2d2b6 Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Fri, 27 Jul 2018 00:55:11 +0530 Subject: [PATCH 3/4] updated readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 434e2ca..61d6af0 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Currently we have following images - - [java8](containers/java8) - [nodejs6](containers/nodejs6) - [nodejs](containers/nodejs8) + - [php7](containers/php7) - [py2](containers/py2) - [py3](containers/py3) - [ruby](containers/ruby) From 4aa581342f9452c0658707f8f3639f428d508d43 Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Thu, 2 Aug 2018 12:43:40 +0530 Subject: [PATCH 4/4] tests passing --- README.md | 2 ++ containers/perl/Dockerfile | 9 +++++++++ containers/perl/compile.sh | 1 + containers/perl/run.sh | 3 +++ containers/rust/Dockerfile | 9 +++++++++ containers/rust/compile.sh | 3 +++ containers/rust/run.sh | 4 ++++ test.sh | 4 ++++ tests/perl/run.stdin | 1 + tests/perl/script.pl | 2 ++ tests/perl/test_worker.sh | 41 ++++++++++++++++++++++++++++++++++++++ tests/rust/run.stdin | 1 + tests/rust/script.rs | 11 ++++++++++ tests/rust/test_worker.sh | 41 ++++++++++++++++++++++++++++++++++++++ 14 files changed, 132 insertions(+) create mode 100644 containers/perl/Dockerfile create mode 100644 containers/perl/compile.sh create mode 100644 containers/perl/run.sh create mode 100644 containers/rust/Dockerfile create mode 100644 containers/rust/compile.sh create mode 100644 containers/rust/run.sh create mode 100644 tests/perl/run.stdin create mode 100644 tests/perl/script.pl create mode 100644 tests/perl/test_worker.sh create mode 100644 tests/rust/run.stdin create mode 100644 tests/rust/script.rs create mode 100644 tests/rust/test_worker.sh diff --git a/README.md b/README.md index 61d6af0..3ab3aaf 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,9 @@ Currently we have following images - - [java8](containers/java8) - [nodejs6](containers/nodejs6) - [nodejs](containers/nodejs8) + - [perl](containers/perl) - [php7](containers/php7) - [py2](containers/py2) - [py3](containers/py3) - [ruby](containers/ruby) + - [rust](containers/rust) diff --git a/containers/perl/Dockerfile b/containers/perl/Dockerfile new file mode 100644 index 0000000..e374a28 --- /dev/null +++ b/containers/perl/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.6 + +RUN apk add --no-cache perl="5.24.4-r0" bash + +COPY ./compile.sh /bin/compile.sh +COPY ./run.sh /bin/run.sh + +RUN chmod 777 /bin/compile.sh; \ + chmod 777 /bin/run.sh diff --git a/containers/perl/compile.sh b/containers/perl/compile.sh new file mode 100644 index 0000000..f1f641a --- /dev/null +++ b/containers/perl/compile.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/containers/perl/run.sh b/containers/perl/run.sh new file mode 100644 index 0000000..7045523 --- /dev/null +++ b/containers/perl/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +perl script.pl < run.stdin 1> run.stdout 2> run.stderr diff --git a/containers/rust/Dockerfile b/containers/rust/Dockerfile new file mode 100644 index 0000000..3022f43 --- /dev/null +++ b/containers/rust/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.6 + +RUN apk add --no-cache musl-dev bash rust="1.17.0-r2" + +COPY ./compile.sh /bin/compile.sh +COPY ./run.sh /bin/run.sh + +RUN chmod 777 /bin/compile.sh; \ + chmod 777 /bin/run.sh diff --git a/containers/rust/compile.sh b/containers/rust/compile.sh new file mode 100644 index 0000000..035348e --- /dev/null +++ b/containers/rust/compile.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +rustc script.rs 2> compile.stderr 1> compile.stdout diff --git a/containers/rust/run.sh b/containers/rust/run.sh new file mode 100644 index 0000000..7878268 --- /dev/null +++ b/containers/rust/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +chmod 777 script.rs +./script < run.stdin 1> run.stdout 2> run.stderr diff --git a/test.sh b/test.sh index 10dbb18..5eff80c 100755 --- a/test.sh +++ b/test.sh @@ -43,3 +43,7 @@ @test "test ruby" { bash tests/ruby/test_worker.sh } + +@test "test rust" { + bash tests/rust/test_worker.sh +} diff --git a/tests/perl/run.stdin b/tests/perl/run.stdin new file mode 100644 index 0000000..216e97c --- /dev/null +++ b/tests/perl/run.stdin @@ -0,0 +1 @@ +World diff --git a/tests/perl/script.pl b/tests/perl/script.pl new file mode 100644 index 0000000..c735b06 --- /dev/null +++ b/tests/perl/script.pl @@ -0,0 +1,2 @@ +$input = ; +print "Hello ${input}"; diff --git a/tests/perl/test_worker.sh b/tests/perl/test_worker.sh new file mode 100644 index 0000000..6e254c2 --- /dev/null +++ b/tests/perl/test_worker.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +pushd $(dirname "$0") +DIR=$(pwd) +RUNBOX="${DIR}/runbox" + +echo $RUNBOX +# Remove RUNBOX +rm -rf $RUNBOX + +# Create runbox +mkdir -p $RUNBOX + +# Copy source to runbox +cp -fv $DIR/script.pl $RUNBOX/script.pl +cp -fv $DIR/run.stdin $RUNBOX/run.stdin + +# Test Compile +docker run \ + --cpus="0.5" \ + --memory="20m" \ + --ulimit nofile=64:64 \ + --rm \ + --read-only \ + -v "$RUNBOX":/usr/src/runbox \ + -v "$RUNBOX":/tmp \ + -w /usr/src/runbox codingblocks/judge-worker-perl \ + bash -c "/bin/compile.sh && /bin/run.sh" + +ls -lh ${RUNBOX} + +expected="Hello World" +actual="$(cat ${RUNBOX}/run.stdout)" +if [ "$expected" == "$actual" ] ;then + : +else + echo "MISMATCH: Expected = $expected; Actual = $actual" + exit 1 +fi + +# Delete runbox +rm -rf $RUNBOX diff --git a/tests/rust/run.stdin b/tests/rust/run.stdin new file mode 100644 index 0000000..216e97c --- /dev/null +++ b/tests/rust/run.stdin @@ -0,0 +1 @@ +World diff --git a/tests/rust/script.rs b/tests/rust/script.rs new file mode 100644 index 0000000..c56b158 --- /dev/null +++ b/tests/rust/script.rs @@ -0,0 +1,11 @@ +use std::io; + +fn main() { + let mut input = String::new(); + + io::stdin().read_line(&mut input) + .ok() + .expect("Couldn't read line"); + + println!("Hello {}", input); +} diff --git a/tests/rust/test_worker.sh b/tests/rust/test_worker.sh new file mode 100644 index 0000000..78904fe --- /dev/null +++ b/tests/rust/test_worker.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +pushd $(dirname "$0") +DIR=$(pwd) +RUNBOX="${DIR}/runbox" + +echo $RUNBOX +# Remove RUNBOX +rm -rf $RUNBOX + +# Create runbox +mkdir -p $RUNBOX + +# Copy source to runbox +cp $DIR/script.rs $RUNBOX/script.rs +cp $DIR/run.stdin $RUNBOX/run.stdin + +# Test Compile +docker run \ + --cpus="1" \ + --memory="100m" \ + --ulimit nofile=64:64 \ + --rm \ + --read-only \ + -v "$RUNBOX":/usr/src/runbox \ + -v "$RUNBOX":/tmp \ + -w /usr/src/runbox codingblocks/judge-worker-rust \ + bash -c "/bin/compile.sh && /bin/run.sh" + +ls -lh ${RUNBOX} + +expected="Hello World" +actual="$(cat ${RUNBOX}/run.stdout)" +if [ "$expected" == "$actual" ] ;then + : +else + echo "MISMATCH: Expected = $expected; Actual = $actual" + exit 1 +fi + +# Delete runbox +rm -rf $RUNBOX