# Use Ubuntu as base image for better compatibility FROM ubuntu:22.04 # Prevent interactive prompts during package installation ENV DEBIAN_FRONTEND=noninteractive # Update and install essential packages RUN apt-get update && apt-get install -y \ # Python 3.11 and pip software-properties-common \ python3.11 \ python3.11-dev \ python3-pip \ python3.11-venv \ # C/C++ compilers and tools build-essential \ gcc \ g++ \ make \ # Java 17 (full JDK) openjdk-17-jdk \ # Version control and utilities git \ curl \ wget \ vim \ # Process monitoring procps \ htop \ # Clean up && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Set Python 3.11 as default python3 RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \ && update-alternatives --set python3 /usr/bin/python3.11 # Set JAVA_HOME ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 ENV PATH="$JAVA_HOME/bin:$PATH" # Create app directory WORKDIR /app # Create non-root user RUN useradd -m -u 1000 -s /bin/bash user && \ chown -R user:user /app # Give user permissions to create temp directories RUN mkdir -p /tmp/code_workspace && \ chown -R user:user /tmp/code_workspace && \ chmod 755 /tmp/code_workspace # Switch to non-root user USER user # Set user paths ENV PATH="/home/user/.local/bin:$PATH" ENV PYTHONPATH="/app:$PYTHONPATH" # Copy requirements first (for better caching) COPY --chown=user:user requirements.txt . # Install Python dependencies RUN pip3 install --no-cache-dir --upgrade pip && \ pip3 install --no-cache-dir -r requirements.txt # Copy application files COPY --chown=user:user . . # Verify installations RUN echo "=== Version Check ===" && \ python3 --version && \ pip3 --version && \ java -version && \ javac -version && \ gcc --version && \ g++ --version # Expose port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Start the application CMD ["python3", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]