-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.cpu
More file actions
74 lines (56 loc) · 2.32 KB
/
Dockerfile.cpu
File metadata and controls
74 lines (56 loc) · 2.32 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
# CPU-Only Dockerfile (No GPU required)
# --- Builder Stage ---
FROM python:3.11-slim AS builder
# Set DEBIAN_FRONTEND to noninteractive to avoid prompts during apt-get install
ENV DEBIAN_FRONTEND=noninteractive
# Install system dependencies
RUN apt-get update && apt-get install -y \
tesseract-ocr \
aria2 \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy the uv binary for fast package installation
COPY --from=ghcr.io/astral-sh/uv:0.2.9 /uv /usr/local/bin/
# Create and activate a virtual environment
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Copy your requirements file
COPY requirements.txt .
# Install Python dependencies using uv (CPU-only versions)
RUN --mount=type=cache,target=/root/.cache/uv \
echo "Installing Python packages..." && \
uv pip install -r requirements.txt && \
echo "Python packages installed successfully"
# Download NLTK data with progress indication
RUN echo "Downloading NLTK data packages..." && \
python3 -c "import nltk; \
print('Downloading punkt...'); nltk.download('punkt', quiet=False); \
print('Downloading stopwords...'); nltk.download('stopwords', quiet=False); \
print('Downloading averaged_perceptron_tagger...'); nltk.download('averaged_perceptron_tagger', quiet=False); \
print('Downloading maxent_ne_chunker...'); nltk.download('maxent_ne_chunker', quiet=False); \
print('Downloading words...'); nltk.download('words', quiet=False); \
print('All NLTK data downloaded successfully')"
# --- Final Stage ---
FROM python:3.11-slim AS final
ENV DEBIAN_FRONTEND=noninteractive
# Install only the runtime system dependencies
RUN apt-get update && apt-get install -y \
tesseract-ocr \
aria2 \
&& rm -rf /var/lib/apt/lists/*
# Copy the virtual environment with installed packages from the builder stage
COPY --from=builder /opt/venv /opt/venv
# Copy the application code
COPY ./api /app/api
# Set the working directory
WORKDIR /app
# Make the virtual environment's binaries available
ENV PATH="/opt/venv/bin:$PATH"
# Set environment for CPU-only operation
ENV CUDA_VISIBLE_DEVICES=""
ENV OMP_NUM_THREADS=4
# Expose the port the app runs on
EXPOSE 8000
# Command to run the CPU-only FastAPI application
CMD ["python3", "-m", "uvicorn", "api.main_cpu:app", "--host", "0.0.0.0", "--port", "8000"]