From b1d683699f45c1ab91ae3e936eeafb23b2df8172 Mon Sep 17 00:00:00 2001 From: xpetit <32063953+xpetit@users.noreply.github.com> Date: Thu, 30 Jul 2020 13:51:21 +0200 Subject: [PATCH] Add Go exam image (run with arguments) --- go/exam/Dockerfile | 11 +++++++++++ go/exam/entrypoint.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 go/exam/Dockerfile create mode 100755 go/exam/entrypoint.sh diff --git a/go/exam/Dockerfile b/go/exam/Dockerfile new file mode 100644 index 000000000..f68e02b89 --- /dev/null +++ b/go/exam/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1-alpine + +ENV GIT_TERMINAL_PROMPT=0 +RUN apk add --no-cache git +RUN go get golang.org/x/tools/cmd/goimports +RUN go get github.com/01-edu/z01 +RUN go get github.com/01-edu/public/go/tests/rc +COPY --from=mkcert-ca . /usr/local/share/ca-certificates +RUN update-ca-certificates +COPY entrypoint.sh /usr/local/bin +ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"] diff --git a/go/exam/entrypoint.sh b/go/exam/entrypoint.sh new file mode 100755 index 000000000..562ffb12e --- /dev/null +++ b/go/exam/entrypoint.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -o noglob +set -o errexit +set -o nounset +IFS=' +' + +mkdir -p src/student +cd src/student + +first_file=$(echo "$EXPECTED_FILES" | cut -d' ' -f1) +mkdir -p "$(dirname "$first_file")" +cat > "$first_file" + +# Format code +goimports -w . + +# Check restrictions +if test "$ALLOWED_FUNCTIONS" && test "$EXPECTED_FILES"; then + IFS=' ' + # shellcheck disable=SC2086 + rc "$first_file" $ALLOWED_FUNCTIONS + IFS=' +' +fi + +cd + +# Run program +go build "./src/student/$EXERCISE" +./"${EXERCISE}" "$@"