-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (55 loc) · 2.12 KB
/
Dockerfile
File metadata and controls
74 lines (55 loc) · 2.12 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
69
70
71
72
73
74
# Dockerfile for Google Cloud Run
# Builds both React frontend and Python backend in a single container
# Stage 1: Build React frontend
FROM node:20-slim AS frontend-builder
WORKDIR /app/frontend
# Firebase config build args (public values, baked into JS bundle by Vite)
ARG VITE_FIREBASE_API_KEY
ARG VITE_FIREBASE_AUTH_DOMAIN
ARG VITE_FIREBASE_PROJECT_ID
ARG VITE_FIREBASE_STORAGE_BUCKET
ARG VITE_FIREBASE_MESSAGING_SENDER_ID
ARG VITE_FIREBASE_APP_ID
# Copy package files
COPY frontend/package*.json ./
# Install dependencies
RUN npm ci
# Copy frontend source
COPY frontend/ ./
# Build production bundle (Vite reads VITE_* from env at build time)
RUN npm run build
# Stage 2: Python runtime
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies
# Note: pillow-heif bundles its own libheif, no system package needed
# Using libgl1 (not libgl1-mesa-glx) for newer Debian versions
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Copy Python requirements
COPY backend/requirements.txt ./
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Pre-download CLIP model during build (caches in image)
RUN python -c "from transformers import CLIPModel, CLIPProcessor; \
CLIPModel.from_pretrained('openai/clip-vit-base-patch32'); \
CLIPProcessor.from_pretrained('openai/clip-vit-base-patch32'); \
print('✅ CLIP model pre-downloaded')"
# Copy backend source
COPY backend/app ./app
COPY backend/reference_art ./reference_art
# Copy built frontend from previous stage
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PORT=8080
# Expose port (Cloud Run uses 8080 by default)
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/api/health')" || exit 1
# Run the application - Cloud Run sets PORT env variable
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8080}"]