sathishaiuse commited on
Commit
dc183a6
·
verified ·
1 Parent(s): c8bc6f3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +49 -36
Dockerfile CHANGED
@@ -1,47 +1,60 @@
1
- # Dockerfile — patched: python:3.11-slim + system libs + baked model + /tmp/model perms
2
- FROM python:3.11-slim
3
 
4
- ENV DEBIAN_FRONTEND=noninteractive \
5
- PYTHONUNBUFFERED=1 \
6
- STREAMLIT_SERVER_HEADLESS=true \
7
- STREAMLIT_SERVER_RUN_ON_SAVE=false \
8
- STREAMLIT_SERVER_ENABLECORS=false \
9
- STREAMLIT_SERVER_PORT=8501 \
10
- STREAMLIT_SERVER_ADDRESS=0.0.0.0
11
 
 
12
  WORKDIR /app
13
 
14
- # Install minimal system libs needed by numpy/scipy/xgboost wheels
15
- RUN apt-get update && apt-get install -y --no-install-recommends \
16
- libgomp1 \
17
- libopenblas-dev \
18
- ca-certificates \
19
- && rm -rf /var/lib/apt/lists/*
20
-
21
- # Copy project files into image
22
- COPY . /app
23
 
24
- # Ensure /tmp/model exists and is writable by the runtime non-root user (UID 1000).
25
- # Also copy a baked model if present in repo root, and set permissive ownership/permissions.
26
- RUN mkdir -p /tmp/model && \
27
- cp /app/best_overall_XGBoost.joblib /tmp/model/best_overall_XGBoost.joblib 2>/dev/null || true && \
28
- chown -R 1000:1000 /tmp/model && \
29
- chmod -R a+rwx /tmp/model
30
 
31
- # Upgrade pip & install Python dependencies from requirements.txt
32
- RUN python -m pip install --upgrade pip setuptools wheel
33
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
34
 
35
- # Create non-root user and switch
36
- RUN useradd -m -u 1000 user
37
- USER user
38
- ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
39
 
40
- # Use user's home app dir for runtime; copy app files there
41
- WORKDIR $HOME/app
42
- RUN cp -r /app/* $HOME/app/ || true
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  EXPOSE 8501
45
 
46
- # Run streamlit with explicit flags (single-line JSON array)
47
- CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.headless=true", "--server.runOnSave=false", "--server.enableCORS=false", "--server.enableXsrfProtection=false", "--logger.level=debug"]
 
1
+ # Dockerfile
2
+ FROM python:3.10-slim
3
 
4
+ # Set non-root user if you want (optional)
5
+ # RUN adduser --disabled-password appuser
6
+ # USER appuser
 
 
 
 
7
 
8
+ ENV DEBIAN_FRONTEND=noninteractive
9
  WORKDIR /app
10
 
11
+ # Build args for secret/token usage at build time (if you provide it)
12
+ ARG HF_TOKEN
13
+ ENV HF_TOKEN=${HF_TOKEN}
 
 
 
 
 
 
14
 
15
+ # Copy requirements first for better caching
16
+ COPY requirements.txt /app/requirements.txt
 
 
 
 
17
 
18
+ # Install system deps and python deps
19
+ RUN apt-get update && apt-get install -y --no-install-recommends \
20
+ build-essential \
21
+ ca-certificates \
22
+ git \
23
+ && rm -rf /var/lib/apt/lists/*
24
 
25
+ RUN pip install --upgrade pip
26
+ RUN pip install -r /app/requirements.txt
 
 
27
 
28
+ # Copy app source
29
+ COPY . /app
 
30
 
31
+ # Pre-download model during build (if HF_TOKEN / repo available)
32
+ # This will try to download the model and save it to the HF cache; it will also
33
+ # leave a copy in the default cache path which is fine for runtime.
34
+ RUN python - <<'PY'
35
+ import os, sys
36
+ from huggingface_hub import hf_hub_download
37
+ repo = os.getenv("HF_MODEL_REPO", "sathishaiuse/wellness-classifier-model")
38
+ fname = os.getenv("HF_MODEL_FILENAME", "best_overall_XGBoost.joblib")
39
+ token = os.getenv("HF_TOKEN") or None
40
+ try:
41
+ print("Attempting to pre-download model:", repo, fname, "token_present=", bool(token))
42
+ path = hf_hub_download(repo_id=repo, filename=fname, token=token)
43
+ print("Model downloaded to:", path)
44
+ # Also copy to /app for easier direct loading if desired
45
+ import shutil
46
+ dest = os.path.join("/app", os.path.basename(path))
47
+ try:
48
+ shutil.copy(path, dest)
49
+ print("Copied model to", dest)
50
+ except Exception as e:
51
+ print("Could not copy model to /app:", e)
52
+ except Exception as e:
53
+ print("Pre-download failed (continues build). Error:", e)
54
+ PY
55
+
56
+ # Expose port for local testing (Streamlit default 8501)
57
  EXPOSE 8501
58
 
59
+ # default command for Streamlit (adjust if your original app uses different flags)
60
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.headless=true"]