103 lines
3.1 KiB
Docker
103 lines
3.1 KiB
Docker
# Multi-Stage Dockerfile für MYP (Manage Your Printers) System
|
|
# Mercedes-Benz TBA Marienfelde - 3D-Drucker-Management
|
|
|
|
# ===== STAGE 1: Python Dependencies Builder =====
|
|
FROM python:3.11-slim-bullseye as python-builder
|
|
|
|
LABEL maintainer="Till Tomczak <till.tomczak@mercedes-benz.com>"
|
|
LABEL description="MYP - 3D Printer Management System for Mercedes-Benz"
|
|
LABEL version="1.0"
|
|
|
|
# Build-Dependencies installieren
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
gcc \
|
|
python3-dev \
|
|
libffi-dev \
|
|
libssl-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Python-Dependencies in virtuelle Umgebung installieren
|
|
RUN python -m venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Requirements kopieren und installieren
|
|
COPY backend/requirements.txt /tmp/requirements.txt
|
|
RUN pip install --upgrade pip wheel setuptools && \
|
|
pip install --no-cache-dir -r /tmp/requirements.txt
|
|
|
|
# ===== STAGE 2: Node.js Builder für Frontend-Assets =====
|
|
FROM node:18-slim as node-builder
|
|
|
|
# Frontend-Dependencies und Build
|
|
WORKDIR /app
|
|
COPY backend/package*.json ./
|
|
|
|
# Versuche npm install, aber ignoriere Fehler für einfaches Setup
|
|
RUN npm ci --only=production 2>/dev/null || npm install --only=production 2>/dev/null || echo "NPM install übersprungen"
|
|
RUN npm cache clean --force 2>/dev/null || true
|
|
|
|
# TailwindCSS Build - mit Fallback
|
|
COPY backend/static ./static/
|
|
COPY backend/templates ./templates/
|
|
RUN npm run build:css 2>/dev/null || echo "✅ CSS Build übersprungen - verwende Standard-CSS"
|
|
|
|
# ===== STAGE 3: Production Runtime =====
|
|
FROM python:3.11-slim-bullseye as production
|
|
|
|
# Umgebungsvariablen
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV FLASK_ENV=production
|
|
ENV MYP_ENV=production
|
|
ENV PYTHONPATH=/app
|
|
|
|
# System-Dependencies für Production
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
curl \
|
|
iputils-ping \
|
|
sqlite3 \
|
|
openssl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Arbeitsverzeichnis erstellen
|
|
WORKDIR /app
|
|
|
|
# Python virtuelle Umgebung kopieren
|
|
COPY --from=python-builder /opt/venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Frontend-Assets kopieren
|
|
COPY --from=node-builder /app/static/ /app/static/
|
|
|
|
# Anwendungs-Code kopieren
|
|
COPY backend/ /app/
|
|
|
|
# Verzeichnisse für Logs, Uploads, Database, etc. erstellen
|
|
RUN mkdir -p /app/logs /app/uploads /app/static/uploads /app/instance /app/database && \
|
|
chmod -R 755 /app/logs /app/uploads /app/static/uploads /app/instance /app/database
|
|
|
|
# SSL-Zertifikate-Verzeichnis erstellen
|
|
RUN mkdir -p /app/ssl && chmod 755 /app/ssl
|
|
|
|
# Benutzer für Security erstellen
|
|
RUN useradd --create-home --shell /bin/bash myp && \
|
|
chown -R myp:myp /app
|
|
|
|
# Ports exposieren
|
|
EXPOSE 80 443 5000
|
|
|
|
# Health Check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD curl -f http://localhost:5000/ || exit 1
|
|
|
|
# Startup-Skript
|
|
COPY docker-entrypoint.sh /usr/local/bin/
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
# Als myp-Benutzer ausführen
|
|
USER myp
|
|
|
|
# Entry Point
|
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
|
CMD ["python", "app.py", "--host=0.0.0.0", "--port=5000"] |