-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (53 loc) · 1.75 KB
/
Dockerfile
File metadata and controls
70 lines (53 loc) · 1.75 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
# Multi-stage build for optimized production image
FROM python:3.10-slim as builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
# Production stage
FROM python:3.10-slim
WORKDIR /app
# Install runtime dependencies for OpenCV
RUN apt-get update && apt-get install -y --no-install-recommends \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1 \
libgomp1 \
libgl1 \
&& rm -rf /var/lib/apt/lists/*
# Copy Python packages from builder
COPY --from=builder /root/.local /root/.local
# Make sure scripts in .local are usable
ENV PATH=/root/.local/bin:$PATH
# Create cache directories with proper permissions
RUN mkdir -p /app/.cache && chmod -R 777 /app/.cache
# Set environment variables for caching
ENV HF_HOME=/app/.cache/huggingface
ENV HF_DATASETS_CACHE=/app/.cache/datasets
ENV TORCH_HOME=/app/.cache/torch
ENV MPLCONFIGDIR=/app/.cache/matplotlib
# Copy application code
COPY app.py .
COPY config.py .
COPY video_processor.py .
COPY model/ ./model/
# Create non-root user for security (optional but recommended)
# RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
# USER appuser
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8080/health')" || exit 1
# Run with optimized settings
CMD ["uvicorn", "app:app", \
"--host", "0.0.0.0", \
"--port", "8080", \
"--workers", "1", \
"--timeout-keep-alive", "60", \
"--log-level", "info"]