reduced image size
This commit is contained in:
parent
c4f03ebc2f
commit
98bfc95f5c
26
Dockerfile
26
Dockerfile
|
|
@ -1,25 +1,25 @@
|
||||||
# Build stage - install dependencies
|
# Stage 1: Install dependencies
|
||||||
FROM python:3.11-slim AS builder
|
FROM python:3.11-slim AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install Python dependencies to a virtual environment
|
# Install Python packages
|
||||||
# (Most packages have pre-built wheels for amd64, no compilation needed!)
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN python -m venv /opt/venv && \
|
RUN pip install --no-cache-dir --upgrade pip && \
|
||||||
/opt/venv/bin/pip install --no-cache-dir --upgrade pip && \
|
pip install --no-cache-dir --prefix=/install -r requirements.txt && \
|
||||||
/opt/venv/bin/pip install --no-cache-dir -r requirements.txt
|
# Clean up unnecessary files to reduce image size
|
||||||
|
find /install -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
|
||||||
|
find /install -type f -name "*.pyc" -delete && \
|
||||||
|
find /install -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
|
||||||
|
find /install -type d -name "*.dist-info" -exec rm -rf {}/RECORD {} + 2>/dev/null || true
|
||||||
|
|
||||||
# Final stage - minimal runtime image (no build tools!)
|
# Stage 2: Final minimal image
|
||||||
FROM python:3.11-slim
|
FROM python:3.11-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy only the virtual environment from builder (no bloat!)
|
# Copy only installed packages (no pip cache, no build artifacts)
|
||||||
COPY --from=builder /opt/venv /opt/venv
|
COPY --from=builder /install /usr/local
|
||||||
|
|
||||||
# Use the virtual environment
|
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
|
||||||
|
|
||||||
# Copy application files
|
# Copy application files
|
||||||
COPY backend ./backend
|
COPY backend ./backend
|
||||||
|
|
@ -35,7 +35,7 @@ RUN mkdir -p data/notes data/search_index
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=60s --timeout=3s --start-period=5s --retries=3 \
|
||||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue