Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
102 lines (84 loc) · 2.74 KB
/
Copy pathDockerfile
File metadata and controls
102 lines (84 loc) · 2.74 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
# Document Manager - Optimized Production Image
# Multi-stage build for minimal final image size
# Stage 1: Build dependencies
FROM python:3.12-slim AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
g++ \
libmagic-dev \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy and install Python dependencies
WORKDIR /build
COPY requirements.txt .
# Upgrade pip and install dependencies
RUN pip install --upgrade pip setuptools wheel && \
pip install --no-cache-dir -r requirements.txt
# Stage 2: Runtime image
FROM python:3.12-slim AS runtime
# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
# Tesseract OCR and languages
tesseract-ocr \
tesseract-ocr-deu \
tesseract-ocr-eng \
# PDF utilities
poppler-utils \
# Image processing libraries
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
libgomp1 \
# File type detection
libmagic1 \
# Health check
curl \
# Clean up
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy Python environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create non-root user with specific UID for consistency
RUN groupadd -r -g 1000 appuser && \
useradd -r -u 1000 -g appuser -m -d /home/appuser -s /bin/bash appuser
# Set working directory
WORKDIR /app
# Copy application code
COPY --chown=appuser:appuser app/ ./app/
COPY --chown=appuser:appuser frontend/ ./frontend/
COPY --chown=appuser:appuser docker-entrypoint.sh ./
# Create necessary directories with correct permissions
RUN mkdir -p data/logs data/staging data/storage data/uploads data/backups && \
chmod +x docker-entrypoint.sh && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Runtime environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app \
# Tesseract and Poppler paths
TESSERACT_PATH=/usr/bin/tesseract \
POPPLER_PATH=/usr/bin \
# Application settings
DATABASE_URL=sqlite:///./data/documents.db \
AI_PROVIDER=openai \
TRUSTED_PROXY_IPS=127.0.0.1
# Add metadata labels
LABEL maintainer="Jannik Reinhard" \
version="1.0.0" \
description="AI-powered document management system" \
org.opencontainers.image.source="https://github.com/JayRHa/document-manager"
# Expose application port
EXPOSE 8000
# Health check with proper timing
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/api/health || exit 1
# Use entrypoint script for initialization
ENTRYPOINT ["/app/docker-entrypoint.sh"]