Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +65 -60
Dockerfile
CHANGED
|
@@ -1,75 +1,81 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
| 22 |
ENV PATH="$JAVA_HOME/bin:$PATH"
|
| 23 |
|
| 24 |
-
# Create app directory
|
| 25 |
WORKDIR /app
|
| 26 |
|
| 27 |
-
# Create non-root user
|
| 28 |
-
RUN useradd -m -u 1000 user && \
|
| 29 |
-
chown -R user:user /app
|
| 30 |
-
# Set ulimits for the user to prevent Java memory allocation issues
|
| 31 |
-
echo "user soft nofile 65536" >> /etc/security/limits.conf && \
|
| 32 |
-
echo "user hard nofile 65536" >> /etc/security/limits.conf && \
|
| 33 |
-
echo "user soft nproc 32768" >> /etc/security/limits.conf && \
|
| 34 |
-
echo "user hard nproc 32768" >> /etc/security/limits.conf && \
|
| 35 |
-
echo "user soft memlock unlimited" >> /etc/security/limits.conf && \
|
| 36 |
-
echo "user hard memlock unlimited" >> /etc/security/limits.conf && \
|
| 37 |
-
echo "user soft stack 8192" >> /etc/security/limits.conf && \
|
| 38 |
-
echo "user hard stack 8192" >> /etc/security/limits.conf
|
| 39 |
-
|
| 40 |
-
# Create a startup script to set ulimits
|
| 41 |
-
RUN echo '#!/bin/bash\n\
|
| 42 |
-
ulimit -n 65536\n\
|
| 43 |
-
ulimit -u 32768\n\
|
| 44 |
-
ulimit -m unlimited\n\
|
| 45 |
-
ulimit -s 8192\n\
|
| 46 |
-
ulimit -v unlimited\n\
|
| 47 |
-
exec "$@"' > /entrypoint.sh && \
|
| 48 |
-
chmod +x /entrypoint.sh
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
RUN
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
java -version && \
|
| 55 |
-
javac -version
|
| 56 |
|
| 57 |
# Switch to non-root user
|
| 58 |
USER user
|
|
|
|
|
|
|
| 59 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
| 60 |
|
| 61 |
-
# Copy requirements first (better
|
| 62 |
-
COPY --chown=user:user
|
| 63 |
|
| 64 |
# Install Python dependencies
|
| 65 |
-
RUN
|
| 66 |
-
|
| 67 |
|
| 68 |
-
# Copy application
|
| 69 |
-
COPY --chown=user:user .
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
RUN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# Expose port
|
| 75 |
EXPOSE 7860
|
|
@@ -78,6 +84,5 @@ EXPOSE 7860
|
|
| 78 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 79 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 80 |
|
| 81 |
-
# Start
|
| 82 |
-
|
| 83 |
-
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use Ubuntu as base image for better compatibility
|
| 2 |
+
FROM ubuntu:22.04
|
| 3 |
+
|
| 4 |
+
# Prevent interactive prompts during package installation
|
| 5 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
+
|
| 7 |
+
# Update and install essential packages
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
# Python 3.11 and pip
|
| 10 |
+
software-properties-common \
|
| 11 |
+
python3.11 \
|
| 12 |
+
python3.11-dev \
|
| 13 |
+
python3-pip \
|
| 14 |
+
python3.11-venv \
|
| 15 |
+
# C/C++ compilers and tools
|
| 16 |
+
build-essential \
|
| 17 |
+
gcc \
|
| 18 |
+
g++ \
|
| 19 |
+
make \
|
| 20 |
+
# Java 17 (full JDK)
|
| 21 |
+
openjdk-17-jdk \
|
| 22 |
+
# Version control and utilities
|
| 23 |
+
git \
|
| 24 |
+
curl \
|
| 25 |
+
wget \
|
| 26 |
+
vim \
|
| 27 |
+
# Process monitoring
|
| 28 |
+
procps \
|
| 29 |
+
htop \
|
| 30 |
+
# Clean up
|
| 31 |
+
&& apt-get clean \
|
| 32 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 33 |
+
|
| 34 |
+
# Set Python 3.11 as default python3
|
| 35 |
+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \
|
| 36 |
+
&& update-alternatives --set python3 /usr/bin/python3.11
|
| 37 |
+
|
| 38 |
+
# Set JAVA_HOME
|
| 39 |
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
| 40 |
ENV PATH="$JAVA_HOME/bin:$PATH"
|
| 41 |
|
| 42 |
+
# Create app directory
|
| 43 |
WORKDIR /app
|
| 44 |
|
| 45 |
+
# Create non-root user
|
| 46 |
+
RUN useradd -m -u 1000 -s /bin/bash user && \
|
| 47 |
+
chown -R user:user /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# Give user permissions to create temp directories
|
| 50 |
+
RUN mkdir -p /tmp/code_workspace && \
|
| 51 |
+
chown -R user:user /tmp/code_workspace && \
|
| 52 |
+
chmod 755 /tmp/code_workspace
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# Switch to non-root user
|
| 55 |
USER user
|
| 56 |
+
|
| 57 |
+
# Set user paths
|
| 58 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 59 |
+
ENV PYTHONPATH="/app:$PYTHONPATH"
|
| 60 |
|
| 61 |
+
# Copy requirements first (for better caching)
|
| 62 |
+
COPY --chown=user:user requirements.txt .
|
| 63 |
|
| 64 |
# Install Python dependencies
|
| 65 |
+
RUN pip3 install --no-cache-dir --upgrade pip && \
|
| 66 |
+
pip3 install --no-cache-dir -r requirements.txt
|
| 67 |
|
| 68 |
+
# Copy application files
|
| 69 |
+
COPY --chown=user:user . .
|
| 70 |
|
| 71 |
+
# Verify installations
|
| 72 |
+
RUN echo "=== Version Check ===" && \
|
| 73 |
+
python3 --version && \
|
| 74 |
+
pip3 --version && \
|
| 75 |
+
java -version && \
|
| 76 |
+
javac -version && \
|
| 77 |
+
gcc --version && \
|
| 78 |
+
g++ --version
|
| 79 |
|
| 80 |
# Expose port
|
| 81 |
EXPOSE 7860
|
|
|
|
| 84 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 85 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 86 |
|
| 87 |
+
# Start the application
|
| 88 |
+
CMD ["python3", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|