KSvend Claude Happy commited on
Commit
06a727e
·
1 Parent(s): 194479a

fix: optimize Dockerfile layer caching and add .dockerignore

Browse files

Separate dependency install from app code so code changes don't retrigger
full pip install. Add .dockerignore to exclude .git, tests, and results
from build context.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>

Files changed (2) hide show
  1. .dockerignore +10 -0
  2. Dockerfile +26 -6
.dockerignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ .git
2
+ .github
3
+ results
4
+ tests
5
+ docs
6
+ __pycache__
7
+ *.pyc
8
+ *.db
9
+ *.egg-info
10
+ .pytest_cache
Dockerfile CHANGED
@@ -2,22 +2,42 @@ FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
 
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  libgeos-dev \
7
  libproj-dev \
8
  proj-data \
9
  proj-bin \
 
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # Install dependencies as binary wheels (fast, no compilation)
13
  COPY pyproject.toml .
14
- COPY app/__init__.py app/__init__.py
15
- RUN pip install --no-cache-dir --only-binary :all: \
16
- numpy scipy matplotlib cartopy geopandas shapely pyproj rioxarray xarray \
17
- && pip install --no-cache-dir .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- # Copy application code
20
  COPY app/ app/
 
 
 
21
  COPY frontend/ frontend/
22
 
23
  RUN mkdir -p data results
 
2
 
3
  WORKDIR /app
4
 
5
+ # System libs for GEOS/PROJ (required by cartopy, geopandas, pyproj)
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
7
  libgeos-dev \
8
  libproj-dev \
9
  proj-data \
10
  proj-bin \
11
+ g++ \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Layer 1: Install ALL dependencies (cached unless pyproject.toml changes)
15
  COPY pyproject.toml .
16
+ RUN pip install --no-cache-dir --prefer-binary \
17
+ "fastapi>=0.110.0" \
18
+ "uvicorn[standard]>=0.27.0" \
19
+ "aiosqlite>=0.20.0" \
20
+ "pydantic>=2.6.0" \
21
+ "httpx>=0.27.0" \
22
+ "pystac-client>=0.7.0" \
23
+ "stackstac>=0.5.0" \
24
+ "xarray>=2024.1.0" \
25
+ "numpy>=1.24.0" \
26
+ "rioxarray>=0.15.0" \
27
+ "geopandas>=0.14.0" \
28
+ "shapely>=2.0.0" \
29
+ "pyproj>=3.6.0" \
30
+ "matplotlib>=3.8.0" \
31
+ "cartopy>=0.22.0" \
32
+ "reportlab>=4.1.0" \
33
+ "scipy>=1.12.0" \
34
+ "tqdm>=4.66.0"
35
 
36
+ # Layer 2: Install app package (no-deps, just makes app/ importable)
37
  COPY app/ app/
38
+ RUN pip install --no-cache-dir --no-deps .
39
+
40
+ # Layer 3: Frontend (changes most often, cached separately)
41
  COPY frontend/ frontend/
42
 
43
  RUN mkdir -p data results