# Use Python 3.11 slim image FROM python:3.11-slim # Install Node.js and npm RUN apt-get update && apt-get install -y \ curl \ && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* # Set up a new user named "user" with user ID 1000 RUN useradd -m -u 1000 user # Create data directory with proper permissions before switching user RUN mkdir -p /data && chown user:user /data # Switch to the "user" user USER user # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory to the user's home directory WORKDIR $HOME/app # Copy requirements with correct ownership COPY --chown=user requirements.txt . # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy all frontend files first COPY --chown=user frontend $HOME/app/frontend/ # Set up frontend WORKDIR $HOME/app/frontend # Create necessary Next.js directories if they don't exist RUN mkdir -p src/app # Install and build frontend RUN npm install RUN npm run build # Return to app directory WORKDIR $HOME/app # Copy the remaining application code with correct ownership COPY --chown=user . . # Expose only FastAPI port EXPOSE 3000 # Run Next.js in background and FastAPI as main process CMD ["sh", "-c", "npm run start --prefix frontend & uvicorn backend.main:app --host 0.0.0.0 --port 3000"]