-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (46 loc) · 1.87 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (46 loc) · 1.87 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
# ==========================================
# Stage 1: Build the React Frontend
# ==========================================
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
# Copy frontend config files and install dependencies
COPY frontend/package*.json ./
RUN npm ci
# Copy frontend source files and build
COPY frontend/ ./
RUN npm run build
# ==========================================
# Stage 2: Create the Python Runner
# ==========================================
FROM python:3.11-slim AS backend-runner
USER root
WORKDIR /app
# Install system dependencies (Tesseract, OpenCV/graphics libraries) with retry logic for network resilience
RUN apt-get clean && \
(apt-get update || (sleep 5 && apt-get update)) && \
apt-get install -y --no-install-recommends \
tesseract-ocr \
libgl1 \
libglib2.0-0 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy backend requirements and install
COPY image-to-psd-backend/requirements.txt ./
RUN pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu
RUN pip install --no-cache-dir -r requirements.txt
# Copy backend source code
COPY image-to-psd-backend/ ./
# Copy built frontend static assets from Stage 1 into the backend's static directory
COPY --from=frontend-builder /app/frontend/dist ./static
# Ensure outputs directory exists and is writable by any user
RUN mkdir -p outputs && chmod 777 outputs
# Set writable cache directories for AI models (rembg, EasyOCR, torch)
ENV U2NET_HOME=/tmp/.u2net \
EASYOCR_MODULE_PATH=/tmp/.EasyOCR \
TORCH_HOME=/tmp/.torch \
NUMBA_CACHE_DIR=/tmp
# Expose server port (FastAPI default, overridden dynamically by cloud hosts via $PORT)
EXPOSE 7860
ENV PORT=7860
# Start server using Uvicorn directly to prevent worker watchdog timeout kills during heavy CPU tasks
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT}"]