-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
85 lines (63 loc) · 2.05 KB
/
Dockerfile
File metadata and controls
85 lines (63 loc) · 2.05 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
# Multi-stage build for Python Stream Processor
# Stage 1: Builder stage with all build dependencies
FROM python:3.12-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
cmake \
make \
libssl-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy project files
COPY pyproject.toml README.md ./
COPY src ./src
COPY main.py ./
# Install uv package manager
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
/root/.local/bin/uv --version
# Add uv to PATH
ENV PATH="/root/.local/bin:${PATH}"
# Install Python dependencies using uv
RUN /root/.local/bin/uv sync --frozen || /root/.local/bin/uv sync
# Stage 2: Runtime image with minimal dependencies
FROM python:3.12-slim as runtime
# Install only runtime dependencies (FFmpeg)
RUN apt-get update && apt-get install -y \
ffmpeg \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy uv binary from builder
COPY --from=builder /root/.local/bin/uv /root/.local/bin/uv
# Copy the entire application and virtual environment from builder
COPY --from=builder /app /app
# Add uv to PATH
ENV PATH="/root/.local/bin:${PATH}"
# Set Python to run in unbuffered mode
ENV PYTHONUNBUFFERED=1
# Environment variables (can be overridden at runtime)
ENV PULSAR_SERVICE_URL=pulsar://pulsar:6650
ENV PULSAR_TOPIC=persistent://streamhub/stream/frames
ENV PULSAR_SUBSCRIPTION=stream-processor
# Storage: {base_path}/client_ids/{client_id}/device_id/{device_id}/frames|hls/
ENV STORAGE_BASE_PATH=/mnt/streamhub/streams
ENV PROCESSING_MAX_WORKERS=50
ENV PROCESSING_SEGMENT_DURATION_SECONDS=30
ENV PROCESSING_FRAMES_PER_SEGMENT=6
ENV PROCESSING_RETENTION_HOURS=24
ENV METRICS_PORT=9090
ENV METRICS_ENABLED=true
# Create base storage directory
RUN mkdir -p /mnt/streamhub/streams
# Expose metrics port
EXPOSE 9090
# Healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD pgrep -f "python main.py" || exit 1
# Run the application
CMD ["uv", "run", "main.py"]