0.5.1
This commit is contained in:
30
Dockerfile
30
Dockerfile
@@ -1,6 +1,12 @@
|
||||
# Build stage
|
||||
# Build stage with memory optimization
|
||||
FROM rust:slim-bookworm AS build
|
||||
|
||||
# Create temporary swap file to help with memory-intensive compilation
|
||||
RUN dd if=/dev/zero of=/tmp/swapfile bs=1M count=1024 && \
|
||||
chmod 600 /tmp/swapfile && \
|
||||
mkswap /tmp/swapfile && \
|
||||
swapon /tmp/swapfile || true
|
||||
|
||||
# Install build dependencies
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
@@ -24,13 +30,19 @@ RUN USER=root cargo new --bin quoter
|
||||
|
||||
WORKDIR /quoter
|
||||
|
||||
# Copy manifests
|
||||
# Copy manifests and cargo config
|
||||
COPY ./Cargo.lock ./Cargo.lock
|
||||
COPY ./Cargo.toml ./Cargo.toml
|
||||
COPY ./.cargo ./.cargo
|
||||
|
||||
# Cache dependencies
|
||||
# Cache dependencies with memory optimization
|
||||
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
|
||||
RUN cargo build --release
|
||||
# Build dependencies only
|
||||
RUN cargo build --release 2>&1 | head -100 && \
|
||||
# Force cleanup of intermediate files to free memory
|
||||
cargo clean -p quoter && \
|
||||
# Keep only the dependency artifacts
|
||||
find target/release/deps -name "quoter*" -delete
|
||||
|
||||
# Remove the default source file created by cargo new
|
||||
RUN rm src/*.rs
|
||||
@@ -38,9 +50,13 @@ RUN rm src/*.rs
|
||||
# Copy source code
|
||||
COPY ./src ./src
|
||||
|
||||
# Build for release
|
||||
RUN rm ./target/release/deps/quoter*
|
||||
RUN cargo build --release
|
||||
# Build for release with aggressive memory cleanup
|
||||
RUN cargo build --release && \
|
||||
# Immediately strip the binary to save space
|
||||
strip target/release/quoter || true && \
|
||||
# Clean up swap file
|
||||
swapoff /tmp/swapfile || true && \
|
||||
rm -f /tmp/swapfile
|
||||
|
||||
# Final stage
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
Reference in New Issue
Block a user