Spaces:
Sleeping
Sleeping
Commit
·
370239f
1
Parent(s):
56973aa
Optimize Docker build for faster compilation and avoid timeouts
Browse files- Dockerfile +22 -3
Dockerfile
CHANGED
|
@@ -3,6 +3,11 @@
|
|
| 3 |
|
| 4 |
FROM rustlang/rust:nightly-slim as builder
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Install system dependencies
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
pkg-config \
|
|
@@ -18,11 +23,25 @@ RUN apt-get update && apt-get install -y \
|
|
| 18 |
# Set working directory
|
| 19 |
WORKDIR /app
|
| 20 |
|
| 21 |
-
# Copy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
COPY . .
|
| 23 |
|
| 24 |
-
# Build Brain AI
|
| 25 |
-
RUN
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Runtime stage
|
| 28 |
FROM debian:bookworm-slim
|
|
|
|
| 3 |
|
| 4 |
FROM rustlang/rust:nightly-slim as builder
|
| 5 |
|
| 6 |
+
# Set Rust build optimizations for faster compilation
|
| 7 |
+
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
|
| 8 |
+
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
|
| 9 |
+
ENV CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG=false
|
| 10 |
+
|
| 11 |
# Install system dependencies
|
| 12 |
RUN apt-get update && apt-get install -y \
|
| 13 |
pkg-config \
|
|
|
|
| 23 |
# Set working directory
|
| 24 |
WORKDIR /app
|
| 25 |
|
| 26 |
+
# Copy manifests first for dependency caching
|
| 27 |
+
COPY Cargo.toml Cargo.lock ./
|
| 28 |
+
COPY crates/*/Cargo.toml ./crates/
|
| 29 |
+
|
| 30 |
+
# Create empty src directories to allow dependency build
|
| 31 |
+
RUN find crates -name Cargo.toml -execdir mkdir -p src \; -execdir touch src/lib.rs \;
|
| 32 |
+
RUN mkdir -p src && echo "fn main() {}" > src/main.rs
|
| 33 |
+
|
| 34 |
+
# Build dependencies first (this layer will be cached)
|
| 35 |
+
RUN cargo build --release --bin brain; exit 0
|
| 36 |
+
|
| 37 |
+
# Copy the actual source code
|
| 38 |
COPY . .
|
| 39 |
|
| 40 |
+
# Build Brain AI with optimizations for faster compilation
|
| 41 |
+
RUN CARGO_PROFILE_RELEASE_LTO=off \
|
| 42 |
+
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16 \
|
| 43 |
+
CARGO_PROFILE_RELEASE_INCREMENTAL=true \
|
| 44 |
+
cargo build --release --bin brain
|
| 45 |
|
| 46 |
# Runtime stage
|
| 47 |
FROM debian:bookworm-slim
|