winsweb commited on
Commit
df0419a
·
1 Parent(s): 9630604

Ultra-lean build: Surgical copy and pinned dependencies

Browse files
Files changed (2) hide show
  1. Dockerfile +23 -17
  2. requirements.txt +9 -9
Dockerfile CHANGED
@@ -1,30 +1,36 @@
1
  FROM python:3.10-slim
2
 
3
- WORKDIR /app
 
 
 
 
4
 
5
- # Install system dependencies
6
- RUN apt-get update && \
7
- apt-get clean && \
8
- rm -rf /var/lib/apt/lists/*
9
 
10
- # Set up user with UID 1000 (Hugging Face standard)
11
  RUN useradd -m -u 1000 user
12
- USER user
13
- ENV HOME=/home/user \
14
- PATH=/home/user/.local/bin:$PATH \
15
- PYTHONPATH=/app
16
 
17
- # Copy requirements first for better caching
18
  COPY --chown=user requirements.txt .
19
- RUN pip install --no-cache-dir --user --upgrade -r requirements.txt
 
20
 
21
- # Copy the application code
22
- COPY --chown=user . .
23
 
24
- # Ensure app directories exist and are writable
25
- RUN mkdir -p data/input data/output data/save_pdf logs data/raw_csv_temp data/output_process_data data/strictly_cleaned_data
 
 
 
 
 
 
 
 
26
 
27
- # Use 0.0.0.0 and 7860
28
  EXPOSE 7860
29
 
30
  # Run API
 
1
  FROM python:3.10-slim
2
 
3
+ # Set environment variables
4
+ ENV PYTHONDONTWRITEBYTECODE=1 \
5
+ PYTHONUNBUFFERED=1 \
6
+ PYTHONPATH=/app \
7
+ HOME=/home/user
8
 
9
+ WORKDIR /app
 
 
 
10
 
11
+ # Create user
12
  RUN useradd -m -u 1000 user
 
 
 
 
13
 
14
+ # Copy and install requirements first
15
  COPY --chown=user requirements.txt .
16
+ RUN pip install --no-cache-dir --upgrade pip && \
17
+ pip install --no-cache-dir --user -r requirements.txt
18
 
19
+ # Add user local bin to path
20
+ ENV PATH="/home/user/.local/bin:${PATH}"
21
 
22
+ # surgically copy only what is needed
23
+ COPY --chown=user telecom_anomaly/ telecom_anomaly/
24
+ COPY --chown=user config/ config/
25
+ COPY --chown=user main.py .
26
+
27
+ # Create empty directories with right permissions
28
+ RUN mkdir -p data/input data/output data/save_pdf logs data/raw_csv_temp data/output_process_data data/strictly_cleaned_data && \
29
+ chown -R user:user /app
30
+
31
+ USER user
32
 
33
+ # Expose HF default port
34
  EXPOSE 7860
35
 
36
  # Run API
requirements.txt CHANGED
@@ -1,14 +1,14 @@
1
  # Core Analysis
2
- pandas>=1.3.0
3
- numpy>=1.21.0
4
- scikit-learn>=1.0.0
5
- pdfplumber>=0.7.0
6
 
7
  # API
8
- fastapi>=0.95.0
9
- uvicorn>=0.21.0
10
- python-multipart>=0.0.6
11
- pydantic>=1.10.0
12
 
13
  # Export & PDF
14
- fpdf2>=2.7.0
 
1
  # Core Analysis
2
+ pandas==2.0.3
3
+ numpy==1.24.3
4
+ scikit-learn==1.3.0
5
+ pdfplumber==0.10.2
6
 
7
  # API
8
+ fastapi==0.103.1
9
+ uvicorn==0.23.2
10
+ python-multipart==0.0.6
11
+ pydantic==1.10.12
12
 
13
  # Export & PDF
14
+ fpdf2==2.7.4