File size: 2,359 Bytes
d5c104e
 
 
 
 
1364348
d5c104e
 
 
 
 
1364348
d5c104e
 
 
 
 
1364348
d5c104e
 
 
 
 
 
 
 
 
1364348
d5c104e
 
 
1364348
d5c104e
1364348
88b2fda
1364348
d5c104e
 
1364348
 
 
 
 
 
 
d5c104e
 
 
 
 
1364348
d5c104e
 
 
 
 
1364348
d5c104e
 
1364348
d5c104e
 
 
1364348
d5c104e
 
 
 
1364348
d5c104e
 
 
 
 
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
# Stage 1: Build the React Frontend
FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Create writable directories
RUN mkdir -p /tmp/huggingface && \
    chmod -R 777 /tmp/huggingface && \
    mkdir -p /app/workspace && \
    chmod -R 777 /app/workspace

# Set cache environment variables
ENV HF_HOME=/tmp/huggingface \
    TRANSFORMERS_CACHE=/tmp/huggingface \
    XDG_CACHE_HOME=/tmp \
    WRITABLE_DIR=/app/workspace

# Copy and build frontend
COPY frontend ./frontend
WORKDIR /app/frontend
RUN if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
    elif [ -f package-lock.json ]; then npm ci; \
    elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
    else echo "No lockfile found. Exiting." && exit 1; \
    fi
RUN npm run build

# Stage 2: FastAPI Backend
FROM python:3.12-slim AS backend
WORKDIR /app

# Install OS dependencies and set up locales
RUN apt-get update --fix-missing && \
    apt-get install --no-install-recommends -y git curl locales && \
    sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    locale-gen en_US.UTF-8 && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Set locale environment variables
ENV LANG=en_US.UTF-8 \
    LANGUAGE=en_US:en \
    LC_ALL=en_US.UTF-8 \
    PYTHONIOENCODING=utf-8

# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
    apt-get update --fix-missing && \
    apt-get install --no-install-recommends -y nodejs && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Copy and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124
RUN python -m spacy download en_core_web_sm

# Disable telemetry
ENV DEEPEVAL_TELEMETRY_OPT_OUT=YES

# Copy backend code and frontend build
COPY . .
COPY --from=builder /app/frontend/build ./frontend/build

# Set up user and permissions
RUN mkdir -p /tmp/huggingface /app/workspace && \
    chmod -R 777 /tmp/huggingface /app/workspace && \
    useradd -m spaces-user && \
    chown -R spaces-user:spaces-user /tmp/huggingface /app/workspace

USER spaces-user

EXPOSE ${PORT:-7860}

CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]