Severian commited on
Commit
90f57a2
·
1 Parent(s): 953b0b8

fix: optimize Dockerfile for Hugging Face Spaces deployment

Browse files
Files changed (1) hide show
  1. Dockerfile +36 -4
Dockerfile CHANGED
@@ -4,20 +4,52 @@
4
  FROM python:3.10-slim-bookworm AS base
5
 
6
  # Configure build environment with optimized settings
7
- ENV NODE_OPTIONS="--max_old_space_size=2048" \
8
  NEXT_TELEMETRY_DISABLED=1 \
9
  NODE_ENV=production \
10
  PYTHONDONTWRITEBYTECODE=1 \
11
  TZ=UTC \
12
- STORAGE_DIR=/storage
 
 
13
 
14
- # Install base dependencies
15
  RUN apt-get update && \
16
  apt-get install -y --no-install-recommends \
17
  tzdata git curl redis-server && \
18
  rm -f /etc/localtime && \
19
  ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
20
- echo $TZ > /etc/timezone
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  # ============================================
23
  # Web builder stage - optimized
 
4
  FROM python:3.10-slim-bookworm AS base
5
 
6
  # Configure build environment with optimized settings
7
+ ENV NODE_OPTIONS="--max_old_space_size=4096" \
8
  NEXT_TELEMETRY_DISABLED=1 \
9
  NODE_ENV=production \
10
  PYTHONDONTWRITEBYTECODE=1 \
11
  TZ=UTC \
12
+ STORAGE_DIR=/storage \
13
+ PIP_NO_CACHE_DIR=1 \
14
+ PIP_DISABLE_PIP_VERSION_CHECK=1
15
 
16
+ # Install base dependencies with retry mechanism
17
  RUN apt-get update && \
18
  apt-get install -y --no-install-recommends \
19
  tzdata git curl redis-server && \
20
  rm -f /etc/localtime && \
21
  ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
22
+ echo $TZ > /etc/timezone && \
23
+ apt-get clean && \
24
+ rm -rf /var/lib/apt/lists/*
25
+
26
+ # Split package installation into smaller chunks
27
+ RUN pip install --no-cache-dir \
28
+ gunicorn gevent grpcio pydantic-settings protobuf grpcio-tools && \
29
+ pip install --no-cache-dir \
30
+ flask flask-cors Flask-SQLAlchemy==3.1.1 Flask-Migrate==4.0.7 && \
31
+ pip install --no-cache-dir \
32
+ flask-login flask-restful flask-limiter flask-caching flask-jwt-extended flask-socketio && \
33
+ pip install --no-cache-dir \
34
+ PyYAML celery redis psycopg2-binary sqlalchemy alembic
35
+
36
+ # Install ML-related packages separately
37
+ RUN pip install --no-cache-dir \
38
+ numpy pandas scikit-learn scipy && \
39
+ pip install --no-cache-dir \
40
+ torch --index-url https://download.pytorch.org/whl/cpu && \
41
+ pip install --no-cache-dir \
42
+ tensorflow-cpu
43
+
44
+ # Install AI service packages
45
+ RUN pip install --no-cache-dir \
46
+ openai==1.14.0 anthropic==0.23.1 cohere==4.43 && \
47
+ pip install --no-cache-dir \
48
+ langchain langchain-community langchain-core langchain-openai
49
+
50
+ # Install NLTK and download required data
51
+ RUN pip install --no-cache-dir nltk && \
52
+ python -m nltk.downloader punkt averaged_perceptron_tagger
53
 
54
  # ============================================
55
  # Web builder stage - optimized