Skip to content

Commit

Permalink
build: 👷 Add Dockerfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Dec 20, 2023
1 parent 290c36c commit 8d874ae
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
62 changes: 26 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -39,21 +39,21 @@ 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
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"]
Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 8d874ae

Please sign in to comment.