From 5b9c754965d871a3f043a3c5d84467c65bf06752 Mon Sep 17 00:00:00 2001 From: eason <30045503+Eason0729@users.noreply.github.com> Date: Wed, 6 Dec 2023 18:34:48 +0800 Subject: [PATCH] test: :white_check_mark: update and run docker example --- backend/src/init/db.rs | 6 ++-- docker/production/backend/backend.sqlite | 0 docker/production/backend/config.toml | 15 +++++++++ docker/production/docker-compose.yml | 6 ++-- docker/production/judger/config.toml | 25 +++++++++++++++ docker/quickstart/backend/backend.sqlite | 0 docker/quickstart/backend/config.toml | 15 +++++++++ docker/quickstart/docker-compose.yml | 6 ++-- docker/quickstart/judger/config.toml | 25 +++++++++++++++ docker/simple/docker-compose.yml | 40 ------------------------ 10 files changed, 89 insertions(+), 49 deletions(-) create mode 100644 docker/production/backend/backend.sqlite create mode 100644 docker/production/backend/config.toml create mode 100644 docker/production/judger/config.toml create mode 100644 docker/quickstart/backend/backend.sqlite create mode 100644 docker/quickstart/backend/config.toml create mode 100644 docker/quickstart/judger/config.toml delete mode 100644 docker/simple/docker-compose.yml diff --git a/backend/src/init/db.rs b/backend/src/init/db.rs index 1ac60075..fad89534 100644 --- a/backend/src/init/db.rs +++ b/backend/src/init/db.rs @@ -23,11 +23,12 @@ pub async fn init(config: &GlobalConfig) { fs::File::create(PathBuf::from(config.database.path.clone())) .await .unwrap(); - first_migration(config).await; let db: DatabaseConnection = Database::connect(&uri).await.unwrap(); + first_migration(config,&db).await; DB.set(db).unwrap(); + println!("Database created"); } } @@ -41,8 +42,7 @@ fn hash(config: &GlobalConfig, src: &str) -> Vec { .to_vec() } -pub async fn first_migration(config: &GlobalConfig) { - let db = DB.get().unwrap(); +pub async fn first_migration(config: &GlobalConfig,db:&DatabaseConnection) { let mut perm = UserPermBytes::default(); perm.grant_link(true); diff --git a/docker/production/backend/backend.sqlite b/docker/production/backend/backend.sqlite new file mode 100644 index 00000000..e69de29b diff --git a/docker/production/backend/config.toml b/docker/production/backend/config.toml new file mode 100644 index 00000000..a72dc9ab --- /dev/null +++ b/docker/production/backend/config.toml @@ -0,0 +1,15 @@ +bind_address = "0.0.0.0:8081" +log_level = 0 + +[database] +path = "database/backend.sqlite" +salt = "be sure to change it" + +[[judger]] +name = "http://127.0.0.1:8080" +type = "static" + +[grpc] +trust_x_forwarded_for = false +public_pem = "cert.pem" +private_pem = "key.pem" diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index b9719d6b..4411affd 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -20,8 +20,8 @@ services: container_name: mdoj-backend image: ghcr.io/mdcpp/mdoj:backend volumes: - - ./database/:/database/ - - ./config/:/config/ + - ./judger/:/config/ + - ./judger/:/database/ networks: - backend - judger @@ -32,7 +32,7 @@ services: image: ghcr.io/mdcpp/mdoj:judger volumes: - /sys/fs/cgroup:/sys/fs/cgroup - - ./config/:/config/ + - ./judger/:/config/ networks: - judger networks: diff --git a/docker/production/judger/config.toml b/docker/production/judger/config.toml new file mode 100644 index 00000000..4273bf70 --- /dev/null +++ b/docker/production/judger/config.toml @@ -0,0 +1,25 @@ +log_level = 0 + +[runtime] +temp = ".temp" +bind = "0.0.0.0:8080" +accuracy = 50000 +root_cgroup = "mdoj/c." + +[platform] +cpu_time_multiplier = 1.0 +available_memory = 1073741824 +output_limit = 33554432 + +[nsjail] +runtime = "./nsjail-3.1" +rootless = false +log = "/dev/null" +cgroup_version = "v2" + +[plugin] +path = "plugins" + +[kernel] +kernel_hz = 1000 +tickless = false diff --git a/docker/quickstart/backend/backend.sqlite b/docker/quickstart/backend/backend.sqlite new file mode 100644 index 00000000..e69de29b diff --git a/docker/quickstart/backend/config.toml b/docker/quickstart/backend/config.toml new file mode 100644 index 00000000..a72dc9ab --- /dev/null +++ b/docker/quickstart/backend/config.toml @@ -0,0 +1,15 @@ +bind_address = "0.0.0.0:8081" +log_level = 0 + +[database] +path = "database/backend.sqlite" +salt = "be sure to change it" + +[[judger]] +name = "http://127.0.0.1:8080" +type = "static" + +[grpc] +trust_x_forwarded_for = false +public_pem = "cert.pem" +private_pem = "key.pem" diff --git a/docker/quickstart/docker-compose.yml b/docker/quickstart/docker-compose.yml index b9719d6b..4411affd 100644 --- a/docker/quickstart/docker-compose.yml +++ b/docker/quickstart/docker-compose.yml @@ -20,8 +20,8 @@ services: container_name: mdoj-backend image: ghcr.io/mdcpp/mdoj:backend volumes: - - ./database/:/database/ - - ./config/:/config/ + - ./judger/:/config/ + - ./judger/:/database/ networks: - backend - judger @@ -32,7 +32,7 @@ services: image: ghcr.io/mdcpp/mdoj:judger volumes: - /sys/fs/cgroup:/sys/fs/cgroup - - ./config/:/config/ + - ./judger/:/config/ networks: - judger networks: diff --git a/docker/quickstart/judger/config.toml b/docker/quickstart/judger/config.toml new file mode 100644 index 00000000..4273bf70 --- /dev/null +++ b/docker/quickstart/judger/config.toml @@ -0,0 +1,25 @@ +log_level = 0 + +[runtime] +temp = ".temp" +bind = "0.0.0.0:8080" +accuracy = 50000 +root_cgroup = "mdoj/c." + +[platform] +cpu_time_multiplier = 1.0 +available_memory = 1073741824 +output_limit = 33554432 + +[nsjail] +runtime = "./nsjail-3.1" +rootless = false +log = "/dev/null" +cgroup_version = "v2" + +[plugin] +path = "plugins" + +[kernel] +kernel_hz = 1000 +tickless = false diff --git a/docker/simple/docker-compose.yml b/docker/simple/docker-compose.yml deleted file mode 100644 index 9ac61d12..00000000 --- a/docker/simple/docker-compose.yml +++ /dev/null @@ -1,40 +0,0 @@ -# TODO: change build to remote image -version: '3.9' -services: - gateway: - container_name: mdoj-gateway - image: - # remove comment if you need traefik - # labels: - # - "traefik.enable=true" - # - "traefik.http.routers.mdoj.rule=Host(`mdoj.example.com`)" - # - "traefik.http.services.mdoj.loadbalancer.server.port=80" - # - "traefik.http.middlewares.mdoj-grpcweb.grpcweb.allowOrigins=*" - # - "traefik.http.routers.mdoj.middlewares=mdoj-grpc" - # volumes: - # - ../frontend/build:/usr/share/nginx/html - ports: - - "80:80" - networks: - - backend - backend: - container_name: mdoj-backend - image: - volumes: - # TODO: change file bind mount to directory bind mount - - ./backend.sqlite:/backend/backend.sqlite - networks: - - backend - - judger - judger: - container_name: mdoj-judger - # you can actually turn this off if you setup the cgroup properly(user of the container should own the cgroup) - privileged: true - image: - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup - networks: - - judger -networks: - judger: - backend: