From a3de075eafaaea354341b0001872c82aed3cfc51 Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 11 Jul 2018 13:44:42 +0530 Subject: [PATCH 1/4] 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 From 1b8d57da450545b43f6bd6b74c207e3b3f0c7329 Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 11 Jul 2018 14:06:34 +0530 Subject: [PATCH 2/4] Update golang dockerfile --- containers/golang/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/containers/golang/Dockerfile b/containers/golang/Dockerfile index c757399..7acf721 100644 --- a/containers/golang/Dockerfile +++ b/containers/golang/Dockerfile @@ -1,6 +1,6 @@ -FROM frolvlad/alpine-go +FROM alpine:3.6 -RUN apk add --no-cache bash +RUN apk add --no-cache musl-dev bash go="1.8.4-r0" COPY ./compile.sh /bin/compile.sh COPY ./run.sh /bin/run.sh From 09309a8a19abe89da0755dda81d9f7a7eba81f7e Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 11 Jul 2018 14:52:17 +0530 Subject: [PATCH 3/4] Change tmpdir in golang dockerfile --- containers/golang/Dockerfile | 1 + tests/golang/test_worker.sh | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/containers/golang/Dockerfile b/containers/golang/Dockerfile index 7acf721..52f728c 100644 --- a/containers/golang/Dockerfile +++ b/containers/golang/Dockerfile @@ -2,6 +2,7 @@ FROM alpine:3.6 RUN apk add --no-cache musl-dev bash go="1.8.4-r0" +ENV TMPDIR /usr/src/runbox COPY ./compile.sh /bin/compile.sh COPY ./run.sh /bin/run.sh diff --git a/tests/golang/test_worker.sh b/tests/golang/test_worker.sh index 8490860..1aac0de 100755 --- a/tests/golang/test_worker.sh +++ b/tests/golang/test_worker.sh @@ -19,7 +19,6 @@ docker run \ --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" From 5ddbd03e2fe65603766e6a1474ed28170458eb93 Mon Sep 17 00:00:00 2001 From: Kapil Date: Wed, 11 Jul 2018 15:42:09 +0530 Subject: [PATCH 4/4] Update golang run.sh --- containers/golang/run.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/containers/golang/run.sh b/containers/golang/run.sh index a5f7b61..fd66d20 100644 --- a/containers/golang/run.sh +++ b/containers/golang/run.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash -chmod 777 program.go -go run program.go < run.stdin 1> run.stdout 2> run.stderr +go run program.go < run.stdin 1> run.stdout 2> run.stderr \ No newline at end of file