Spaces:
Paused
Paused
Hemang Thakur
commited on
Commit
·
d8479e9
1
Parent(s):
a6a6a62
disable deepeval telemetry
Browse files- Dockerfile +26 -29
Dockerfile
CHANGED
@@ -1,13 +1,11 @@
|
|
1 |
# ----------------------------
|
2 |
-
# Stage 1:
|
3 |
# ----------------------------
|
4 |
-
FROM node:20-alpine AS
|
5 |
RUN apk add --no-cache libc6-compat
|
|
|
6 |
|
7 |
-
#
|
8 |
-
WORKDIR /app/workspace
|
9 |
-
|
10 |
-
# Create writable directories for Hugging Face Spaces and ensure full permissions
|
11 |
RUN mkdir -p /tmp/huggingface && \
|
12 |
chmod -R 777 /tmp/huggingface && \
|
13 |
mkdir -p /app/workspace && \
|
@@ -19,59 +17,58 @@ ENV HF_HOME=/tmp/huggingface \
|
|
19 |
XDG_CACHE_HOME=/tmp \
|
20 |
WRITABLE_DIR=/app/workspace
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
# ----------------------------
|
25 |
-
FROM setup AS frontend
|
26 |
-
# Switch to the frontend subdirectory under the project root
|
27 |
-
WORKDIR /app/workspace/frontend
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
|
32 |
-
# Install dependencies using
|
33 |
RUN if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
34 |
elif [ -f package-lock.json ]; then npm ci; \
|
35 |
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
36 |
else echo "No lockfile found. Exiting." && exit 1; \
|
37 |
fi
|
38 |
|
39 |
-
# Build the React app
|
40 |
RUN npm run build
|
41 |
|
42 |
# ----------------------------
|
43 |
-
# Stage
|
44 |
# ----------------------------
|
45 |
FROM python:3.12-slim AS backend
|
46 |
-
|
47 |
-
WORKDIR /app/workspace
|
48 |
|
49 |
# Install OS-level dependencies
|
50 |
RUN apt-get update --fix-missing && \
|
51 |
apt-get install --no-install-recommends -y git curl && \
|
52 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
53 |
|
54 |
-
# Install Node.js
|
55 |
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
56 |
apt-get update --fix-missing && \
|
57 |
apt-get install --no-install-recommends -y nodejs && \
|
58 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
59 |
|
60 |
-
# Copy
|
61 |
-
COPY . .
|
62 |
-
|
63 |
-
# Copy the built React app from the frontend stage into the appropriate location
|
64 |
-
COPY --from=frontend /app/workspace/frontend/build ./frontend/build
|
65 |
-
|
66 |
-
# Install Python dependencies from requirements.txt
|
67 |
RUN pip install --no-cache-dir -r requirements.txt
|
68 |
|
69 |
# Install additional dependencies for torch and spaCy
|
70 |
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
|
71 |
RUN python -m spacy download en_core_web_sm
|
72 |
|
73 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
EXPOSE ${PORT:-7860}
|
75 |
|
76 |
-
# Start the FastAPI backend using Uvicorn
|
77 |
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]
|
|
|
1 |
# ----------------------------
|
2 |
+
# Stage 1: Build the React Frontend
|
3 |
# ----------------------------
|
4 |
+
FROM node:20-alpine AS builder
|
5 |
RUN apk add --no-cache libc6-compat
|
6 |
+
WORKDIR /app
|
7 |
|
8 |
+
# Create writable directories for Hugging Face Spaces
|
|
|
|
|
|
|
9 |
RUN mkdir -p /tmp/huggingface && \
|
10 |
chmod -R 777 /tmp/huggingface && \
|
11 |
mkdir -p /app/workspace && \
|
|
|
17 |
XDG_CACHE_HOME=/tmp \
|
18 |
WRITABLE_DIR=/app/workspace
|
19 |
|
20 |
+
# Copy the 'frontend' folder from the project root into the container
|
21 |
+
COPY frontend ./frontend
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Switch to the frontend directory
|
24 |
+
WORKDIR /app/frontend
|
25 |
|
26 |
+
# Install dependencies (using yarn, npm, or pnpm)
|
27 |
RUN if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
28 |
elif [ -f package-lock.json ]; then npm ci; \
|
29 |
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
30 |
else echo "No lockfile found. Exiting." && exit 1; \
|
31 |
fi
|
32 |
|
33 |
+
# Build the React app (produces a production-ready build in the "build" folder)
|
34 |
RUN npm run build
|
35 |
|
36 |
# ----------------------------
|
37 |
+
# Stage 2: Set Up the FastAPI Backend and Serve the React App
|
38 |
# ----------------------------
|
39 |
FROM python:3.12-slim AS backend
|
40 |
+
WORKDIR /app
|
|
|
41 |
|
42 |
# Install OS-level dependencies
|
43 |
RUN apt-get update --fix-missing && \
|
44 |
apt-get install --no-install-recommends -y git curl && \
|
45 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
46 |
|
47 |
+
# Install Node.js (if needed for any backend tasks)
|
48 |
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
49 |
apt-get update --fix-missing && \
|
50 |
apt-get install --no-install-recommends -y nodejs && \
|
51 |
apt-get clean && rm -rf /var/lib/apt/lists/*
|
52 |
|
53 |
+
# Copy requirements.txt and install Python dependencies
|
54 |
+
COPY requirements.txt .
|
|
|
|
|
|
|
|
|
|
|
55 |
RUN pip install --no-cache-dir -r requirements.txt
|
56 |
|
57 |
# Install additional dependencies for torch and spaCy
|
58 |
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
|
59 |
RUN python -m spacy download en_core_web_sm
|
60 |
|
61 |
+
# Disable telemetry for deepeval
|
62 |
+
ENV DEEPEVAL_TELEMETRY_OPT_OUT=YES
|
63 |
+
|
64 |
+
# Copy the rest of your backend code and resources
|
65 |
+
COPY . .
|
66 |
+
|
67 |
+
# Copy the built React app from the builder stage into the same folder structure as used in your FastAPI code
|
68 |
+
COPY --from=builder /app/frontend/build ./frontend/build
|
69 |
+
|
70 |
+
# Expose the port
|
71 |
EXPOSE ${PORT:-7860}
|
72 |
|
73 |
+
# Start the FastAPI backend using Uvicorn, reading the PORT env variable
|
74 |
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-7860}"]
|