Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22.5
FROM golang:1.24
LABEL ru.senjun.image.authors="Shipilov Dmitry"

WORKDIR /home/code_runner
Expand All @@ -11,6 +11,10 @@ COPY task/run-task.sh /home/code_runner/task
RUN mkdir /home/code_runner/playground
COPY playground/run-playground.sh /home/code_runner/playground

# Directory for practice
RUN mkdir /home/code_runner/practice
COPY practice/run-practice.sh /home/code_runner/practice

RUN mkdir -p task/user-code && cd task/user-code && go mod init senjun/user/user-code

# Change access write for code_runner home directory to root recursively
Expand Down
64 changes: 64 additions & 0 deletions golang/practice/run-practice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

# parse flags - single letters prefixed with hyphen before each argument
# example: sh run.sh -f task
# column after option means required argument
while getopts f:p:o:rt opt
do
case "${opt}" in
f) project=${OPTARG}
;;
o) user_options="${OPTARG}"
;;
p) main_path=${OPTARG}
;;
r) run=${OPTARG}
;;
t) test=${OPTARG}
;;
\?) echo "Invalid option" >&2
exit
;;
esac
done

# prepare project
f="$(basename -- $project)"
cd /home/code_runner/practice/$f/cmd

# we call gofmt to prevent compiler errors:
# go compiler treats formatting errors as compilation errors!

# TODO: format go code in online IDE to show user the right way
# timeout 5s gofmt -s -w .

if [ ${run+x} ]; then
# run cpp project
# TODO which name for project should use here?

if ! ( timeout 10s go run . ); then
echo "Code execution timeout"
echo user_solution_error_f936a25e
exit
fi

echo user_code_ok_f936a25e
echo user_solution_ok_f936a25e
exit
fi

# e.g: sh run.sh -f dir_name -t
if [ ${test+x} ]; then
echo user_code_ok_f936a25e
if ! ( timeout 10s go test . ); then
echo "Tests execution timeout"
echo tests_cases_error_f936a25e
exit
fi

echo user_solution_ok_f936a25e
exit
fi

# Never goes here
echo "Never should go here!"