Jobsforce commited on
Commit
f62cf8a
·
verified ·
1 Parent(s): c166a9c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -26
Dockerfile CHANGED
@@ -1,37 +1,28 @@
 
1
  FROM python:3.10-slim
2
 
3
- ENV PYTHONDONTWRITEBYTECODE=1
4
- ENV PYTHONUNBUFFERED=1
5
- ENV HF_HOME=/app/hf_cache
6
- ENV NLTK_DATA=/app/nltk_data
7
- ENV PORT=8080
8
 
9
- WORKDIR /app
 
10
 
11
- # System dependencies
12
- RUN apt-get update && apt-get install -y \
13
- gcc \
14
- python3-dev \
15
- curl \
16
- && rm -rf /var/lib/apt/lists/*
17
-
18
- # Copy code and install Python deps
19
  COPY requirements.txt .
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
- # Download NLTK data
23
- RUN python -c "import nltk; nltk.download('punkt', download_dir='/app/nltk_data')"
24
-
25
- # Preload huggingface model (optional)
26
- RUN python -c "from transformers import AutoTokenizer, AutoModelForSequenceClassification; \
27
- AutoTokenizer.from_pretrained('priyabrat/AI.or.Human.text.classification', cache_dir='/app/hf_cache'); \
28
- AutoModelForSequenceClassification.from_pretrained('priyabrat/AI.or.Human.text.classification', cache_dir='/app/hf_cache')"
29
-
30
- # Copy all app files
31
  COPY . .
32
 
33
- # Fix permissions — make hf_cache and nltk_data writable by everyone
34
- RUN chmod -R 777 /app/hf_cache /app/nltk_data || true
 
35
 
 
 
 
 
36
  EXPOSE 8080
37
- CMD ["gunicorn", "app:app"]
 
 
 
1
+ # Use a slim official Python image
2
  FROM python:3.10-slim
3
 
4
+ # Create a new user
5
+ RUN useradd -m appuser
 
 
 
6
 
7
+ # Set work directory
8
+ WORKDIR /home/appuser/app
9
 
10
+ # Copy and install dependencies
 
 
 
 
 
 
 
11
  COPY requirements.txt .
12
  RUN pip install --no-cache-dir -r requirements.txt
13
 
14
+ # Copy code and give permissions
 
 
 
 
 
 
 
 
15
  COPY . .
16
 
17
+ # Change ownership and switch to non-root
18
+ RUN chown -R appuser:appuser /home/appuser
19
+ USER appuser
20
 
21
+ # Download NLTK tokenizer data
22
+ RUN python -c "import nltk; nltk.download('punkt')"
23
+
24
+ # Expose port
25
  EXPOSE 8080
26
+
27
+ # Run using uvicorn
28
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080"]