Update Dockerfile
Browse files- Dockerfile +29 -4
Dockerfile
CHANGED
|
@@ -1,20 +1,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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
COPY requirements.txt .
|
| 14 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
COPY . .
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
| 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 |
+
# Create necessary directories with correct ownership and permissions
|
| 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 |
+
# Copy requirements and install Python dependencies
|
| 29 |
COPY requirements.txt .
|
|
|
|
| 30 |
|
| 31 |
+
RUN pip install --no-cache-dir -r requirements.txt && \
|
| 32 |
+
python -c "import nltk; nltk.download('punkt', download_dir='/app/nltk_data')" && \
|
| 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 |
+
CMD ["gunicorn", "app:app"]
|