Browse Source

working-ish

pull/533/head
Xavier Petit 5 years ago committed by xpetit
parent
commit
4cd53cebe1
  1. 22
      go/Dockerfile
  2. 48
      go/entrypoint.sh
  3. 4
      go/src/lib/lib.go

22
go/Dockerfile

@ -1,8 +1,20 @@
FROM golang:1-alpine
RUN apk add git
RUN apk add --no-cache git nano
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/rc
COPY . /app
ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"]
WORKDIR src
COPY entrypoint.sh /usr/local/bin
COPY src .
RUN go install rc
RUN find -mindepth 2 -maxdepth 2 -name '*_correct' -type d|xargs go install
RUN find -mindepth 2 -maxdepth 2 -name '*_correct' -type d|cut -d/ -f1-2|xargs go install
RUN find -mindepth 2 -maxdepth 2 -name '*_correct' -type d|cut -d/ -f1-2|xargs rm -rf
WORKDIR /tmp
USER 1000
ENTRYPOINT ["/bin/sh", "/usr/local/bin/entrypoint.sh"]
# compare performance with and without :
# ENV CGO_ENABLED 0
# -trimpath -ldflags="-s -w"
# -i
# -a (to rebuild everything and prepare .a files)
# git clone in Dockerfile to make it work anywhere (no COPY)

48
go/entrypoint.sh

@ -5,30 +5,36 @@ set -o pipefail
IFS='
'
cp -rT /app /jail
mkdir -p src/student
cd src/student
if test "$EXPECTED_FILES"; then
echo -n 'Formatting (with `goimports -d .`) ... '
cd /jail/student
s=$(goimports -d .)
if test "$s"; then
echo
echo "$s"
exit 1
fi
echo OK
if test "$ALLOWED_FUNCTIONS"; then
rc "$EXPECTED_FILES" $ALLOWED_FUNCTIONS
fi
if test "$REPOSITORY"; then
git clone --depth=1 --shallow-submodules "$REPOSITORY" .
fi
cd /jail
if ! test -f ${EXERCISE}_test.go; then
echo No test file found for the exercise : "$EXERCISE"
# Check formatting
s=$(goimports -d .)
if test "$s"; then
echo '$ goimports -d .'
echo "$s"
exit 1
fi
# TODO: maybe change btree exercises so that they work without student code and then delete this line
find . -name '*_test.go' ! -name ${EXERCISE}_test.go -delete
go test -failfast '-run=(?i)'test${EXERCISE}
# Check restrictions
if test "$ALLOWED_FUNCTIONS"; then
for file in $EXPECTED_FILES; do
rc "$file" $ALLOWED_FUNCTIONS
done
fi
# Compile test
cd
GOPATH=$GOPATH:$HOME
if command -v "$EXERCISE"_test &>/dev/null; then
# The exercise is a program
go build "student/$EXERCISE"
"$EXERCISE"_test
else
# The exercise is a function
go run "$EXERCISE"_test
fi

4
go/src/lib/lib.go

@ -362,8 +362,8 @@ func ChallengeMain(exercise string, args ...string) {
code := func(code int) string {
return fmt.Sprintf("echo $?\n%d\n$", code)
}
student, studentCode := run("./student")
solution, solutionCode := run("test_" + exercise)
student, studentCode := run("./" + exercise)
solution, solutionCode := run(exercise + "_correct")
if solutionCode != 0 {
if studentCode == 0 {
Fatalln("Your program does not fail when it should (with a non-zero exit status) :" + "\n" +

Loading…
Cancel
Save