1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# RusTorch Production Dockerfile
# Multi-stage build for optimized production image
# Build stage
FROM rust:1.81-slim as builder
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
cmake \
clang \
python3 \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /usr/src/rustorch
# Copy manifests first for better caching
COPY Cargo.toml ./
# Create src directory and add dummy lib.rs to build dependencies
RUN mkdir -p src && echo "// Dummy lib for dependency compilation" > src/lib.rs
# Build dependencies (this will generate a new Cargo.lock compatible with container's Cargo version)
RUN cargo build --release && rm -rf src
# Copy source code
COPY src ./src
COPY examples ./examples
COPY benches ./benches
# Build the library only (excluding problematic binaries)
RUN cargo build --release --lib
# Production stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
# Create app user
RUN useradd -m -u 1001 rustorch
# Create necessary directories
RUN mkdir -p /app/data /app/models /app/output /app/lib && \
chown -R rustorch:rustorch /app
# Copy examples only
COPY --from=builder /usr/src/rustorch/examples /app/examples/
# Copy library files
COPY --from=builder /usr/src/rustorch/target/release/librustorch.* /app/lib/
# Set environment variables
ENV RUST_LOG=info
ENV RUSTORCH_DATA_PATH=/app/data
ENV RUSTORCH_MODEL_PATH=/app/models
ENV RUSTORCH_OUTPUT_PATH=/app/output
# Switch to non-root user
USER rustorch
# Set working directory
WORKDIR /app
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD echo "RusTorch container is healthy"
# Default command
CMD ["bash"]