Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (57 loc) · 2.52 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (57 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Agri-Intelligence platform — container image.
# Works for: local `docker compose up`, CI, and Hugging Face Spaces (Docker SDK).
# HF Spaces reads `app_port: 8000` from README.md and runs this image as uid 1000.
FROM python:3.11-slim
# System libs needed by lightgbm / shap / numpy / torch wheels.
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 curl \
&& rm -rf /var/lib/apt/lists/*
# Non-root user (required/recommended by Hugging Face Spaces) + writable caches.
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
MPLCONFIGDIR=/home/user/.cache/matplotlib \
TORCH_HOME=/home/user/.cache/torch \
PYTHONUNBUFFERED=1 \
# Single-threaded OpenMP: torch + lightgbm + sklearn each bundle an OpenMP
# runtime; this avoids a native init-order crash when loaded in one process,
# and is correct for single-request inference workers.
OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 KMP_DUPLICATE_LIB_OK=TRUE
WORKDIR /app
# CPU-only PyTorch FIRST — avoids the ~2 GB CUDA download and keeps the image
# small enough for free hosts. Pinned to the versions the models were saved with.
RUN pip install --no-cache-dir \
torch==2.2.1 torchvision==0.17.1 \
--index-url https://download.pytorch.org/whl/cpu
# Remaining deps (torch/torchvision already satisfied above, so not re-downloaded).
COPY api/requirements.txt ./api/requirements.txt
RUN pip install --no-cache-dir -r api/requirements.txt
# Application code + model/data artifacts the pipelines load at runtime.
# (.dockerignore excludes only training images + the raw price xlsx.)
COPY api ./api
COPY models ./models
COPY data ./data
COPY vision ./vision
COPY yield_pred ./yield_pred
COPY weather ./weather
COPY irrigation ./irrigation
COPY fertilizer ./fertilizer
COPY profit ./profit
COPY carbon ./carbon
COPY market ./market
COPY schemes ./schemes
COPY assistant ./assistant
COPY dashboards ./dashboards
COPY twin ./twin
COPY scripts ./scripts
COPY conftest.py pytest.ini ./
# Hand ownership to the non-root user (covers app code + cache dirs).
RUN mkdir -p /home/user/.cache && chown -R user:user /app /home/user
USER user
# The assistant needs an LLM key at runtime — pass it in, never bake it in:
# docker run -e NVIDIA_API_KEY=... -p 8000:8000 agri-intelligence
# (on HF Spaces, set NVIDIA_API_KEY as a Space secret)
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s \
CMD curl -fsS http://localhost:8000/health || exit 1
CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000"]