From 8d874aec5eed924d5920a0c737ec1d5e5164d956 Mon Sep 17 00:00:00 2001 From: Jisu-Woniu <31986081+Jisu-Woniu@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:56:29 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=F0=9F=91=B7=20Add=20Dockerfile.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 62 +++++++++++++++++++++++------------------------------- Cargo.toml | 10 ++++----- Dockerfile | 32 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 Dockerfile diff --git a/Cargo.lock b/Cargo.lock index 61a0845..7a71311 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,7 +135,7 @@ dependencies = [ "futures-util", "http 0.2.11", "http-body 0.4.6", - "hyper 0.14.27", + "hyper 0.14.28", "itoa", "matchit", "memchr", @@ -163,7 +163,7 @@ dependencies = [ "http 1.0.0", "http-body 1.0.0", "http-body-util", - "hyper 1.0.1", + "hyper 1.1.0", "hyper-util", "itoa", "matchit", @@ -712,9 +712,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -727,7 +727,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", @@ -736,9 +736,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f9214f3e703236b221f1a9cd88ec8b4adfa5296de01ab96216361f4692f56" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" dependencies = [ "bytes", "futures-channel", @@ -759,7 +759,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper 0.14.27", + "hyper 0.14.28", "pin-project-lite", "tokio", "tokio-io-timeout", @@ -776,9 +776,9 @@ dependencies = [ "futures-util", "http 1.0.0", "http-body 1.0.0", - "hyper 1.0.1", + "hyper 1.1.0", "pin-project-lite", - "socket2 0.5.5", + "socket2", "tokio", "tower", "tower-service", @@ -1331,9 +1331,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -1392,16 +1392,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.5" @@ -1453,18 +1443,18 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" dependencies = [ "proc-macro2", "quote", @@ -1473,9 +1463,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ "deranged", "itoa", @@ -1495,9 +1485,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" dependencies = [ "time-core", ] @@ -1519,9 +1509,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.0" +version = "1.35.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" +checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" dependencies = [ "backtrace", "bytes", @@ -1529,7 +1519,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2 0.5.5", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -1628,7 +1618,7 @@ dependencies = [ "h2 0.3.22", "http 0.2.11", "http-body 0.4.6", - "hyper 0.14.27", + "hyper 0.14.28", "hyper-timeout", "percent-encoding", "pin-project", @@ -2095,9 +2085,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.28" +version = "0.5.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c830786f7720c2fd27a1a0e27a709dbd3c4d009b56d098fc742d4f4eab91fe2" +checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 859e74d..01814c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "rsjudge" -description = "An online judge sandbox server in Rust." version = "0.1.0" +authors = ["NJUPT-SAST"] edition = "2021" license = "Unknown" -authors = ["NJUPT-SAST"] +description = "An online judge sandbox server in Rust." [package.metadata.deb] assets = [ @@ -39,10 +39,11 @@ systemd-units = { enable = false } [dependencies] cgroups = "0.1.0" clap = { version = "4.4.11", features = ["derive"] } +nix = { version = "0.27.1", features = ["fs"] } serde = { version = "1.0.193", features = ["derive"] } shadow-rs = "0.25.0" strfmt = "0.2.4" -tokio = { version = "1.35.0", features = ["fs"] } +tokio = { version = "1.35.1", features = ["fs"] } toml = "0.8.8" # Optional dependencies @@ -50,10 +51,9 @@ axum = { version = "0.7.2", optional = true } tonic = { version = "0.10.2", optional = true } utoipa = { version = "4.1.0", features = ["axum_extras"], optional = true } utoipa-swagger-ui = { version = "5.0.0", features = ["axum"], optional = true } -nix = { version = "0.27.1", features = ["fs"] } [dev-dependencies] -tokio = { version = "1.35.0", features = ["rt-multi-thread", "macros"] } +tokio = { version = "1.35.1", features = ["rt-multi-thread", "macros"] } [features] grpc = ["dep:tonic"] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1bafea4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Use the official Rust image as the base image +FROM rust:latest AS builder + +# Set the working directory inside the container +WORKDIR /app + +# Copy the Cargo.toml and Cargo.lock files to the container +COPY Cargo.toml Cargo.lock ./ + +# Build the dependencies separately to take advantage of Docker layer caching +RUN mkdir -p src && touch src/lib.rs && cargo build --release && rm -rf src + +# Copy the source code to the container +COPY build.rs . +COPY src ./src + +# Build the project +RUN cargo build --release + +# Create a new container for running the build executable +FROM debian:stable-slim + +# Set the working directory inside the container +WORKDIR /app + +# Copy the build executable from the builder container +COPY --from=builder /app/target/release/rsjudge . + +COPY templates/* config/ + +# Set the entry point for the container +CMD ["./rsjudge", "-c", "config"]