From a3de075eafaaea354341b0001872c82aed3cfc51 Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 11 Jul 2018 13:44:42 +0530 Subject: [PATCH] Add support for golang --- README.md | 1 + containers/golang/Dockerfile | 9 +++++++++ containers/golang/compile.sh | 1 + containers/golang/run.sh | 4 ++++ test.sh | 4 ++++ tests/golang/program.go | 9 +++++++++ tests/golang/run.stdin | 1 + tests/golang/test_worker.sh | 38 ++++++++++++++++++++++++++++++++++++ 8 files changed, 67 insertions(+) create mode 100644 containers/golang/Dockerfile create mode 100755 containers/golang/compile.sh create mode 100644 containers/golang/run.sh create mode 100644 tests/golang/program.go create mode 100644 tests/golang/run.stdin create mode 100755 tests/golang/test_worker.sh diff --git a/README.md b/README.md index afe6533..cfdda76 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Currently we have following images - - [c](containers/c) - [cpp](containers/cpp) - [c#](containers/csharp) + - [golang](containers/golang) - [java8](containers/java8) - [nodejs6](containers/nodejs6) - [nodejs](containers/nodejs8) diff --git a/containers/golang/Dockerfile b/containers/golang/Dockerfile new file mode 100644 index 0000000..c757399 --- /dev/null +++ b/containers/golang/Dockerfile @@ -0,0 +1,9 @@ +FROM frolvlad/alpine-go + +RUN apk add --no-cache 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/golang/compile.sh b/containers/golang/compile.sh new file mode 100755 index 0000000..212c4ba --- /dev/null +++ b/containers/golang/compile.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash \ No newline at end of file diff --git a/containers/golang/run.sh b/containers/golang/run.sh new file mode 100644 index 0000000..a5f7b61 --- /dev/null +++ b/containers/golang/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +chmod 777 program.go +go run program.go < run.stdin 1> run.stdout 2> run.stderr diff --git a/test.sh b/test.sh index 4592172..1260f87 100755 --- a/test.sh +++ b/test.sh @@ -12,6 +12,10 @@ bash tests/csharp/test_worker.sh } +@test "test golang" { + bash tests/golang/test_worker.sh +} + @test "test java8" { bash tests/java8/test_worker.sh } diff --git a/tests/golang/program.go b/tests/golang/program.go new file mode 100644 index 0000000..42b9ff4 --- /dev/null +++ b/tests/golang/program.go @@ -0,0 +1,9 @@ +package main; + +import "fmt"; + +func main() { + var input string + fmt.Scanf("%s", &input) + fmt.Println("Hello " + input) +} \ No newline at end of file diff --git a/tests/golang/run.stdin b/tests/golang/run.stdin new file mode 100644 index 0000000..beef906 --- /dev/null +++ b/tests/golang/run.stdin @@ -0,0 +1 @@ +World \ No newline at end of file diff --git a/tests/golang/test_worker.sh b/tests/golang/test_worker.sh new file mode 100755 index 0000000..8490860 --- /dev/null +++ b/tests/golang/test_worker.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +pushd $(dirname "$0") +DIR=$(pwd) +RUNBOX="${DIR}/runbox" + +echo $RUNBOX +# Create runbox +mkdir -p $RUNBOX + +# Copy source to runbox +cp $DIR/program.go $RUNBOX/program.go +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-golang \ + 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