# Build stage for Rust engine FROM rust:1.75-bookworm as rust-builder WORKDIR /app RUN apt-get update && apt-get install -y pkg-config libssl-dev COPY rust-engine /app/rust-engine WORKDIR /app/rust-engine # Pre-build to cache dependencies RUN cargo build --release # Build stage for Node/React frontend FROM node:20-bookworm as node-builder WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build # Final runtime stage FROM node:20-bookworm # Install system dependencies including those needed for Rust toolchain RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ curl \ build-essential \ pkg-config \ libssl-dev \ git \ && update-ca-certificates \ && rm -rf /var/lib/apt/lists/* # Install Rust toolchain safely RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" WORKDIR /app # Copy built assets COPY --from=node-builder /app/dist /app/dist COPY --from=node-builder /app/package*.json /app/ COPY --from=node-builder /app/server.ts /app/ COPY --from=node-builder /app/node_modules /app/node_modules COPY --from=node-builder /app/tsconfig.json /app/ COPY --from=node-builder /app/src /app/src # Copy the rust-engine source and pre-built artifacts COPY --from=rust-builder /app/rust-engine /app/rust-engine # Hugging Face Spaces defaults ENV PORT=7860 ENV NODE_ENV=production # Force 0.0.0.0 ENV HOST=0.0.0.0 EXPOSE 7860 # Start the unified server # Using tsx to run the server.ts entry point which manages the Rust sidecar CMD ["npx", "tsx", "server.ts"]