File size: 2,759 Bytes
8d7950f
 
 
 
 
 
 
 
49d2391
 
 
 
 
 
 
 
8d7950f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
efc235a
 
 
8d7950f
 
 
 
 
 
 
 
 
49d2391
 
 
 
 
8d7950f
 
 
 
 
 
 
 
 
cfd01d8
8d7950f
 
 
 
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
# --- Stage 1: Build Frontend ---
FROM node:20-bookworm-slim AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm ci --prefer-offline
COPY frontend/ ./
RUN NODE_OPTIONS="--max-old-space-size=4096" npm run build

# --- Stage 1b: Build Website ---
FROM node:20-bookworm-slim AS website-builder
WORKDIR /app/Website
COPY Website/package*.json ./
RUN npm ci --prefer-offline
COPY Website/ ./
RUN NODE_OPTIONS="--max-old-space-size=4096" npm run build

# --- Stage 2: Build Backend & Final Image ---
FROM python:3.11-slim-bookworm

# Install system dependencies
RUN apt-get update && apt-get install -y \
    nginx \
    curl \
    gnupg \
    redis-server \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

# Set up user for Hugging Face (uid 1000)
RUN useradd -m -u 1000 user
WORKDIR /app

# Copy Backend
COPY --chown=user:user backend/ /app/backend/
# Build-time .env with placeholder values so Pydantic Settings validation passes during pip install.
# All secrets are overridden at runtime via HuggingFace Space Secrets (environment variables).
RUN printf 'DATABASE_URL=sqlite+aiosqlite:///./leadpilot.db\nREDIS_URL=redis://localhost:6379/0\nJWT_SECRET=build_time_placeholder\nJWT_ALGORITHM=HS256\nENCRYPTION_KEY_FERNET=ZmDfcTF7_60GrrY167zsiPd67pEvs0aGOv2oasOM1Pg=\nEMAIL_PROVIDER=console\n' > /app/backend/.env && chown user:user /app/backend/.env
RUN pip install --no-cache-dir -r /app/backend/requirements.txt
# Ensure SQLite DB is writeable by the user
RUN touch /app/backend/leadpilot.db && chown user:user /app/backend/leadpilot.db

# Copy Frontend build from Stage 1
COPY --chown=user:user --from=frontend-builder /app/frontend/.next/standalone /app/frontend/.next/standalone
COPY --chown=user:user --from=frontend-builder /app/frontend/.next/static /app/frontend/.next/standalone/.next/static
COPY --chown=user:user --from=frontend-builder /app/frontend/public /app/frontend/.next/standalone/public

# Copy Website build from Stage 1b
COPY --chown=user:user --from=website-builder /app/Website/.next/standalone /app/Website/.next/standalone
COPY --chown=user:user --from=website-builder /app/Website/.next/static /app/Website/.next/standalone/.next/static
COPY --chown=user:user --from=website-builder /app/Website/public /app/Website/.next/standalone/public

# Copy start script and nginx config
COPY nginx.conf /etc/nginx/nginx.conf
COPY --chown=user:user start.sh /app/start.sh
RUN chmod +x /app/start.sh

# Environment variables
ENV PORT=7860
ENV DATABASE_URL=sqlite+aiosqlite:////app/backend/leadpilot.db
ENV NEXT_PUBLIC_API_BASE_URL=""
ENV APP_BASE_URL=https://ashrafkassem-leadpilot.hf.space

EXPOSE 7860

CMD ["/app/start.sh"]