File size: 2,156 Bytes
b64de39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75fda81
 
b64de39
75fda81
b64de39
 
 
 
 
 
 
 
 
 
 
 
 
75fda81
 
 
 
 
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
69
70
71
# FarmHelp - Hugging Face Spaces Docker
# Multi-stage: build frontend, then run backend + static SPA on port 7860

# ---------------------------------------------------------------------------
# Stage 1: Frontend build (Vite + React)
# ---------------------------------------------------------------------------
FROM node:20-alpine AS frontend

WORKDIR /app/frontend

COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci

COPY frontend/ ./

# Same-origin API in production (backend serves both API and static)
ENV VITE_API_BASE_URL=""
RUN npm run build

# ---------------------------------------------------------------------------
# Stage 2: Backend + static files
# ---------------------------------------------------------------------------
FROM python:3.10-slim

WORKDIR /app/backend

# System deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    && rm -rf /var/lib/apt/lists/*

# Python dependencies
COPY backend/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# Backend application
COPY backend/ ./

# Frontend build from stage 1
COPY --from=frontend /app/frontend/dist /app/static

# ---------------------------------------------------------------------------
# Environment variables (Hugging Face / production)
# Override via HF Space Secrets or Docker run -e if needed.
# ---------------------------------------------------------------------------
ENV PORT=7860
ENV ENVIRONMENT=production
ENV STATIC_DIR=/app/static
# Database URL will be set by start.sh based on available storage
ENV DATABASE_URL=sqlite:////app/backend/farmhelp.db
ENV LOG_LEVEL=INFO
ENV LOG_FILE=/app/backend/logs/app.log
ENV RATE_LIMIT_PER_MINUTE=60
ENV WEATHER_CACHE_HOURS=6
ENV MANDI_CACHE_HOURS=24
ENV CORS_ORIGINS='["*"]'
ENV OPEN_METEO_API_URL=https://api.open-meteo.com/v1/forecast
ENV DATA_GOV_IN_API_URL=https://api.data.gov.in/resource
ENV DATA_GOV_IN_API_KEY=""
ENV DEBUG=false
ENV APP_NAME="Farm Help API"
ENV APP_VERSION=1.0.0

EXPOSE 7860

# Make startup script executable (already copied with backend/)
RUN chmod +x /app/backend/start.sh

# Run startup script
CMD ["/app/backend/start.sh"]