refactor: [30388f42] Verschlanke Company-Explorer Dockerfile

- Implementierung von Multi-Stage-Builds mit Fokus auf minimales Runtime-Image.
- Nutzung von --no-install-recommends und aggressive Bereinigung von apt-Caches.
- Entfernung von Test-Dateien und Build-Tools aus dem finalen Image.
- Deaktivierung des uvicorn Auto-Reloads für stabilere Produktion-Umgebung.
This commit is contained in:
2026-03-06 15:12:30 +00:00
parent d4140d04b4
commit 526ac54093

View File

@@ -1,33 +1,49 @@
# --- STAGE 1: Build Frontend ---
FROM node:20-slim AS frontend-builder
WORKDIR /build
# Use --no-cache and clear npm cache to keep this layer small if needed,
# although it's a build stage.
COPY frontend/package*.json ./
RUN npm install
RUN npm install --no-audit --no-fund
COPY frontend/ ./
RUN grep "ROBOTICS EDITION" src/App.tsx || echo "Version string not found in App.tsx"
RUN npm run build
# --- STAGE 2: Backend Builder ---
FROM python:3.11-slim AS backend-builder
WORKDIR /app
RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
# Install only the bare essentials for building Python wheels
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential gcc && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt
# Install to /install to easily copy to final stage
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# --- STAGE 3: Final Runtime ---
FROM python:3.11-slim
WORKDIR /app
# Copy only installed packages from backend-builder
COPY --from=backend-builder /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH
# Set non-interactive to avoid prompts
ENV DEBIAN_FRONTEND=noninteractive
# Copy Built Frontend from Stage 1 (To a safe location outside /app)
# Minimal runtime system dependencies (if any are ever needed)
# Currently none identified from requirements.txt that need system libs on slim
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy only the installed Python packages
COPY --from=backend-builder /install /usr/local
ENV PATH=/usr/local/bin:$PATH
# Copy Built Frontend
COPY --from=frontend-builder /build/dist /frontend_static
# Copy Backend Source
# Copy only necessary Backend Source
COPY backend ./backend
COPY backend/tests /app/backend/tests
# Environment Variables
ENV PYTHONPATH=/app
@@ -36,5 +52,5 @@ ENV PYTHONUNBUFFERED=1
# Expose Port
EXPOSE 8000
# Start FastAPI
CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
# Start FastAPI (Production mode without --reload)
CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "8000"]