-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (46 loc) · 1.51 KB
/
Dockerfile
File metadata and controls
63 lines (46 loc) · 1.51 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
# Multi-stage Dockerfile for Edge Anomaly Detection
# Optimized for production deployment
# Stage 1: Base image with Python and dependencies
FROM python:3.10-slim as base
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
git \
wget \
&& rm -rf /var/lib/apt/lists/*
# Stage 2: Build dependencies
FROM base as builder
# Copy requirements
COPY requirements.txt .
# Install Python dependencies
RUN pip install --user --no-warn-script-location -r requirements.txt
# Stage 3: Runtime image
FROM base as runtime
# Copy Python dependencies from builder
COPY --from=builder /root/.local /root/.local
# Make sure scripts in .local are usable
ENV PATH=/root/.local/bin:$PATH
# Copy application code
COPY . /app
# Install package
RUN pip install --no-deps -e .
# Create necessary directories
RUN mkdir -p /app/data /app/exports /app/checkpoints /app/logs
# Expose ports
EXPOSE 8000
EXPOSE 9090
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
# Default command (can be overridden)
CMD ["python", "api/app.py"]
# Alternative commands for different services:
# Training: CMD ["python", "train.py"]
# Inference: CMD ["python", "inference.py", "--model", "exports/model.onnx", "--backend", "onnx"]