Spaces:
Sleeping
Sleeping
# 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"] | |