-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
104 lines (87 loc) · 2.82 KB
/
Dockerfile
File metadata and controls
104 lines (87 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Use Ubuntu 22.04 as base image
FROM ubuntu:22.04
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
# Increase pip timeout and retries for network issues
ENV PIP_DEFAULT_TIMEOUT=120
ENV PIP_RETRIES=5
# Set work directory
WORKDIR /app
# Install system dependencies and add deadsnakes PPA for Python 3.11
RUN apt-get update && apt-get install -y \
software-properties-common \
wget \
curl \
git \
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt-get update \
&& apt-get install -y \
python3.11 \
python3.11-dev \
python3.11-venv \
python3.11-distutils \
python3-pip \
libreoffice \
poppler-utils \
ffmpeg \
build-essential \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
libgcc-s1 \
&& rm -rf /var/lib/apt/lists/*
# Create symlinks for python and pip
RUN ln -sf /usr/bin/python3.11 /usr/bin/python && \
ln -sf /usr/bin/python3.11 /usr/bin/python3
# Install pip for Python 3.11
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
# Install setuptools and wheel with retries
RUN python3.11 -m pip install --no-cache-dir --upgrade pip setuptools wheel \
--timeout 120 --retries 5
# Copy requirements first for better Docker layer caching
COPY requirements.txt pyproject.toml ./
# Install Python dependencies with retries and increased timeout
# Split into chunks to avoid timeout on large packages
RUN python3.11 -m pip install --no-cache-dir \
--timeout 120 --retries 5 \
numpy scipy pandas matplotlib \
&& python3.11 -m pip install --no-cache-dir \
--timeout 120 --retries 5 \
torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu \
|| true
# Install remaining requirements
RUN python3.11 -m pip install --no-cache-dir \
--timeout 120 --retries 5 \
-r requirements.txt \
|| python3.11 -m pip install --no-cache-dir \
--timeout 120 --retries 5 \
--use-deprecated=legacy-resolver \
-r requirements.txt
# Copy the entire project
COPY . .
# Create a non-root user first
RUN useradd --create-home --shell /bin/bash app
# Create necessary directories and set ownership
RUN mkdir -p tmp && \
mkdir -p contents && \
mkdir -p tree_splits && \
mkdir -p assets && \
mkdir -p model_cache && \
chown -R app:app /app
# Set permissions for entrypoint script
RUN chmod +x /app/docker-entrypoint.sh && \
chmod +x /app/start_api.py && \
chmod +x /app/download_models.py
# Switch to non-root user
USER app
# Expose port for FastAPI service
EXPOSE 6025
# Set the entrypoint
ENTRYPOINT ["/app/docker-entrypoint.sh"]
# Default command - run the FastAPI service with startup script
CMD ["python", "/app/start_api.py", "--host", "0.0.0.0", "--port", "6025", "--workers", "1"]