From f7d900b562e13d630514c692ffadc231d542f577 Mon Sep 17 00:00:00 2001 From: slhmy <1484836413@qq.com> Date: Thu, 8 Feb 2024 20:15:01 +0800 Subject: [PATCH] Pass judger in docker-compose --- .gitignore | 4 +++- .vscode/settings.json | 6 +++++- environment/docker-compose.yml | 15 ++++++++------- environment/rclone-minio.example.conf | 9 +++++++++ src/application/migrate_db/main.go | 6 +++--- src/service/mapper/problem.go | 6 +++--- src/service/model/problem.go | 3 +-- tests/core/minio_test.go | 2 +- .../icpc/{hello_world => hello-world}/.timelimit | 0 .../data/secret/0.ans | 0 .../data/secret/0.in | 0 .../data/secret/1.ans | 0 .../data/secret/1.in | 0 .../output_validators/interactor-a-plus-b | Bin .../output_validators/lcmp | Bin .../output_validators/ncmp | Bin .../{hello_world => hello-world}/problem.yaml | 0 tests/mapper/problem_test.go | 4 ++-- 18 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 environment/rclone-minio.example.conf rename tests/data/packages/icpc/{hello_world => hello-world}/.timelimit (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/data/secret/0.ans (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/data/secret/0.in (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/data/secret/1.ans (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/data/secret/1.in (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/output_validators/interactor-a-plus-b (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/output_validators/lcmp (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/output_validators/ncmp (100%) rename tests/data/packages/icpc/{hello_world => hello-world}/problem.yaml (100%) diff --git a/.gitignore b/.gitignore index 95a1f38..e356da6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,6 @@ dist.zip # Ignore generated files *.pb.go -**/swaggo-gen/docs.go \ No newline at end of file +**/swaggo-gen/docs.go + +environment/rclone-minio.conf \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index f3381d1..b273c69 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,9 @@ "postman": "api", ".github/workflows": "github", "test-collection": "resource" - } + }, + "go.testFlags": [ + "-v", + "-count=1" + ], } diff --git a/environment/docker-compose.yml b/environment/docker-compose.yml index 57f9e79..4b412d8 100644 --- a/environment/docker-compose.yml +++ b/environment/docker-compose.yml @@ -30,14 +30,15 @@ services: ports: - "6379:6379" - judger-1: + judger: image: ghcr.io/oj-lab/judger/judger-server:main + pull_policy: always restart: always ports: - "8000:8000" - - judger-2: - image: ghcr.io/oj-lab/judger/judger-server:main - restart: always - ports: - - "8001:8000" \ No newline at end of file + environment: + - BASE_URL=http://host.docker.internal:8080/api/v1/judge + - INTERVAL=10 + - RUST_LOG=DEBUG + volumes: + - ../environment/rclone-minio.conf:/workspace/data/rclone-minio.conf diff --git a/environment/rclone-minio.example.conf b/environment/rclone-minio.example.conf new file mode 100644 index 0000000..dc382cb --- /dev/null +++ b/environment/rclone-minio.example.conf @@ -0,0 +1,9 @@ +[minio] +type = s3 +provider = Minio +env_auth = false +access_key_id = your_access_key_id +secret_access_key = your_access_key_id +endpoint = http://host.docker.internal:9000 +location_constraint = +acl = private \ No newline at end of file diff --git a/src/application/migrate_db/main.go b/src/application/migrate_db/main.go index 14a74da..330331f 100644 --- a/src/application/migrate_db/main.go +++ b/src/application/migrate_db/main.go @@ -20,7 +20,7 @@ func main() { Title: "Hello World!", Description: &description, Tags: []*model.AlgorithmTag{ - {Slug: "primer", Name: "Primer"}, + {Name: "Primer"}, }, }) @@ -30,8 +30,8 @@ func main() { Title: "A + B", Description: &description, Tags: []*model.AlgorithmTag{ - {Slug: "primer", Name: "Primer"}, - {Slug: "math", Name: "Math"}, + {Name: "Primer"}, + {Name: "Math"}, }, }) diff --git a/src/service/mapper/problem.go b/src/service/mapper/problem.go index 76df835..5f503a4 100644 --- a/src/service/mapper/problem.go +++ b/src/service/mapper/problem.go @@ -39,7 +39,7 @@ type GetProblemOptions struct { func buildGetProblemTXByOptions(tx *gorm.DB, options GetProblemOptions, isCount bool) *gorm.DB { tagsList := []string{} for _, tag := range options.Tags { - tagsList = append(tagsList, tag.Slug) + tagsList = append(tagsList, tag.Name) } tx = tx.Model(&model.Problem{}) if len(options.Selection) > 0 { @@ -47,7 +47,7 @@ func buildGetProblemTXByOptions(tx *gorm.DB, options GetProblemOptions, isCount } if len(tagsList) > 0 { tx = tx.Joins("JOIN problem_algorithm_tags ON problem_algorithm_tags.problem_slug = problems.slug"). - Where("problem_algorithm_tags.algorithm_tag_slug in ?", tagsList) + Where("problem_algorithm_tags.algorithm_tag_name in ?", tagsList) } if options.Slug != nil { tx = tx.Where("slug = ?", *options.Slug) @@ -98,7 +98,7 @@ func GetProblemListByOptions(tx *gorm.DB, options GetProblemOptions) ([]model.Pr func GetTagsList(problem model.Problem) []string { tagsList := []string{} for _, tag := range problem.Tags { - tagsList = append(tagsList, tag.Slug) + tagsList = append(tagsList, tag.Name) } return tagsList } diff --git a/src/service/model/problem.go b/src/service/model/problem.go index d2a2734..aed75c6 100644 --- a/src/service/model/problem.go +++ b/src/service/model/problem.go @@ -10,8 +10,7 @@ type Problem struct { type AlgorithmTag struct { MetaFields - Slug string `gorm:"primaryKey" json:"slug"` - Name string `gorm:"not null" json:"name"` + Name string `gorm:"primaryKey" json:"name"` Problems []*Problem `gorm:"many2many:problem_algorithm_tags;" json:"problems,omitempty"` } diff --git a/tests/core/minio_test.go b/tests/core/minio_test.go index 90af3b0..864c1b2 100644 --- a/tests/core/minio_test.go +++ b/tests/core/minio_test.go @@ -33,7 +33,7 @@ func TestMinio(T *testing.T) { } // Upload package files - packagePath := "tests/data/packages/icpc/hello_world" + packagePath := "../data/packages/icpc/hello-world" filepath.Walk(packagePath, func(path string, info fs.FileInfo, err error) error { if info == nil { return fmt.Errorf("file info is nil") diff --git a/tests/data/packages/icpc/hello_world/.timelimit b/tests/data/packages/icpc/hello-world/.timelimit similarity index 100% rename from tests/data/packages/icpc/hello_world/.timelimit rename to tests/data/packages/icpc/hello-world/.timelimit diff --git a/tests/data/packages/icpc/hello_world/data/secret/0.ans b/tests/data/packages/icpc/hello-world/data/secret/0.ans similarity index 100% rename from tests/data/packages/icpc/hello_world/data/secret/0.ans rename to tests/data/packages/icpc/hello-world/data/secret/0.ans diff --git a/tests/data/packages/icpc/hello_world/data/secret/0.in b/tests/data/packages/icpc/hello-world/data/secret/0.in similarity index 100% rename from tests/data/packages/icpc/hello_world/data/secret/0.in rename to tests/data/packages/icpc/hello-world/data/secret/0.in diff --git a/tests/data/packages/icpc/hello_world/data/secret/1.ans b/tests/data/packages/icpc/hello-world/data/secret/1.ans similarity index 100% rename from tests/data/packages/icpc/hello_world/data/secret/1.ans rename to tests/data/packages/icpc/hello-world/data/secret/1.ans diff --git a/tests/data/packages/icpc/hello_world/data/secret/1.in b/tests/data/packages/icpc/hello-world/data/secret/1.in similarity index 100% rename from tests/data/packages/icpc/hello_world/data/secret/1.in rename to tests/data/packages/icpc/hello-world/data/secret/1.in diff --git a/tests/data/packages/icpc/hello_world/output_validators/interactor-a-plus-b b/tests/data/packages/icpc/hello-world/output_validators/interactor-a-plus-b similarity index 100% rename from tests/data/packages/icpc/hello_world/output_validators/interactor-a-plus-b rename to tests/data/packages/icpc/hello-world/output_validators/interactor-a-plus-b diff --git a/tests/data/packages/icpc/hello_world/output_validators/lcmp b/tests/data/packages/icpc/hello-world/output_validators/lcmp similarity index 100% rename from tests/data/packages/icpc/hello_world/output_validators/lcmp rename to tests/data/packages/icpc/hello-world/output_validators/lcmp diff --git a/tests/data/packages/icpc/hello_world/output_validators/ncmp b/tests/data/packages/icpc/hello-world/output_validators/ncmp similarity index 100% rename from tests/data/packages/icpc/hello_world/output_validators/ncmp rename to tests/data/packages/icpc/hello-world/output_validators/ncmp diff --git a/tests/data/packages/icpc/hello_world/problem.yaml b/tests/data/packages/icpc/hello-world/problem.yaml similarity index 100% rename from tests/data/packages/icpc/hello_world/problem.yaml rename to tests/data/packages/icpc/hello-world/problem.yaml diff --git a/tests/mapper/problem_test.go b/tests/mapper/problem_test.go index b1fdf48..9ef130b 100644 --- a/tests/mapper/problem_test.go +++ b/tests/mapper/problem_test.go @@ -17,7 +17,7 @@ func TestProblemMapper(t *testing.T) { Slug: "a-plus-b-problem", Title: "A+B Problem", Description: &description, - Tags: []*model.AlgorithmTag{{Slug: "tag1"}, {Slug: "tag2"}}, + Tags: []*model.AlgorithmTag{{Name: "tag1"}, {Name: "tag2"}}, } err := mapper.CreateProblem(db, problem) @@ -38,7 +38,7 @@ func TestProblemMapper(t *testing.T) { problemOption := mapper.GetProblemOptions{ Selection: model.ProblemInfoSelection, - Tags: []*model.AlgorithmTag{{Slug: "tag1"}}, + Tags: []*model.AlgorithmTag{{Name: "tag1"}}, Slug: &problem.Slug, }