Spaces:
Sleeping
Sleeping
File size: 2,723 Bytes
1ef36b9 |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# Brain AI - Hugging Face Deployment Dockerfile
# Built on August 07, 2025 - Using Rust nightly for edition2024 support
FROM rustlang/rust:nightly-slim as builder
# Set Rust build optimizations for faster compilation
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
ENV CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG=false
# Install system dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
libsqlite3-dev \
build-essential \
curl \
python3 \
python3-pip \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy manifests first for dependency caching
COPY Cargo.toml Cargo.lock ./
COPY crates/*/Cargo.toml ./crates/
# Create empty src directories to allow dependency build
RUN find crates -name Cargo.toml -execdir mkdir -p src \; -execdir touch src/lib.rs \;
RUN mkdir -p src && echo "fn main() {}" > src/main.rs
# Build dependencies first (this layer will be cached)
RUN cargo build --release --bin brain; exit 0
# Copy the actual source code
COPY . .
# Build Brain AI with optimizations for faster compilation
RUN CARGO_PROFILE_RELEASE_LTO=off \
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16 \
CARGO_PROFILE_RELEASE_INCREMENTAL=true \
cargo build --release --bin brain
# Runtime stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libssl3 \
libsqlite3-0 \
python3 \
python3-pip \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create app user
RUN useradd -m -s /bin/bash appuser
# Set working directory
WORKDIR /app
# Copy built binary and essential files
COPY --from=builder /app/target/release/brain /usr/local/bin/brain
COPY --from=builder /app/web/ ./web/
COPY --from=builder /app/data/ ./data/
COPY --from=builder /app/examples/ ./examples/
# Copy configuration files
COPY --from=builder /app/Cargo.toml ./
COPY --from=builder /app/README.md ./
# Create necessary directories
RUN mkdir -p /app/logs /app/temp /app/sessions
# Set permissions
RUN chown -R appuser:appuser /app
RUN chmod +x /usr/local/bin/brain
# Switch to app user
USER appuser
# Set environment variables for Hugging Face deployment
ENV RUST_LOG=info
ENV BRAIN_PORT=7860
ENV BRAIN_HOST=0.0.0.0
ENV BRAIN_ENV=production
ENV BRAIN_DATA_DIR=/app/data
ENV BRAIN_LOG_DIR=/app/logs
ENV BRAIN_WEB_DIR=/app/web
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Expose port 7860 (Hugging Face Spaces standard)
EXPOSE 7860
# Start Brain AI
CMD ["brain", "--port", "7860", "--host", "0.0.0.0", "--mode", "web"]
|