-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
107 lines (81 loc) · 3.36 KB
/
Copy pathDockerfile
File metadata and controls
107 lines (81 loc) · 3.36 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
105
106
107
# syntax=docker/dockerfile:1
# Dockerfile for AVI - Content Safety System
# Multi-stage build for CPU and GPU variants
# =============================================================================
# BASE STAGE - Common dependencies
# =============================================================================
FROM python:3.11-slim AS base
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
TOKENIZERS_PARALLELISM=false
WORKDIR /app
# Install system dependencies with retry and fallback
RUN apt-get update \
&& apt-get install -y --no-install-recommends --fix-missing \
build-essential \
curl \
|| (apt-get clean && apt-get update && apt-get install -y --no-install-recommends --fix-missing build-essential curl) \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and constraints
COPY requirements.txt ./
COPY constraints.txt ./
# Create required directories
RUN mkdir -p data/raw data/processed data/indexes data/feedback data/logs
# =============================================================================
# CPU STAGE - CPU-only inference (default)
# =============================================================================
FROM base AS cpu
ENV DEVICE=cpu
# Install CPU dependencies
RUN pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Set up entrypoint script
RUN chmod +x /app/docker-entrypoint.sh
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/api/v1/health || exit 1
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
# =============================================================================
# GPU STAGE - CUDA-enabled inference
# =============================================================================
FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04 AS gpu
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
TOKENIZERS_PARALLELISM=false \
DEVICE=cuda
WORKDIR /app
# Install Python and system dependencies with retry and fallback
RUN apt-get update \
&& apt-get install -y --no-install-recommends --fix-missing \
python3.11 \
python3.11-venv \
python3-pip \
build-essential \
curl \
|| (apt-get clean && apt-get update && apt-get install -y --no-install-recommends --fix-missing python3.11 python3.11-venv python3-pip build-essential curl) \
&& ln -sf /usr/bin/python3.11 /usr/bin/python \
&& ln -sf /usr/bin/python3.11 /usr/bin/python3 \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
COPY requirements.txt ./
COPY constraints.txt ./
# Install GPU dependencies (PyTorch with CUDA)
RUN pip install --upgrade pip \
&& pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cu121 \
&& pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create required directories
RUN mkdir -p data/raw data/processed data/indexes data/feedback data/logs
# Set up entrypoint script
RUN chmod +x /app/docker-entrypoint.sh
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/api/v1/health || exit 1
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]