-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (61 loc) · 1.92 KB
/
Dockerfile
File metadata and controls
75 lines (61 loc) · 1.92 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
# Multi-stage Docker build for Droidit ML security platform
FROM python:3.11-slim as builder
# Build dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
make \
libffi-dev \
libssl-dev \
git \
build-essential \
wget \
unzip \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy requirements and install dependencies
COPY requirements.txt /tmp/
RUN pip install --no-cache-dir --upgrade pip wheel && \
pip install --no-cache-dir -r /tmp/requirements.txt
# Production stage
FROM python:3.11-slim as production
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -r droidit \
&& useradd -r -g droidit -d /app -s /bin/bash droidit
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create application directories
WORKDIR /app
RUN mkdir -p data/models data/features data/labels data/reports secrets logs plugins \
&& chown -R droidit:droidit /app
# Copy application code
COPY --chown=droidit:droidit . .
# Set environment variables
ENV PYTHONPATH=/app \
DROIDIT_MODEL_PATH=/app/data/models \
DROIDIT_FEATURE_DIR=/app/data/features \
DROIDIT_LABEL_DIR=/app/data/labels \
DROIDIT_REPORT_DIR=/app/data/reports \
DROIDIT_LOG_LEVEL=INFO \
DROIDIT_ENABLE_METRICS=1 \
DROIDIT_FEEDBACK_ENABLED=1 \
DROIDIT_ENABLE_SHAP=1 \
DROIDIT_RATE_LIMIT_PER_MINUTE=100 \
DROIDIT_ENVIRONMENT=prod
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Switch to non-root user
USER droidit
# Expose port
EXPOSE 8000
# Default command
CMD ["uvicorn", "droidit.api.server:app", "--host", "0.0.0.0", "--port", "8000"]