From 6e21aa3b8aea77526e83c42d4053bee631329b12 Mon Sep 17 00:00:00 2001 From: Gurkengewuerz Date: Mon, 4 Nov 2024 20:04:52 +0100 Subject: [PATCH] fix: fixed build errors on unix --- docker/compose.yml | 4 ++++ docker/judge/entrypoint.sh | 8 ++++++++ internal/judge/docker.go | 34 +++++++++++++++++----------------- internal/judge/pool.go | 2 +- internal/models/submission.go | 1 - 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/docker/compose.yml b/docker/compose.yml index 0f3a02b..54a9723 100644 --- a/docker/compose.yml +++ b/docker/compose.yml @@ -3,6 +3,7 @@ services: image: ghcr.io/gurkengewuerz/gitcodejudge-server:latest restart: unless-stopped networks: [traefik] + volumes: - ${CONTAINER_DIR}/judge/tests:/test_cases - ${CONTAINER_DIR}/judge/db:/db @@ -18,6 +19,9 @@ services: - DB_PATH=/db - PDF_FOOTER_COPYRIGHT=Copyright by Gurkengewuerz - LEADERBOARD_ENABLED=true + - OAUTH2_ISSUER=${OAUTH2_ISSUER:-} + - OAUTH2_CLIENT_ID=${OAUTH2_CLIENT_ID:-} + - OAUTH2_SECRET=${OAUTH2_SECRET:-} labels: - "traefik.enable=true" - "traefik.docker.network=traefik" diff --git a/docker/judge/entrypoint.sh b/docker/judge/entrypoint.sh index bee8d0e..982e25c 100644 --- a/docker/judge/entrypoint.sh +++ b/docker/judge/entrypoint.sh @@ -1,6 +1,13 @@ #!/usr/bin/env ash set -e +trim() { + local s2 s="$*" + until s2="${s#[[:space:]]}"; [ "$s2" = "$s" ]; do s="$s2"; done + until s2="${s%[[:space:]]}"; [ "$s2" = "$s" ]; do s="$s2"; done + echo "$s" +} + # Check if required environment variables are set if [ -z "$JUDGE_WORKSHOP" ] || [ -z "$JUDGE_TASK" ]; then >&2 echo "Error: JUDGE_WORKSHOP and JUDGE_TASK environment variables must be set" @@ -9,6 +16,7 @@ fi # Define the solutions directory SOLUTIONS_DIR="/repo/${JUDGE_WORKSHOP}/${JUDGE_TASK}" +SOLUTIONS_DIR=$(trim "$SOLUTIONS_DIR") INPUT_FILE="/judge/input.txt" # Check if solutions directory exists diff --git a/internal/judge/docker.go b/internal/judge/docker.go index b96b1d1..b1eae94 100644 --- a/internal/judge/docker.go +++ b/internal/judge/docker.go @@ -1,21 +1,21 @@ package judge import ( - "bytes" - "context" - "fmt" - "github.com/docker/docker/api/types/image" - "github.com/docker/docker/pkg/stdcopy" - "github.com/gurkengewuerz/GitCodeJudge/internal/config" - "github.com/gurkengewuerz/GitCodeJudge/internal/models" - log "github.com/sirupsen/logrus" - "io" - "os" - "path/filepath" - "time" - - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/client" + "bytes" + "context" + "fmt" + "github.com/docker/docker/api/types/image" + "github.com/docker/docker/pkg/stdcopy" + "github.com/gurkengewuerz/GitCodeJudge/internal/config" + "github.com/gurkengewuerz/GitCodeJudge/internal/models" + log "github.com/sirupsen/logrus" + "io" + "os" + "path/filepath" + "time" + + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/client" ) type DockerExecutor struct { @@ -97,8 +97,8 @@ func (e *DockerExecutor) RunCode(ctx context.Context, testCase models.TestCase) &container.Config{ Image: config.CFG.DockerImage, Env: []string{ - fmt.Sprintf("JUDGE_WORKSHOP=%s", testCase.Solution.Workshop), - fmt.Sprintf("JUDGE_TASK=%s", testCase.Solution.Task), + fmt.Sprintf("JUDGE_WORKSHOP=%s", Trim(testCase.Solution.Workshop)), + fmt.Sprintf("JUDGE_TASK=%s", Trim(testCase.Solution.Task)), }, WorkingDir: "/judge", }, diff --git a/internal/judge/pool.go b/internal/judge/pool.go index 946b799..6f95f5d 100644 --- a/internal/judge/pool.go +++ b/internal/judge/pool.go @@ -63,7 +63,7 @@ func (p *Pool) worker() { } owner, repo := parts[0], parts[1] - targetURL := fmt.Sprintf("%s/results/%s", submission.BaseURL, submission.CommitID) + targetURL := fmt.Sprintf("%s/results/%s", appConfig.CFG.BaseURL, submission.CommitID) if err := submission.GitClient.PostStarting(owner, repo, submission.CommitID, targetURL, status.StatusNone, "Judge started"); err != nil { log.WithFields(fields).WithError(err).Error("Failed to post starting") diff --git a/internal/models/submission.go b/internal/models/submission.go index 3b780c4..028cdaf 100644 --- a/internal/models/submission.go +++ b/internal/models/submission.go @@ -34,7 +34,6 @@ type Submission struct { CloneURL string Solutions []Solution GitClient *gitea.GiteaClient - BaseURL string } type TestResult struct {