diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0d95126 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.env +target \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 321ded6..f822433 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,17 @@ name = "splatoon-server-rust" version = "0.1.0" edition = "2021" +[profile.prod] +inherits = "release" +overflow-checks = false +strip = true +debug = false +debug-assertions = false +lto = true +incremental = false + + + [dependencies] bytemuck = { version = "1.21.0", features = ["derive"] } dotenv = "0.15.0" diff --git a/Dockerfile b/Dockerfile index 5c73325..39ae51c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,19 @@ -FROM rust:1.85 AS builder +FROM rust:alpine AS builder WORKDIR /app COPY . . -RUN apt-get update && apt-get install protobuf-compiler -y +RUN apk add --no-cache protobuf-dev git musl-dev lld RUN git submodule update --init --recursive -RUN cargo build --release +RUN RUSTFLAGS="-C relocation-model=static -C linker=ld.lld" cargo build --profile prod --target x86_64-unknown-linux-musl -FROM rust:1.85 AS final - -WORKDIR /app +FROM scratch AS final # Copy the compiled binary from the builder stage -COPY --from=builder /app/target/release/splatoon-server-rust /app/splatoon-server-rust - -# Set executable permissions -RUN chmod +x /app/splatoon-server-rust +COPY --from=builder /app/target/x86_64-unknown-linux-musl/prod/splatoon-server-rust /splatoon-server-rust # Command to run the application -CMD ["/app/splatoon-server-rust"] +ENTRYPOINT ["/splatoon-server-rust"]