Files
Brancheneinstufung2/company-explorer/Dockerfile

60 lines
1.8 KiB
Docker

# --- STAGE 1: Build Frontend ---
# This stage uses a more robust, standard pattern for building Node.js apps.
# It creates a dedicated 'frontend' directory inside the container to avoid potential
# file conflicts in the root directory.
FROM node:20-slim AS frontend-builder
WORKDIR /app
# Copy the entire frontend project into a 'frontend' subdirectory
COPY frontend ./frontend
# Set the working directory to the new subdirectory
WORKDIR /app/frontend
# Install dependencies and build the project from within its own directory
RUN npm install --no-audit --no-fund
RUN npm run build
# --- STAGE 2: Backend Builder ---
FROM python:3.11-slim AS backend-builder
WORKDIR /app
# 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 .
# 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
# Set non-interactive to avoid prompts
ENV DEBIAN_FRONTEND=noninteractive
# Minimal runtime system dependencies (if any are ever needed)
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 from the new, correct location
COPY --from=frontend-builder /app/frontend/dist /frontend_static
# Copy only necessary Backend Source
COPY backend ./backend
# Environment Variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
# Expose Port
EXPOSE 8000
# Start FastAPI (Production mode without --reload)
CMD ["uvicorn", "backend.app:app", "--host", "0.0.0.0", "--port", "8000"]