Files
office_translator/docker/backend/Dockerfile
sepehr ce8e150a61 feat: homelab deployment - NPM + IONOS DNS + monitoring + NAS backup
- Restructured docker-compose for Nginx Proxy Manager (no custom nginx)
- Added domain wordly.art configuration
- Added Prometheus + Grafana monitoring stack with pre-configured dashboards
- Added PostgreSQL backup script to NAS (daily/weekly/monthly rotation)
- Added alert rules for backend, system, and Docker metrics
- Updated deployment guide for NPM + IONOS DNS homelab setup
- Added marketing plan document
- PDF translator and watermark support
- Enhanced middleware, routes, and translator modules

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 11:43:28 +02:00

79 lines
2.1 KiB
Docker

# Document Translation API - Backend Dockerfile
# Multi-stage build for optimized production image
FROM python:3.12-slim AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libmagic1 \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt .
# Create virtual environment and install dependencies
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Production stage
FROM python:3.12-slim AS production
WORKDIR /app
# Install runtime dependencies + LibreOffice headless (required for DOCX→PDF)
RUN apt-get update && apt-get install -y --no-install-recommends \
libmagic1 \
libpq5 \
curl \
fonts-noto \
fonts-noto-cjk \
fonts-noto-cjk-extra \
libreoffice-writer-nogui \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create non-root user with a proper home directory (LibreOffice needs it)
RUN groupadd -r translator && \
useradd -r -g translator -m -d /home/translator translator && \
mkdir -p /home/translator/.cache && \
chown -R translator:translator /home/translator
# Create necessary directories
RUN mkdir -p /app/uploads /app/outputs /app/logs /app/temp \
&& chown -R translator:translator /app
# Copy application code
COPY --chown=translator:translator . .
# Make entrypoint executable
RUN chmod +x docker/backend/entrypoint.sh
# Switch to non-root user
USER translator
# Environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=8000 \
WORKERS=4
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${PORT}/health || exit 1
# Expose port
EXPOSE ${PORT}
# Use entrypoint script to handle migrations and startup
ENTRYPOINT ["docker/backend/entrypoint.sh"]