Spaces:
Sleeping
Sleeping
| FROM python:3.11-slim | |
| # Install essential packages with no-install-recommends to minimize size | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends \ | |
| # Basic system tools | |
| gcc \ | |
| g++ \ | |
| make \ | |
| git \ | |
| wget \ | |
| curl \ | |
| procps \ | |
| # Java runtime - using OpenJDK 17 headless | |
| openjdk-17-jre-headless \ | |
| openjdk-17-jdk-headless \ | |
| && rm -rf /var/lib/apt/lists/* \ | |
| && apt-get clean | |
| # Set JAVA_HOME and optimize JVM for containers | |
| ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 | |
| ENV PATH="$JAVA_HOME/bin:$PATH" | |
| # Configure JVM to work better in containers with minimal memory | |
| # These settings help prevent metaspace and code cache allocation issues | |
| # Note: We intentionally don't use JAVA_TOOL_OPTIONS to avoid conflicts | |
| # ENV JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport" | |
| # Verify installations | |
| RUN python3 --version && \ | |
| gcc --version && \ | |
| g++ --version && \ | |
| java -version && \ | |
| javac -version && \ | |
| # Test Java with minimal memory settings | |
| java -XX:+PrintFlagsFinal -version 2>&1 | grep -E "(UseContainerSupport|MaxRAMPercentage)" | |
| # Create app directory first | |
| WORKDIR /app | |
| # Create non-root user | |
| RUN useradd -m -u 1000 user && \ | |
| chown -R user:user /app | |
| # Switch to non-root user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| # Copy requirements first (better layer caching) | |
| COPY --chown=user:user ./requirements.txt requirements.txt | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Copy application code | |
| COPY --chown=user:user . /app | |
| # Create temporary directory for code execution | |
| RUN mkdir -p /tmp/code_workspace && chmod 755 /tmp/code_workspace | |
| # 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 command with explicit memory settings for uvicorn | |
| CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |