jacob-valdez commited on
Commit
3a0eb51
·
1 Parent(s): 157c6fe

Optimize for HF Spaces storage limits: smaller base image, essential deps only, dockerignore

Browse files
Files changed (3) hide show
  1. .dockerignore +36 -0
  2. Dockerfile +11 -16
  3. requirements.txt +7 -7
.dockerignore ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__
2
+ *.pyc
3
+ *.pyo
4
+ *.pyd
5
+ .Python
6
+ env
7
+ pip-log.txt
8
+ pip-delete-this-directory.txt
9
+ .tox
10
+ .coverage
11
+ .coverage.*
12
+ .pytest_cache
13
+ nosetests.xml
14
+ coverage.xml
15
+ *.cover
16
+ *.log
17
+ .git
18
+ .mypy_cache
19
+ .pytest_cache
20
+ .hypothesis
21
+ *.egg-info
22
+ dist
23
+ build
24
+ .env
25
+ .venv
26
+ env/
27
+ venv/
28
+ ENV/
29
+ env.bak/
30
+ venv.bak/
31
+ .DS_Store
32
+ Thumbs.db
33
+ *.tmp
34
+ *.temp
35
+ .cache
36
+ *.sqlite3
Dockerfile CHANGED
@@ -1,38 +1,33 @@
1
- # Dockerfile for BuilderBrain inference API on Hugging Face Spaces
2
  FROM python:3.11-slim
3
 
4
  # Set environment variables
5
  ENV PYTHONUNBUFFERED=1
6
  ENV PYTHONDONTWRITEBYTECODE=1
 
 
7
 
8
- # Install system dependencies
9
  RUN apt-get update && apt-get install -y \
10
- build-essential \
11
  curl \
12
- git \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
- # Install Python dependencies
16
- COPY requirements.txt .
17
- RUN pip install --no-cache-dir -r requirements.txt
18
-
19
- # Create non-root user
20
- RUN useradd -m -u 1000 builderbrain
21
-
22
  # Set work directory
23
  WORKDIR /app
24
 
 
 
 
 
25
  # Copy application files
26
  COPY app.py .
27
  COPY inference_api_app.py .
28
 
29
- # Change ownership
30
- RUN chown -R builderbrain:builderbrain /app
31
-
32
- # Switch to non-root user
33
  USER builderbrain
34
 
35
- # Expose port (HF Spaces uses 7860)
36
  EXPOSE 7860
37
 
38
  # Health check
 
1
+ # Optimized Dockerfile for Hugging Face Spaces (under 50GB limit)
2
  FROM python:3.11-slim
3
 
4
  # Set environment variables
5
  ENV PYTHONUNBUFFERED=1
6
  ENV PYTHONDONTWRITEBYTECODE=1
7
+ ENV PIP_NO_CACHE_DIR=1
8
+ ENV PIP_DISABLE_PIP_VERSION_CHECK=1
9
 
10
+ # Install only essential system dependencies
11
  RUN apt-get update && apt-get install -y \
 
12
  curl \
 
13
  && rm -rf /var/lib/apt/lists/*
14
 
 
 
 
 
 
 
 
15
  # Set work directory
16
  WORKDIR /app
17
 
18
+ # Copy requirements first for better caching
19
+ COPY requirements.txt .
20
+ RUN pip install --no-cache-dir -r requirements.txt
21
+
22
  # Copy application files
23
  COPY app.py .
24
  COPY inference_api_app.py .
25
 
26
+ # Create non-root user for security
27
+ RUN useradd -m -u 1000 builderbrain && chown -R builderbrain:builderbrain /app
 
 
28
  USER builderbrain
29
 
30
+ # Expose port
31
  EXPOSE 7860
32
 
33
  # Health check
requirements.txt CHANGED
@@ -1,7 +1,7 @@
1
- fastapi>=0.104.0
2
- uvicorn[standard]>=0.24.0
3
- torch>=2.0.0
4
- transformers>=4.35.0
5
- psutil>=5.9.0
6
- pydantic>=2.5.0
7
- python-multipart>=0.0.6
 
1
+ fastapi==0.104.1
2
+ uvicorn[standard]==0.24.0
3
+ torch==2.1.0
4
+ transformers==4.35.2
5
+ psutil==5.9.6
6
+ pydantic==2.5.0
7
+ python-multipart==0.0.6