From 8fbb90c3c321407ccdf56d761ecea2b2ea394502 Mon Sep 17 00:00:00 2001 From: VibhorCodecianGupta Date: Thu, 2 Aug 2018 20:32:25 +0530 Subject: [PATCH] R support --- README.md | 1 + containers/r/Dockerfile | 9 +++++++++ containers/r/compile.sh | 1 + containers/r/run.sh | 3 +++ test.sh | 10 +++++++--- tests/r/run.stdin | 1 + tests/r/script.r | 2 ++ tests/r/test_worker.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 containers/r/Dockerfile create mode 100644 containers/r/compile.sh create mode 100644 containers/r/run.sh create mode 100644 tests/r/run.stdin create mode 100644 tests/r/script.r create mode 100644 tests/r/test_worker.sh diff --git a/README.md b/README.md index ffff7bc..952edc1 100644 --- a/README.md +++ b/README.md @@ -29,5 +29,6 @@ Currently we have following images - - [perl](containers/perl) - [py2](containers/py2) - [py3](containers/py3) + - [R](containers/r) - [ruby](containers/ruby) - [rust](containers/rust) diff --git a/containers/r/Dockerfile b/containers/r/Dockerfile new file mode 100644 index 0000000..059a839 --- /dev/null +++ b/containers/r/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.6 + +RUN apk add --no-cache R="3.3.3-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/r/compile.sh b/containers/r/compile.sh new file mode 100644 index 0000000..f1f641a --- /dev/null +++ b/containers/r/compile.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/containers/r/run.sh b/containers/r/run.sh new file mode 100644 index 0000000..eabf00a --- /dev/null +++ b/containers/r/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +Rscript script.r < run.stdin 1> run.stdout 2> run.stderr diff --git a/test.sh b/test.sh index 290a453..cd0acb1 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 @@ -40,6 +40,10 @@ bash tests/py3/test_worker.sh } +@test "test R" { + bash tests/R/test_worker.sh +} + @test "test ruby" { bash tests/ruby/test_worker.sh } diff --git a/tests/r/run.stdin b/tests/r/run.stdin new file mode 100644 index 0000000..216e97c --- /dev/null +++ b/tests/r/run.stdin @@ -0,0 +1 @@ +World diff --git a/tests/r/script.r b/tests/r/script.r new file mode 100644 index 0000000..0fa9284 --- /dev/null +++ b/tests/r/script.r @@ -0,0 +1,2 @@ +input <- readLines(file("stdin")) +cat('Hello',input) diff --git a/tests/r/test_worker.sh b/tests/r/test_worker.sh new file mode 100644 index 0000000..ecca601 --- /dev/null +++ b/tests/r/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.r $RUNBOX/script.r +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 r \ + 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