Spaces:
Running
Running
docker update
Browse files- Dockerfile +19 -35
Dockerfile
CHANGED
@@ -1,65 +1,49 @@
|
|
1 |
-
# Use
|
2 |
FROM python:3.10-slim
|
3 |
|
4 |
# Set working directory
|
5 |
WORKDIR /app
|
6 |
|
7 |
-
# Set environment variables
|
8 |
ENV PYTHONUNBUFFERED=1 \
|
9 |
PYTHONDONTWRITEBYTECODE=1 \
|
10 |
-
DEBIAN_FRONTEND=noninteractive
|
|
|
11 |
|
12 |
-
# Install system
|
13 |
-
RUN apt-get update && \
|
14 |
-
apt-get install -y \
|
15 |
ffmpeg \
|
16 |
libsndfile1 \
|
|
|
|
|
17 |
wget \
|
18 |
curl \
|
19 |
git \
|
20 |
build-essential \
|
21 |
&& rm -rf /var/lib/apt/lists/*
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
# Create non-root user to avoid git permission issues
|
26 |
-
RUN useradd -m appuser && chown -R appuser /app
|
27 |
-
|
28 |
-
# Set HOME explicitly to match the non-root user
|
29 |
-
ENV HOME=/home/appuser
|
30 |
-
|
31 |
-
# Switch to appuser for git config
|
32 |
-
USER appuser
|
33 |
-
|
34 |
-
# Configure git to avoid permission issues during HF build
|
35 |
-
RUN git config --global --add safe.directory /app && \
|
36 |
-
git config --global user.email "[email protected]" && \
|
37 |
-
git config --global user.name "peace2024"
|
38 |
-
|
39 |
-
USER root
|
40 |
-
|
41 |
-
# Copy requirements first to leverage Docker layer caching
|
42 |
COPY requirements-hf.txt .
|
43 |
|
44 |
-
#
|
45 |
RUN pip install --no-cache-dir --upgrade pip && \
|
46 |
pip install --no-cache-dir -r requirements-hf.txt
|
47 |
|
48 |
-
#
|
|
|
|
|
|
|
49 |
COPY . .
|
50 |
|
51 |
# Create necessary directories
|
52 |
RUN mkdir -p vector_store logs
|
53 |
|
54 |
-
# Expose port
|
55 |
EXPOSE 7860
|
56 |
|
57 |
-
# Install PyTorch CPU wheels (Spaces default)
|
58 |
-
RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
59 |
-
|
60 |
# Health check
|
61 |
-
HEALTHCHECK --interval=30s --timeout=
|
62 |
-
CMD curl -f http://localhost:7860/
|
63 |
|
64 |
-
# Run
|
65 |
-
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"
|
|
|
1 |
+
# Use Python 3.10 slim for ML workloads
|
2 |
FROM python:3.10-slim
|
3 |
|
4 |
# Set working directory
|
5 |
WORKDIR /app
|
6 |
|
7 |
+
# Set environment variables
|
8 |
ENV PYTHONUNBUFFERED=1 \
|
9 |
PYTHONDONTWRITEBYTECODE=1 \
|
10 |
+
DEBIAN_FRONTEND=noninteractive \
|
11 |
+
PORT=7860
|
12 |
|
13 |
+
# Install system dependencies
|
14 |
+
RUN apt-get update && apt-get install -y \
|
|
|
15 |
ffmpeg \
|
16 |
libsndfile1 \
|
17 |
+
libasound2-dev \
|
18 |
+
portaudio19-dev \
|
19 |
wget \
|
20 |
curl \
|
21 |
git \
|
22 |
build-essential \
|
23 |
&& rm -rf /var/lib/apt/lists/*
|
24 |
|
25 |
+
# Copy requirements first for better caching
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
COPY requirements-hf.txt .
|
27 |
|
28 |
+
# Install Python dependencies
|
29 |
RUN pip install --no-cache-dir --upgrade pip && \
|
30 |
pip install --no-cache-dir -r requirements-hf.txt
|
31 |
|
32 |
+
# Install PyTorch CPU (before copying app code)
|
33 |
+
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
34 |
+
|
35 |
+
# Copy app source code
|
36 |
COPY . .
|
37 |
|
38 |
# Create necessary directories
|
39 |
RUN mkdir -p vector_store logs
|
40 |
|
41 |
+
# Expose port
|
42 |
EXPOSE 7860
|
43 |
|
|
|
|
|
|
|
44 |
# Health check
|
45 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
46 |
+
CMD curl -f http://localhost:7860/ || exit 1
|
47 |
|
48 |
+
# Run FastAPI app
|
49 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|