perf: docker + next.js build optimisation - dockerignore exclusions, BuildKit cache mounts, backend image reuse, memory limits, next.js bundle tree-shaking

This commit is contained in:
2026-09-20 12:03:58 +05:30
parent fee57e154b
commit 896073ea2d
6 changed files with 317 additions and 170 deletions

View File

@@ -1,14 +1,28 @@
# ═══════════════════════════════════════════════════════════════════════════
# PragatiVeer Backend – Python 3.11 slim
# Optimised for fast re-builds:
# • requirements.txt copied FIRST → pip cache layer is only invalidated
# when dependencies change, not on every source-code edit.
# • BuildKit pip cache mount keeps wheel cache on host between builds.
# ═══════════════════════════════════════════════════════════════════════════
FROM python:3.11-slim
# Install system deps in a single RUN layer, clean apt cache immediately
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# ── Dependencies first (most stable layer) ──────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Use BuildKit pip cache so wheels are reused across builds
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-cache-dir -r requirements.txt
# ── Source code (changes frequently; comes last) ─────────────────────────────
COPY . .
EXPOSE 8000