# ============================================================================= # Multi-stage Dockerfile for Streaming ASR Client with Triton # # Stage 1: Build React frontend # Stage 2: Python runtime with static files # # Required environment variables: # - NGC_API_KEY: NVIDIA NGC API key for authentication # - FUNCTION_ID: NVCF function ID # - VERSION_ID: (optional) NVCF function version ID # ============================================================================= # ----------------------------------------------------------------------------- # Stage 1: Build the React frontend # ----------------------------------------------------------------------------- FROM node:20-alpine AS frontend-builder WORKDIR /app/web # Install dependencies first (better caching) COPY web/package.json ./ RUN npm install # Copy source and build COPY web/ ./ RUN npm run build # Output will be in /app/web/dist/ # ----------------------------------------------------------------------------- # Stage 2: Python runtime # ----------------------------------------------------------------------------- FROM python:3.11-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app WORKDIR /app # Install system dependencies (ffmpeg and libsndfile for audio processing) RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ libsndfile1 \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies COPY bridge/requirements.txt ./requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Copy Python application COPY bridge/ ./bridge/ # Copy built frontend from stage 1 COPY --from=frontend-builder /app/web/dist ./static/ # Create non-root user for security RUN useradd --create-home --shell /bin/bash appuser && \ chown -R appuser:appuser /app USER appuser # Expose the application port EXPOSE 8080 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/health')" || exit 1 # Run the application CMD ["python", "-m", "bridge.main"]