Skip to content

Commit

Permalink
build: 🚀 add quick-start
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Aug 2, 2024
1 parent 7efdf35 commit c96ae95
Show file tree
Hide file tree
Showing 35 changed files with 179 additions and 330 deletions.
57 changes: 34 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

Performance-oriented contest management system for IOI like contest

> [!IMPORTANT]
> :construction: work in progress, please wait until first release
## Highlights
Expand All @@ -18,43 +19,53 @@ Performance-oriented contest management system for IOI like contest

## Features

> [!TIP]
> Because we use grpc-web(server-side stream), HTTP2 is recommended, otherwise users won't be able to see realtime submit update(it's still very usable)
- :whale:Scalable: When deployed in cluster, you can scale the system to satisfy reasonable request.
- :file_cabinet:Extensible: You can add any programing language by placing a `*.lang` file in `plugins` folder
- :telescope: Powerful `metrics`/`tracing` using ``Open-Telemetry``

## Quick Start

Copy ``docker/quickstart`` file to your server and run `docker compose up -d`, then open `https://localhost` in your browser.

> Because we use grpc-web(server-side stream), HTTP2 is required, you can ignore it or place cert and key in `./cert` folder.
<details>
<summary><h2>Quick Start</h2></summary>

login as `admin@admin` and start play arounds.
Copy `docker/quickstart` file to your server and run `docker compose up -d`, then open [https://localhost](https://localhost) in your browser.

See [wiki](https://github.com/mdcpp/mdoj/wiki) for more details.
login as `admin@admin` and start play arounds.

</details>

## Full Setup(Docker)
<details>
<summary><h2>Full Setup(Docker)</h2></summary>

> Please download source code from release
1. Copy `docker/production` from source code to your folder
2. run migration by running `docker compose up migration`
3. generate config for judger by starting the judger once, and edit config
4. generate config for backend by starting the backend once
5. download and extract plugin(language support) of your choice to `./plugins`

1. Copy ``docker/production`` from source code to your folder
2. generate config for judger by starting the judger once, and edit config
3. generate config for backend by starting the backend once
4. download and extract plugin(language support) of your choice to `./plugins`
If you prefer to use default config, you can skip step 3 and 4.

If you prefer to use default config, you can skip step 2 and 3.
See [wiki](https://github.com/mdcpp/mdoj/wiki) for more details.

</details>

## Setup for development
<details>
<summary><h2>Setup for development</h2></summary>

1. install following package:
1. install following package:

- From system package manager: `protobuf-devel`, `gcc`
- From rustup: `rustup`, `cargo`, `just`
- From their website: `docker`, `docker-compose`
- From system package manager: `protobuf-devel`, `gcc`
- From rustup: `rustup`, `cargo`, `just`
- From their website: `docker`, `docker-compose`

Then start reading documents in subfolder of your interest.
Then start reading documents in subfolder of your interest.

> you may need to run ``just prepare`` in ``judger``, ``backend`` subfolder.
> you may need to run ``just prepare`` in ``judger``, ``backend`` subfolder.
</details>

## Environment
## Configuration

Set `CONFIG_PATH` to change the path to config file, default value is `config.toml`
> [!TIP]
> Set `CONFIG_PATH` to change the path to config file, default value is `config.toml`
4 changes: 2 additions & 2 deletions backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pub enum ConfigRole {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GlobalConfig {
#[serde(default = "default_bind_address")]
pub bind_address: String,
pub address: String,
#[serde(default)]
pub database: Database,
#[serde(default)]
pub log_level: usize,
pub log: usize,
#[serde(default = "default_judger")]
pub judger: Vec<Judger>,
#[serde(default)]
Expand Down
2 changes: 1 addition & 1 deletion backend/src/server/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl OtelGuard {
pub fn new() -> super::Result<Self> {
init_panic_hook();

let level = match CONFIG.log_level {
let level = match CONFIG.log {
0 => Level::TRACE,
1 => Level::DEBUG,
2 => Level::INFO,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Server {
.add_service(SubmitServer::new(self_.clone()))
.add_service(ChatServer::new(self_.clone()))
.add_service(AnnouncementServer::new(self_.clone()))
.serve_with_shutdown(CONFIG.bind_address.clone().parse().unwrap(), async {
.serve_with_shutdown(CONFIG.address.clone().parse().unwrap(), async {
if tokio::signal::ctrl_c().await.is_err() {
tracing::warn!("graceful_shutdown");
}
Expand Down
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.lang
3 changes: 2 additions & 1 deletion docker/dev/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.lang
*.lang
backend/database/*
8 changes: 5 additions & 3 deletions docker/dev/backend/config/config.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
bind_address = "0.0.0.0:8081"
log_level = 0
address = "0.0.0.0:8080"
log = 0
opentelemetry = "grpc://jaeger:4317"
default_role = "user"

[database]
path = "database/backend.sqlite"
salt = "be sure to change it"

[[judger]]
name = "http://judger:8081"
name = "http://judger:8080"
type = "static"

[grpc]
trust_host = ["192.168.216.0/24"]

[imgur]
client_id = "fffffffffffffff"
Expand Down
30 changes: 15 additions & 15 deletions docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
version: "3.9"
services:
# frontend:
# container_name: mdoj-frontend
# image: ghcr.io/mdcpp/mdoj/frontend:staging
# profiles: []
# depends_on:
# - backend
# ports:
# - "80:80"
# networks:
# - backend
frontend:
container_name: mdoj-frontend
image: ghcr.io/mdcpp/mdoj/frontend:staging
profiles: [""]
depends_on:
- backend
ports:
- "8080:8080"
networks:
- backend
backend:
container_name: mdoj-backend
image: ghcr.io/mdcpp/mdoj/backend:staging
profiles: [frontend-dev]
profiles: [frontend-dev, ""]
depends_on:
- judger
- jaeger
Expand All @@ -23,15 +23,15 @@ services:
environment:
- CONFIG_PATH=/config/config.toml
ports:
- "8081:8081"
- "8081:8080"
networks:
- judger
- jaeger
judger:
container_name: mdoj-judger
privileged: true
image: ghcr.io/mdcpp/mdoj/judger:staging
profiles: [backend-dev, frontend-dev]
profiles: [backend-dev, frontend-dev, ""]
cgroup: host
devices:
- /dev/fuse:/dev/fuse
Expand All @@ -42,13 +42,13 @@ services:
- RUST_BACKTRACE=full
- CONFIG_PATH=/config/config.toml
ports:
- "8082:8081"
- "8082:8080"
networks:
- judger
jaeger:
container_name: mdoj-jaeger
image: jaegertracing/all-in-one
profiles: [backend-dev, frontend-dev]
profiles: [backend-dev, frontend-dev, ""]
ports:
- "16686:16686"
- "4317:4317/tcp"
Expand Down
30 changes: 7 additions & 23 deletions docker/dev/judger/config/config.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
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"
log = 1
rootless = false
log = "/dev/null"
cgroup_version = "v2"

[plugin]
path = "plugins"
memory = 1073741824
address = "0.0.0.0:8080"
accounting = "auto"

[kernel]
kernel_hz = 1000
tickless = false
[ratio]
cpu = 1.0
memory = 1.0
File renamed without changes.
Binary file removed docker/production/backend.sqlite
Binary file not shown.
16 changes: 8 additions & 8 deletions docker/production/backend.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
bind_address = "0.0.0.0:8081"
log_level = 2
opentelemetry = true
address = "0.0.0.0:8080"
log = 3
opentelemetry = "grpc://jaeger:4317"
default_role = "user"

[database]
path = "database/backend.sqlite"
salt = "be sure to change it"
migration = false

[[judger]]
name = "mdoj-judger"
type = "swarm"
name = "http://judger:8080"
type = "static"

[grpc]
trust_x_forwarded_for = true
public_pem = "../cert/cert.pem"
private_pem = "../cert/key.pem"
trust_host = ["192.168.216.0/24"]

[imgur]
client_id = "fffffffffffffff"
Expand Down
Binary file removed docker/production/database/backend.sqlite-shm
Binary file not shown.
Binary file removed docker/production/database/backend.sqlite-wal
Binary file not shown.
83 changes: 33 additions & 50 deletions docker/production/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,56 @@
version: '3.9'
version: "3.9"
services:
frontend:
frontend:
container_name: mdoj-frontend
build: ../../frontend
# 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:
- ./certs:/certs
image: ghcr.io/mdcpp/mdoj/frontend:staging
depends_on:
- backend
ports:
- "80:80"
- "443:443"
- "8080:8080"
networks:
- backend
backend:
container_name: mdoj-backend
image: ghcr.io/mdcpp/mdoj:backend
image: ghcr.io/mdcpp/mdoj/backend:staging
depends_on:
- judger
- jaeger
volumes:
- ./backend.toml:/config/config.toml
- ./database:/database/
- ./backend.toml:/backend.toml
- ./database:/database
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317
- CONFIG_PATH=/backend.toml
networks:
- backend
- judger
- otel
- jaeger
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: ghcr.io/mdcpp/mdoj:judger
image: ghcr.io/mdcpp/mdoj/judger:staging
cgroup: host
devices:
- /dev/fuse:/dev/fuse
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
- ./judger.toml:/config/config.toml
tmpfs:
- /.temp
- ./judger.toml:/judger.toml
- ./plugins:/plugins
environment:
- RUST_BACKTRACE=full
- CONFIG_PATH=/judger.toml
networks:
- judger
jaeger:
image: jaegertracing/all-in-one:latest
restart: always
ports:
- "16686:16686"
otel-collector:
image: otel/opentelemetry-collector
restart: always
command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
ports:
depends_on:
container_name: mdoj-jaeger
image: jaegertracing/all-in-one
networks:
- jaeger
- prometheus
networks:
- otel
prometheus:
image: prom/prometheus:latest
restart: always
migration:
container_name: mdoj-migration
image: ghcr.io/mdcpp/mdoj/migration:staging
environment:
- DATABASE_URL=sqlite://database/backend.sqlite?mode=rwc
volumes:
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
- otel
- ./database:/database
networks:
judger:
backend:
otel:
jaeger:
Loading

0 comments on commit c96ae95

Please sign in to comment.