blob: c01ad0419c54d5478e3b02872f982c9a6af41aa7 [file] [log] [blame]
Marc Kupietz9baa27a2025-11-29 15:32:16 +01001# Slim version without GermaLemma (saves ~180MB)
2# Multi-stage Docker build for size optimization
3FROM python:3.12-slim-bookworm AS builder
4
5# Install build dependencies
6RUN apt-get update && apt-get install -y \
7 gcc \
8 g++ \
9 && rm -rf /var/lib/apt/lists/*
10
11# Set environment variables
12ENV PIP_CACHE_DIR="/tmp/.cache/pip" \
13 PYTHONPATH="PYTHONPATH:."
14ENV VIRTUAL_ENV=/app/venv
15ENV PATH="$VIRTUAL_ENV/bin:$PATH"
16
17# Set the working directory and copy requirements
18WORKDIR /app
19
20# Install Python dependencies WITHOUT germalemma
21RUN python -m venv venv
22RUN venv/bin/pip install --upgrade pip wheel thinc spacy
23
24# Production stage
25FROM python:3.12-slim-bookworm AS production
26
27# Install minimal runtime dependencies
28RUN apt-get update && apt-get install -y \
29 wget \
30 coreutils \
31 && rm -rf /var/lib/apt/lists/* \
32 && apt-get clean
33
34# Add non-root user FIRST (before copying files)
35RUN groupadd -r appuser && useradd -r -g appuser appuser
36
37# Copy virtual environment from builder and set ownership immediately
38COPY --from=builder --chown=appuser:appuser /app/venv /app/venv
39
40# Copy application code with correct ownership
41COPY --chown=appuser:appuser lib /app/lib
42COPY --chown=appuser:appuser systems /app/systems
43COPY --chown=appuser:appuser my_utils /app/my_utils
44COPY --chown=appuser:appuser download_with_progress.py /app/download_with_progress.py
45COPY --chown=appuser:appuser list_spacy_models.py /app/list_spacy_models.py
46COPY --chown=appuser:appuser docker-entrypoint.sh /docker-entrypoint.sh
47
48# Set environment variables
49ENV VIRTUAL_ENV=/app/venv
50ENV PATH="$VIRTUAL_ENV/bin:$PATH"
51ENV PYTHONPATH="PYTHONPATH:."
52
53# spaCy processing configuration - GermaLemma disabled by default
54ENV SPACY_USE_DEPENDENCIES="True"
55ENV SPACY_USE_GERMALEMMA="False"
56ENV SPACY_PARSE_TIMEOUT="30"
57ENV SPACY_MAX_SENTENCE_LENGTH="500"
58ENV SPACY_N_PROCESS="10"
59ENV SPACY_BATCH_SIZE="2000"
60ENV SPACY_CHUNK_SIZE="20000"
61
62WORKDIR /app
63
64# Create directories with correct ownership
65RUN mkdir -p "/app/logs" "/app/tmp" "/local/models" && \
66 chown -R appuser:appuser "/app/logs" "/app/tmp" "/local/models" && \
67 chmod +x /docker-entrypoint.sh && \
68 chmod +x /app/download_with_progress.py && \
69 chmod +x /app/list_spacy_models.py
70
71# Set temp directories to use app directory instead of system /tmp
72ENV TMPDIR="/app/tmp"
73ENV TEMP="/app/tmp"
74ENV TMP="/app/tmp"
75
76# Switch to non-root user
77USER appuser
78
79# Define the entry point
80ENTRYPOINT ["/docker-entrypoint.sh"]