Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,134 Bytes
970eef1 f718c1a 970eef1 d6b6619 970eef1 844b271 970eef1 844b271 970eef1 844b271 d99ffd8 970eef1 f8ec36f 844b271 fd99e72 970eef1 f718c1a 970eef1 2baeef7 970eef1 855b7ce |
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 |
# Build frontend
FROM node:18 as frontend-build
WORKDIR /app
COPY frontend/package*.json ./
# Configurer le registre npm miroir pour éviter les erreurs 403
RUN npm config set registry https://registry.npmmirror.com/
RUN npm install
COPY frontend/ ./
# Set environment variable for production build
ENV REACT_APP_NODE_ENV=production
RUN npm run build
# Build backend
FROM python:3.12-slim
WORKDIR /app
# Install system dependencies required for UV, Git and Node.js
RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates git netcat-openbsd && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*
# Install UV (fast Python dependency manager)
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
mv /root/.local/bin/uv /usr/local/bin/uv && chmod +x /usr/local/bin/uv
# Verify UV installation
RUN uv --version
# Create non-root user
RUN useradd -m -u 1000 user
# Create and configure cache directory
RUN mkdir -p /app/.cache && \
chown -R user:user /app
# Copy all backend code first
COPY backend/ .
# Install all dependencies explicitly
RUN pip install fastapi uvicorn
# Install project dependencies
RUN uv pip install -e . --system
# Copy frontend server and build
COPY --from=frontend-build /app/build ./frontend/build
COPY --from=frontend-build /app/package*.json ./frontend/
COPY --from=frontend-build /app/server.js ./frontend/
# Install frontend production dependencies
WORKDIR /app/frontend
# Configurer le registre npm miroir pour éviter les erreurs 403
RUN npm config set registry https://registry.npmmirror.com/
RUN npm install --production
WORKDIR /app
# Environment variables
ENV HF_HOME=/app/.cache \
HF_DATASETS_CACHE=/app/.cache \
INTERNAL_API_PORT=7861 \
PORT=7860 \
NODE_ENV=production
# Note: HF_TOKEN should be provided at runtime, not build time
USER user
EXPOSE 7860 7861
# Start both servers with wait-for
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port 7861 & while ! nc -z 127.0.0.1 7861; do sleep 1; done && cd frontend && npm run serve"] |