ButterM40 commited on
Commit
a828cd4
·
1 Parent(s): 10425b4

Docker: add .dockerignore and robustify Dockerfile for Spaces (install deps, prefer-binary)

Browse files
Files changed (2) hide show
  1. .dockerignore +24 -0
  2. Dockerfile +21 -7
.dockerignore ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ .venv/
3
+ .cache/
4
+ build/
5
+ dist/
6
+ *.pyc
7
+ *.pyo
8
+ *.pyd
9
+ .Python
10
+ env/
11
+ venv/
12
+ .git/
13
+ .github/
14
+ node_modules/
15
+ models/
16
+ *.sqlite3
17
+ *.db
18
+ Dockerfile
19
+ *.log
20
+ /.env
21
+ /.venv
22
+ /.mypy_cache
23
+ /.pytest_cache
24
+ static/node_modules/
Dockerfile CHANGED
@@ -1,6 +1,9 @@
1
  # Use Python 3.11 slim image
2
  FROM python:3.11-slim
3
 
 
 
 
4
  # Set working directory
5
  WORKDIR /code
6
 
@@ -8,20 +11,31 @@ WORKDIR /code
8
  ENV PORT=7860
9
  ENV PYTHONPATH=/code
10
  ENV TRANSFORMERS_CACHE=/code/.cache/transformers
 
11
 
12
- # Install system dependencies
13
  RUN apt-get update && \
14
  apt-get install -y --no-install-recommends \
15
- build-essential \
16
- git \
 
 
 
 
 
 
 
 
 
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
  # Copy requirements first for better caching
20
  COPY requirements.txt .
21
 
22
- # Install Python dependencies
23
- RUN pip install --no-cache-dir --upgrade pip && \
24
- pip install --no-cache-dir -r requirements.txt
 
25
 
26
  # Copy the rest of the application
27
  COPY . .
@@ -29,7 +43,7 @@ COPY . .
29
  # Create cache directory for transformers
30
  RUN mkdir -p /code/.cache/transformers
31
 
32
- # Make port 7860 available
33
  EXPOSE 7860
34
 
35
  # Run the FastAPI server
 
1
  # Use Python 3.11 slim image
2
  FROM python:3.11-slim
3
 
4
+ # Set noninteractive to avoid prompts
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
  # Set working directory
8
  WORKDIR /code
9
 
 
11
  ENV PORT=7860
12
  ENV PYTHONPATH=/code
13
  ENV TRANSFORMERS_CACHE=/code/.cache/transformers
14
+ ENV PIP_DEFAULT_TIMEOUT=100
15
 
16
+ # Install system dependencies commonly required to build wheels
17
  RUN apt-get update && \
18
  apt-get install -y --no-install-recommends \
19
+ build-essential \
20
+ git \
21
+ curl \
22
+ ca-certificates \
23
+ pkg-config \
24
+ libsndfile1 \
25
+ libgl1 \
26
+ libglib2.0-0 \
27
+ python3-dev \
28
+ libffi-dev \
29
+ libssl-dev \
30
  && rm -rf /var/lib/apt/lists/*
31
 
32
  # Copy requirements first for better caching
33
  COPY requirements.txt .
34
 
35
+ # Upgrade pip and install dependencies preferring binary wheels
36
+ RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
37
+ pip install --no-cache-dir --prefer-binary -r requirements.txt || \
38
+ (echo "Initial pip install failed, retrying without --prefer-binary" && pip install --no-cache-dir -r requirements.txt)
39
 
40
  # Copy the rest of the application
41
  COPY . .
 
43
  # Create cache directory for transformers
44
  RUN mkdir -p /code/.cache/transformers
45
 
46
+ # Make port available
47
  EXPOSE 7860
48
 
49
  # Run the FastAPI server