Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +28 -21
Dockerfile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
-
#
|
| 4 |
RUN apt-get update && \
|
| 5 |
apt-get install -y --no-install-recommends \
|
| 6 |
# Basic system tools
|
|
@@ -10,45 +10,52 @@ RUN apt-get update && \
|
|
| 10 |
git \
|
| 11 |
wget \
|
| 12 |
curl \
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
libxext6 \
|
| 17 |
-
libxrender-dev \
|
| 18 |
-
# Java runtime and compiler (headless version for containers)
|
| 19 |
openjdk-17-jdk-headless \
|
| 20 |
-
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
| 21 |
|
| 22 |
-
# Set JAVA_HOME
|
| 23 |
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
| 24 |
ENV PATH="$JAVA_HOME/bin:$PATH"
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
# Verify installations
|
| 31 |
RUN python3 --version && \
|
| 32 |
gcc --version && \
|
| 33 |
g++ --version && \
|
| 34 |
java -version && \
|
| 35 |
-
javac -version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Create non-root user
|
| 38 |
-
RUN useradd -m -u 1000 user
|
|
|
|
|
|
|
|
|
|
| 39 |
USER user
|
| 40 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 41 |
-
WORKDIR /app
|
| 42 |
|
| 43 |
-
# Copy requirements
|
| 44 |
-
COPY --chown=user ./requirements.txt requirements.txt
|
|
|
|
|
|
|
| 45 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 46 |
pip install --no-cache-dir --upgrade -r requirements.txt
|
| 47 |
|
| 48 |
# Copy application code
|
| 49 |
-
COPY --chown=user . /app
|
| 50 |
|
| 51 |
-
# Create temporary directory for code execution
|
| 52 |
RUN mkdir -p /tmp/code_workspace && chmod 755 /tmp/code_workspace
|
| 53 |
|
| 54 |
# Expose port
|
|
@@ -58,5 +65,5 @@ EXPOSE 7860
|
|
| 58 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 59 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 60 |
|
| 61 |
-
# Start command
|
| 62 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
+
# Install essential packages with no-install-recommends to minimize size
|
| 4 |
RUN apt-get update && \
|
| 5 |
apt-get install -y --no-install-recommends \
|
| 6 |
# Basic system tools
|
|
|
|
| 10 |
git \
|
| 11 |
wget \
|
| 12 |
curl \
|
| 13 |
+
procps \
|
| 14 |
+
# Java runtime - using OpenJDK 17 headless
|
| 15 |
+
openjdk-17-jre-headless \
|
|
|
|
|
|
|
|
|
|
| 16 |
openjdk-17-jdk-headless \
|
| 17 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 18 |
+
&& apt-get clean
|
| 19 |
|
| 20 |
+
# Set JAVA_HOME and optimize JVM for containers
|
| 21 |
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
| 22 |
ENV PATH="$JAVA_HOME/bin:$PATH"
|
| 23 |
|
| 24 |
+
# Configure JVM to work better in containers
|
| 25 |
+
# These settings help prevent metaspace allocation issues
|
| 26 |
+
ENV JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=50.0 -XX:InitialRAMPercentage=25.0"
|
| 27 |
|
| 28 |
# Verify installations
|
| 29 |
RUN python3 --version && \
|
| 30 |
gcc --version && \
|
| 31 |
g++ --version && \
|
| 32 |
java -version && \
|
| 33 |
+
javac -version && \
|
| 34 |
+
# Test Java with minimal memory settings
|
| 35 |
+
java -XX:+PrintFlagsFinal -version 2>&1 | grep -E "(UseContainerSupport|MaxRAMPercentage)"
|
| 36 |
+
|
| 37 |
+
# Create app directory first
|
| 38 |
+
WORKDIR /app
|
| 39 |
|
| 40 |
# Create non-root user
|
| 41 |
+
RUN useradd -m -u 1000 user && \
|
| 42 |
+
chown -R user:user /app
|
| 43 |
+
|
| 44 |
+
# Switch to non-root user
|
| 45 |
USER user
|
| 46 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
| 47 |
|
| 48 |
+
# Copy requirements first (better layer caching)
|
| 49 |
+
COPY --chown=user:user ./requirements.txt requirements.txt
|
| 50 |
+
|
| 51 |
+
# Install Python dependencies
|
| 52 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 53 |
pip install --no-cache-dir --upgrade -r requirements.txt
|
| 54 |
|
| 55 |
# Copy application code
|
| 56 |
+
COPY --chown=user:user . /app
|
| 57 |
|
| 58 |
+
# Create temporary directory for code execution
|
| 59 |
RUN mkdir -p /tmp/code_workspace && chmod 755 /tmp/code_workspace
|
| 60 |
|
| 61 |
# Expose port
|
|
|
|
| 65 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 66 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 67 |
|
| 68 |
+
# Start command with explicit memory settings for uvicorn
|
| 69 |
+
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|