# Stage 1: Build Python dependencies FROM python:3.11-slim-bullseye AS builder LABEL maintainer="YourName" # Create and switch to a non-root user RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" # Set working directory WORKDIR /app # Copy and install Python dependencies COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt || echo "No requirements.txt found, skipping." # Copy application files COPY --chown=user . /app # Stage 2: Install the latest Node.js & npm via nvm FROM python:3.11-slim-bullseye AS final WORKDIR /app # Install required dependencies RUN apt-get update && apt-get install -y curl bash git && rm -rf /var/lib/apt/lists/* # Install nvm and the latest Node.js RUN curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash && \ export NVM_DIR="$HOME/.nvm" && \ [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \ nvm install node && \ nvm use node && \ node -v && npm -v # Ensure Node.js is available in PATH ENV NVM_DIR="/root/.nvm" ENV PATH="/root/.nvm/versions/node/$(ls /root/.nvm/versions/node)/bin:$PATH" # Copy application files COPY --from=builder /app /app WORKDIR /app # Ensure Uvicorn is installed RUN pip install --no-cache-dir uvicorn # Expose necessary ports EXPOSE 3000 7860 # Verify Node.js and Python environments before running RUN node -v && npm -v && python --version && pip --version && ls -l /app # Run both services CMD ["/bin/bash", "-c", "node server.js & uvicorn app:app --host 0.0.0.0 --port 7860"]