Update Dockerfile
Browse files- Dockerfile +17 -26
Dockerfile
CHANGED
|
@@ -1,37 +1,28 @@
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
ENV HF_HOME=/app/hf_cache
|
| 6 |
-
ENV NLTK_DATA=/app/nltk_data
|
| 7 |
-
ENV PORT=8080
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 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 |
-
#
|
| 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 |
-
#
|
| 34 |
-
RUN
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
EXPOSE 8080
|
| 37 |
-
|
|
|
|
|
|
|
|
|
| 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"]
|