Update Dockerfile
Browse files- Dockerfile +15 -18
Dockerfile
CHANGED
|
@@ -1,45 +1,42 @@
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
|
| 3 |
-
# Set environment variables
|
| 4 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 5 |
ENV PYTHONUNBUFFERED=1
|
| 6 |
ENV HF_HOME=/app/hf_cache
|
| 7 |
ENV NLTK_DATA=/app/nltk_data
|
| 8 |
ENV PORT=8080
|
| 9 |
|
| 10 |
-
# Set working directory
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
-
# Install system dependencies
|
| 14 |
RUN apt-get update && apt-get install -y \
|
| 15 |
gcc \
|
| 16 |
python3-dev \
|
| 17 |
curl \
|
| 18 |
&& rm -rf /var/lib/apt/lists/*
|
| 19 |
|
| 20 |
-
# Create non-root user before creating directories to set ownership properly
|
| 21 |
RUN adduser --disabled-password --gecos '' appuser
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
RUN mkdir -p /app/hf_cache /app/nltk_data && \
|
| 25 |
chown -R appuser:appuser /app/hf_cache /app/nltk_data /app && \
|
| 26 |
chmod -R 777 /app/hf_cache /app/nltk_data
|
| 27 |
|
| 28 |
-
|
| 29 |
-
COPY requirements.txt .
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
python -c "from transformers import AutoTokenizer, AutoModelForSequenceClassification; \
|
| 34 |
AutoTokenizer.from_pretrained('priyabrat/AI.or.Human.text.classification', cache_dir='/app/hf_cache'); \
|
| 35 |
AutoModelForSequenceClassification.from_pretrained('priyabrat/AI.or.Human.text.classification', cache_dir='/app/hf_cache')"
|
| 36 |
|
| 37 |
-
# Copy application code
|
| 38 |
-
COPY . .
|
| 39 |
-
|
| 40 |
-
# Switch to non-root user
|
| 41 |
-
USER appuser
|
| 42 |
-
|
| 43 |
-
# Expose port and define default command
|
| 44 |
EXPOSE 8080
|
| 45 |
-
|
|
|
|
|
|
| 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 |
RUN apt-get update && apt-get install -y \
|
| 12 |
gcc \
|
| 13 |
python3-dev \
|
| 14 |
curl \
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
|
|
|
| 17 |
RUN adduser --disabled-password --gecos '' appuser
|
| 18 |
|
| 19 |
+
COPY requirements.txt .
|
| 20 |
+
|
| 21 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 22 |
+
|
| 23 |
+
# Download NLTK punkt data with correct dir
|
| 24 |
+
RUN python -c "import nltk; nltk.download('punkt', download_dir='/app/nltk_data')"
|
| 25 |
+
|
| 26 |
+
# Copy app code and then set ownership & permissions
|
| 27 |
+
COPY . .
|
| 28 |
+
|
| 29 |
RUN mkdir -p /app/hf_cache /app/nltk_data && \
|
| 30 |
chown -R appuser:appuser /app/hf_cache /app/nltk_data /app && \
|
| 31 |
chmod -R 777 /app/hf_cache /app/nltk_data
|
| 32 |
|
| 33 |
+
USER appuser
|
|
|
|
| 34 |
|
| 35 |
+
# Preload huggingface model cache at runtime (optional)
|
| 36 |
+
RUN python -c "from transformers import AutoTokenizer, AutoModelForSequenceClassification; \
|
|
|
|
| 37 |
AutoTokenizer.from_pretrained('priyabrat/AI.or.Human.text.classification', cache_dir='/app/hf_cache'); \
|
| 38 |
AutoModelForSequenceClassification.from_pretrained('priyabrat/AI.or.Human.text.classification', cache_dir='/app/hf_cache')"
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
EXPOSE 8080
|
| 41 |
+
|
| 42 |
+
CMD ["gunicorn", "app:app"]
|