File size: 1,619 Bytes
a60c0af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6662114
a60c0af
 
 
6662114
 
 
a60c0af
 
 
 
 
 
00fc696
 
7f51e41
a60c0af
 
 
 
 
 
 
 
00fc696
 
4c6e259
00fc696
 
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
# ============================================
# Stage 1: Build Frontend
# ============================================
FROM node:20-alpine AS frontend-builder

WORKDIR /app/frontend

# Copy package files
COPY frontend/package*.json ./

# Install dependencies
RUN npm ci

# Copy frontend source
COPY frontend/ ./

# Set API base URL to same origin (relative path)
ENV VITE_API_BASE_URL=""

# Build frontend
RUN npm run build

# ============================================
# Stage 2: Python Backend + Serve Frontend
# ============================================
FROM python:3.12-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy backend source code and pyproject.toml
COPY backend/pyproject.toml ./
COPY backend/src/ ./src/

# Install Python dependencies
RUN pip install --no-cache-dir .

# Copy built frontend to serve as static files
COPY --from=frontend-builder /app/frontend/dist ./static

# Set working directory to src for imports
WORKDIR /app/src

# Create notes directory with proper permissions for HF Spaces (runs as non-root user)
RUN mkdir -p /app/src/notes && chmod 777 /app/src/notes

# Expose port 7860 (Hugging Face Spaces default)
EXPOSE 7860

# Environment variables (will be overridden by HF Secrets)
ENV HOST=0.0.0.0
ENV PORT=7860
ENV CORS_ORIGINS="*"

# Use absolute path for notes workspace
ENV NOTES_WORKSPACE="/app/src/notes"

# Start the application (ensure notes dir exists at runtime)
CMD mkdir -p /app/src/notes && python -m uvicorn main:app --host 0.0.0.0 --port 7860