-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
202 lines (171 loc) · 4.79 KB
/
Dockerfile
File metadata and controls
202 lines (171 loc) · 4.79 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Multi-stage Dockerfile for QuData LLM Processing System
# Optimized for production deployment with security and performance considerations
# Build stage - Install dependencies and build the application
FROM python:3.11-slim AS builder
# Set build arguments
ARG BUILD_DATE
ARG VERSION
ARG VCS_REF
# Add metadata labels
LABEL maintainer="Qubase Team" \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="QuData" \
org.label-schema.description="LLM Data Processing System" \
org.label-schema.version=$VERSION \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.schema-version="1.0"
# Install system build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
libpq-dev \
libxml2-dev \
libxslt1-dev \
libffi-dev \
libssl-dev \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Upgrade pip and install wheel
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
# Copy project metadata and source for editable install
COPY pyproject.toml ./
COPY requirements.txt* ./
COPY README.md ./
COPY src/ ./src/
# Install dependencies and package (editable)
RUN pip install --no-cache-dir -e . && \
pip install --no-cache-dir gunicorn uvicorn[standard] && \
pip cache purge
# Production stage - Create the final runtime image
FROM python:3.11-slim AS production
# Install runtime system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
# Database clients
libpq5 \
# Shell and networking utilities required by entrypoint
bash \
netcat-openbsd \
# OCR dependencies
tesseract-ocr \
tesseract-ocr-eng \
tesseract-ocr-fra \
tesseract-ocr-deu \
tesseract-ocr-spa \
libtesseract5 \
# Image processing
libopencv-dev \
# XML processing
libxml2 \
libxslt1.1 \
# Network tools
curl \
wget \
# Process management
supervisor \
# Utilities
jq \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy virtual environment from builder stage
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create non-root user for security
RUN groupadd -r qudata && useradd -r -g qudata -d /app -s /bin/bash qudata
# Set working directory
WORKDIR /app
# Copy application code with proper ownership
COPY --chown=qudata:qudata . .
# Install QuData in development mode
RUN pip install --no-cache-dir -e .
# Create necessary directories with proper permissions
RUN mkdir -p \
data/raw \
data/staging \
data/processed \
data/exports \
logs \
tmp \
configs/templates \
&& chown -R qudata:qudata /app \
&& chmod -R 755 /app \
&& chmod -R 777 /app/data \
&& chmod -R 777 /app/logs \
&& chmod -R 777 /app/tmp
# Copy configuration files
COPY --chown=qudata:qudata configs/ configs/
# Copy supervisor configuration
COPY --chown=qudata:qudata docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Copy entrypoint script
COPY --chown=qudata:qudata docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Set environment variables
ENV PYTHONPATH=/app \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
QUDATA_CONFIG_PATH=/app/configs \
QUDATA_DATA_PATH=/app/data \
QUDATA_LOG_PATH=/app/logs \
QUDATA_TEMP_PATH=/app/tmp \
# Performance settings
WORKERS=4 \
MAX_WORKERS=8 \
BATCH_SIZE=100 \
MAX_MEMORY=4GB \
# Security settings
QUDATA_SECRET_KEY="" \
# Database settings
DB_HOST=localhost \
DB_PORT=5432 \
DB_NAME=qudata \
DB_USER=qudata \
DB_PASSWORD="" \
# Redis settings
REDIS_URL=redis://localhost:6379/0 \
# API settings
API_HOST=0.0.0.0 \
API_PORT=8000 \
# Logging
LOG_LEVEL=INFO
# Expose ports
EXPOSE 8000 8001 8080
# 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 qudata
# Set entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# Default command - can be overridden
CMD ["api"]
# Development stage - For development with hot reload
FROM production AS development
# Switch back to root to install dev dependencies
USER root
# Install development tools
RUN pip install --no-cache-dir \
pytest \
pytest-cov \
pytest-asyncio \
black \
flake8 \
mypy \
fitz \
pre-commit \
jupyter \
ipython
# Install additional development system packages
RUN apt-get update && apt-get install -y --no-install-recommends \
vim \
nano \
htop \
tree \
&& rm -rf /var/lib/apt/lists/*
# Switch back to qudata user
USER qudata
# Override default command for development
CMD ["api", "--reload"]