diff --git a/.github/workflows/docker-publish-server.yml b/.github/workflows/docker-publish-server.yml index fe7bc5b..75543ef 100644 --- a/.github/workflows/docker-publish-server.yml +++ b/.github/workflows/docker-publish-server.yml @@ -1,4 +1,4 @@ -name: Docker +name: Docker Publish Server # This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by @@ -17,7 +17,7 @@ env: # Use docker.io for Docker Hub if empty REGISTRY: ghcr.io # github.repository as / - IMAGE_NAME: ${{ github.repository }}/judge-server + IMAGE_NAME: ${{ github.repository }}/judger-server jobs: @@ -66,12 +66,12 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action + # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a with: - file: docker/judge-server.dockerfile + file: docker/judger-server.dockerfile context: . push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/rust_build.yml b/.github/workflows/rust-check.yml similarity index 98% rename from .github/workflows/rust_build.yml rename to .github/workflows/rust-check.yml index ca04159..73c2e2d 100644 --- a/.github/workflows/rust_build.yml +++ b/.github/workflows/rust-check.yml @@ -1,4 +1,4 @@ -name: Test +name: Rust Check on: push: diff --git a/.vscode/settings.json b/.vscode/settings.json index e1afab8..09a44cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,10 @@ "judge-service": "helper", "judge-server": "server", "postman": "api" - } + }, + "rust-analyzer.linkedProjects": [ + "./judger/Cargo.toml", + "./judger/Cargo.toml", + "./judger/Cargo.toml" + ] } diff --git a/Cargo.toml b/Cargo.toml index 8b13014..b3ccdcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["judge-core", "judge-service", "judge-server", "judge-cli"] +members = ["judge-core", "judger"] resolver = "2" \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index cefe29a..41688fa 100644 --- a/docker/README.md +++ b/docker/README.md @@ -5,5 +5,5 @@ Run the following command under project root instead. ```sh -docker build --pull --rm -f "docker/judge-server.dockerfile" -t oj-lab/judge-server:latest . +docker build --pull --rm -f "docker/judger-server.dockerfile" -t oj-lab/judger-server:latest . ``` diff --git a/docker/judge-server.dockerfile b/docker/judger-server.dockerfile similarity index 61% rename from docker/judge-server.dockerfile rename to docker/judger-server.dockerfile index c76677b..753e531 100644 --- a/docker/judge-server.dockerfile +++ b/docker/judger-server.dockerfile @@ -1,17 +1,17 @@ FROM rust:latest as build COPY judge-core /usr/src/judge-core -COPY judge-server /usr/src/judge-server -WORKDIR /usr/src/judge-server +COPY judger /usr/src/judger +WORKDIR /usr/src/judger RUN apt update && apt install -y libseccomp-dev gcc -RUN cargo build --bin judge-server --release +RUN cargo build --bin judger-server --release FROM ubuntu:latest RUN apt update && apt install -y libseccomp-dev gcc g++ -COPY --from=build /usr/src/judge-server/target/release/judge-server /usr/local/bin/judge-server +COPY --from=build /usr/src/judger/target/release/judger-server /usr/local/bin/judger-server RUN mkdir /workspace WORKDIR /workspace COPY dev-problem-package /workspace/dev-problem-package diff --git a/judge-cli/Cargo.toml b/judge-cli/Cargo.toml deleted file mode 100644 index 20cb9dc..0000000 --- a/judge-cli/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "judge-cli" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -clap = { version = "4.0", features = ["derive"] } -judge-core = { path = "../judge-core" } -env_logger = "0.10.0" -log = "0.4" \ No newline at end of file diff --git a/judge-server/README.md b/judge-server/README.md deleted file mode 100644 index 8bc4687..0000000 --- a/judge-server/README.md +++ /dev/null @@ -1,5 +0,0 @@ -### How to run -`cargo run --bin judge-server -- --env-path ./judge-server/src/environment/.env.development` - -### How to visit OpenAPI -visit `{HOST}/swagger-ui/` \ No newline at end of file diff --git a/judge-server/postman/Judge Server.postman_collection.json b/judge-server/postman/Judge Server.postman_collection.json deleted file mode 100644 index 4535e53..0000000 --- a/judge-server/postman/Judge Server.postman_collection.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "info": { - "_postman_id": "97809aca-56f3-4402-9d73-24c841f5c664", - "name": "Judge Server", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "12985580" - }, - "item": [ - { - "name": "v1/judge/hello-world", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\r\n \"code\": \"#include \\n\\nusing namespace std;\\n\\nint main() {\\n string s;\\n cin >> s;\\n cout << \\\"Hello! \\\" << s << endl;\\n}\\n\",\r\n \"language\": \"Cpp\"\r\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{Judger Host}}/api/v1/judge/hello-world", - "host": [ - "{{Judger Host}}" - ], - "path": [ - "api", - "v1", - "judge", - "hello-world" - ] - } - }, - "response": [] - }, - { - "name": "v1/judge/hello-world TLE", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\r\n \"code\": \"#include \\r\\n#include \\r\\n\\r\\nint main() {\\r\\n clock_t start, step;\\r\\n start = clock();\\r\\n step = clock();\\r\\n while (true) {\\r\\n if (clock() - step > 1000000) {\\r\\n printf(\\\"%lds has passed..\\\\n\\\", (clock() - start) \\/ 1000000);\\r\\n step = clock();\\r\\n }\\r\\n }\\r\\n}\\r\\n\",\r\n \"language\": \"Cpp\"\r\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{Judger Host}}/api/v1/judge/hello-world", - "host": [ - "{{Judger Host}}" - ], - "path": [ - "api", - "v1", - "judge", - "hello-world" - ] - } - }, - "response": [] - } - ] -} \ No newline at end of file diff --git a/judge-server/postman/OJ Lab Environment.postman_environment.json b/judge-server/postman/OJ Lab Environment.postman_environment.json deleted file mode 100644 index 46bbe43..0000000 --- a/judge-server/postman/OJ Lab Environment.postman_environment.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "id": "5fdf6ce1-e53b-44eb-b273-b44be3db8bab", - "name": "OJ Lab Environment", - "values": [ - { - "key": "Judger Host", - "value": "localhost:8000", - "type": "default", - "enabled": true - }, - { - "key": "Service Host", - "value": "localhost:8080", - "type": "default", - "enabled": true - } - ], - "_postman_variable_scope": "environment", - "_postman_exported_at": "2023-09-03T02:21:12.497Z", - "_postman_exported_using": "Postman/10.17.4" -} \ No newline at end of file diff --git a/judge-service/Cargo.toml b/judge-service/Cargo.toml deleted file mode 100644 index 8611768..0000000 --- a/judge-service/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "judge-service" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -judge-core = { path = "../judge-core" } -anyhow = "1.0" -serde = "1" -serde_derive = "1" -serde_json = "1" -log = "0.4" - -[dev-dependencies] -env_logger = "0.10.0" \ No newline at end of file diff --git a/judge-service/src/utils/mod.rs b/judge-service/src/utils/mod.rs deleted file mode 100644 index 8b13789..0000000 --- a/judge-service/src/utils/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/judge-server/Cargo.toml b/judger/Cargo.toml similarity index 79% rename from judge-server/Cargo.toml rename to judger/Cargo.toml index 131f199..711ca6e 100644 --- a/judge-server/Cargo.toml +++ b/judger/Cargo.toml @@ -1,11 +1,16 @@ [package] -name = "judge-server" +name = "judger" version = "0.1.0" -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +judge-core = { path = "../judge-core" } + +# CLI +clap = { version = "4.0", features = ["derive"] } + # Async runtime tokio = { version = "1", features = ["full"] } @@ -37,4 +42,11 @@ thiserror = "1" uuid = { version = "1.4", features = ["serde", "v4"] } -judge-core = { path = "../judge-core" } +[[bin]] +name ="judger-cli" +path ="src/cli/main.rs" + +[[bin]] +name ="judger-server" +path ="src/server/main.rs" + diff --git a/judge-cli/README.md b/judger/README.md similarity index 51% rename from judge-cli/README.md rename to judger/README.md index 3d1cc05..bc79642 100644 --- a/judge-cli/README.md +++ b/judger/README.md @@ -1,26 +1,38 @@ -# Judge Cli +# Judger + +## Cli This will be the easiest and closest way to try out the basic feature of Judger. -## Develop Usage +### Develop Usage To run from the source code, try: ``` shell -cargo run --bin judge-cli -- [COMMAND] +cargo run --bin judger-cli -- [COMMAND] ``` ``` shell -cargo run --bin judge-cli -- batch-judge --help +cargo run --bin judger-cli -- batch-judge --help ``` For an example usage of the lastest batch judge feature: ``` shell -cargo run --bin judge-cli -- batch-judge \ +cargo run --bin judger-cli -- batch-judge \ -s test-collection/src/programs/read_and_write.cpp \ -p test-collection/packages/icpc/hello_world \ -l cpp \ -t icpc \ -r tmp/icpc -``` \ No newline at end of file +``` + +## Server + +### How to run + +`cargo run --bin judger-server -- --env-path ./judge-server/src/environment/.env.development` + +### How to visit OpenAPI + +visit `{HOST}/swagger-ui/` diff --git a/judge-cli/src/main.rs b/judger/src/cli/main.rs similarity index 100% rename from judge-cli/src/main.rs rename to judger/src/cli/main.rs diff --git a/judger/src/lib.rs b/judger/src/lib.rs new file mode 100644 index 0000000..6c31b34 --- /dev/null +++ b/judger/src/lib.rs @@ -0,0 +1,2 @@ +#[allow(dead_code)] +pub mod service; \ No newline at end of file diff --git a/judge-server/src/environment/.env.development b/judger/src/server/environment/.env.development similarity index 100% rename from judge-server/src/environment/.env.development rename to judger/src/server/environment/.env.development diff --git a/judge-server/src/environment/mod.rs b/judger/src/server/environment/mod.rs similarity index 94% rename from judge-server/src/environment/mod.rs rename to judger/src/server/environment/mod.rs index 823c995..91b9255 100644 --- a/judge-server/src/environment/mod.rs +++ b/judger/src/server/environment/mod.rs @@ -9,7 +9,7 @@ pub struct JudgeServerOpt { pub env_path: Option, /// Port to listen to - #[structopt(env = "PORT", default_value = "8000")] + #[structopt(env = "PORT", default_value = "8080")] pub port: u16, #[structopt(long, default_value = "dev-problem-package")] diff --git a/judge-server/src/error.rs b/judger/src/server/error.rs similarity index 100% rename from judge-server/src/error.rs rename to judger/src/server/error.rs diff --git a/judge-server/src/main.rs b/judger/src/server/main.rs similarity index 100% rename from judge-server/src/main.rs rename to judger/src/server/main.rs diff --git a/judge-server/src/service/greet.rs b/judger/src/server/service/greet.rs similarity index 100% rename from judge-server/src/service/greet.rs rename to judger/src/server/service/greet.rs diff --git a/judge-server/src/service/judge.rs b/judger/src/server/service/judge.rs similarity index 100% rename from judge-server/src/service/judge.rs rename to judger/src/server/service/judge.rs diff --git a/judge-server/src/service/mod.rs b/judger/src/server/service/mod.rs similarity index 100% rename from judge-server/src/service/mod.rs rename to judger/src/server/service/mod.rs diff --git a/judge-server/src/service/state.rs b/judger/src/server/service/state.rs similarity index 100% rename from judge-server/src/service/state.rs rename to judger/src/server/service/state.rs diff --git a/judge-service/src/error.rs b/judger/src/service/error.rs similarity index 100% rename from judge-service/src/error.rs rename to judger/src/service/error.rs diff --git a/judge-service/src/lib.rs b/judger/src/service/mod.rs similarity index 78% rename from judge-service/src/lib.rs rename to judger/src/service/mod.rs index 5a294ad..215fb2c 100644 --- a/judge-service/src/lib.rs +++ b/judger/src/service/mod.rs @@ -1,3 +1,2 @@ pub mod error; pub mod package_manager; -mod utils; diff --git a/judge-service/src/package_manager/discription.rs b/judger/src/service/package_manager/discription.rs similarity index 66% rename from judge-service/src/package_manager/discription.rs rename to judger/src/service/package_manager/discription.rs index 04a33a2..d1fe137 100644 --- a/judge-service/src/package_manager/discription.rs +++ b/judger/src/service/package_manager/discription.rs @@ -7,7 +7,7 @@ use std::{ use judge_core::{error::JudgeCoreError, package::PackageType}; use serde_derive::{Deserialize, Serialize}; -use crate::error::JudgeServiceError; +use crate::service::error::JudgeServiceError; pub const PACKAGES_DISCRIPTION_FILE_NAME: &str = "judge-pd.json"; @@ -98,52 +98,3 @@ fn update_package_discription_file( )?; Ok(()) } - -#[cfg(test)] -pub mod package_discription_test { - use judge_core::package::PackageType; - - #[test] - fn test_storaged_package_discription_map() { - use super::StoragedPackageDiscriptionMap; - use std::path::PathBuf; - - let folder = PathBuf::from("../judge-core/tests/temp"); - let mut package_discription_map = - StoragedPackageDiscriptionMap::init(folder.clone()).unwrap(); - - let package_discription = super::PackageDiscription { - name: "test".to_string(), - revision: 1, - package_type: PackageType::ICPC, - }; - package_discription_map.insert(package_discription).unwrap(); - - let package_discription_map = StoragedPackageDiscriptionMap::load(folder).unwrap(); - assert_eq!(package_discription_map.package_discription_map.len(), 1); - assert_eq!( - package_discription_map - .package_discription_map - .get("test") - .unwrap() - .name, - "test" - ); - assert_eq!( - package_discription_map - .package_discription_map - .get("test") - .unwrap() - .revision, - 1 - ); - assert_eq!( - package_discription_map - .package_discription_map - .get("test") - .unwrap() - .package_type, - PackageType::ICPC - ); - } -} diff --git a/judge-service/src/package_manager/mod.rs b/judger/src/service/package_manager/mod.rs similarity index 98% rename from judge-service/src/package_manager/mod.rs rename to judger/src/service/package_manager/mod.rs index af78bae..04b0fb5 100644 --- a/judge-service/src/package_manager/mod.rs +++ b/judger/src/service/package_manager/mod.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use judge_core::package::PackageType; -use crate::error::JudgeServiceError; +use crate::service::error::JudgeServiceError; use self::discription::StoragedPackageDiscriptionMap; diff --git a/judger/tests/package_test.rs b/judger/tests/package_test.rs new file mode 100644 index 0000000..6d01528 --- /dev/null +++ b/judger/tests/package_test.rs @@ -0,0 +1,48 @@ +use std::path::PathBuf; + +use judge_core::package::PackageType; +use judger::service::package_manager::discription::{ + PackageDiscription, StoragedPackageDiscriptionMap, +}; + +const TEST_TEMP_PATH: &str = "tests/temp"; + +#[test] +fn test_storaged_package_discription_map() { + let folder = PathBuf::from(TEST_TEMP_PATH); + let mut package_discription_map = StoragedPackageDiscriptionMap::init(folder.clone()).unwrap(); + + let package_discription = PackageDiscription { + name: "test".to_string(), + revision: 1, + package_type: PackageType::ICPC, + }; + package_discription_map.insert(package_discription).unwrap(); + + let package_discription_map = StoragedPackageDiscriptionMap::load(folder).unwrap(); + assert_eq!(package_discription_map.package_discription_map.len(), 1); + assert_eq!( + package_discription_map + .package_discription_map + .get("test") + .unwrap() + .name, + "test" + ); + assert_eq!( + package_discription_map + .package_discription_map + .get("test") + .unwrap() + .revision, + 1 + ); + assert_eq!( + package_discription_map + .package_discription_map + .get("test") + .unwrap() + .package_type, + PackageType::ICPC + ); +} diff --git a/judger/tests/temp/judge-pd.json b/judger/tests/temp/judge-pd.json new file mode 100644 index 0000000..8ac8c98 --- /dev/null +++ b/judger/tests/temp/judge-pd.json @@ -0,0 +1,7 @@ +{ + "test": { + "name": "test", + "revision": 1, + "package_type": "ICPC" + } +} \ No newline at end of file