Skip to content

Commit

Permalink
Use a base OS to run binary instead of Rust runtime (#67)
Browse files Browse the repository at this point in the history
The Rust runtime for a docker image is large as it includes the language's tooling. It is not needed to run a Rust binary file. This replaces running the binary with the full runtime with a base OS (Debian) to reduce the size of the Docker image.
  • Loading branch information
Wollaston authored Mar 22, 2024
1 parent 37b6902 commit 377f06d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/deployment/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,23 @@ COPY . .
# Build the app
RUN cargo leptos build --release -vv

FROM rustlang/rust:nightly-bullseye as runner
FROM debian:bookworm-slim as runtime
WORKDIR /app
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends openssl ca-certificates \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# -- NB: update binary name from "leptos_start" to match your app name in Cargo.toml --
# Copy the server binary to the /app directory
COPY --from=builder /app/target/release/leptos_start /app/

# /target/site contains our JS/WASM/CSS, etc.
COPY --from=builder /app/target/site /app/site

# Copy Cargo.toml if it’s needed at runtime
COPY --from=builder /app/Cargo.toml /app/
WORKDIR /app

# Set any required env variables and
ENV RUST_LOG="info"
Expand Down

0 comments on commit 377f06d

Please sign in to comment.