Update Dockerfile
Browse files- Dockerfile +7 -49
Dockerfile
CHANGED
|
@@ -1,60 +1,18 @@
|
|
| 1 |
-
FROM python:3.9-slim AS builder
|
| 2 |
-
|
| 3 |
-
# Install system dependencies
|
| 4 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 5 |
-
build-essential \
|
| 6 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 7 |
-
|
| 8 |
-
# Set working directory
|
| 9 |
-
WORKDIR /app
|
| 10 |
-
|
| 11 |
-
# Copy requirements
|
| 12 |
-
COPY requirements.txt .
|
| 13 |
-
|
| 14 |
-
# Install Python dependencies
|
| 15 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 16 |
-
|
| 17 |
FROM python:3.9-slim
|
| 18 |
|
| 19 |
-
# Set environment variables
|
| 20 |
-
ENV TRANSFORMERS_CACHE=/app/cache
|
| 21 |
-
ENV PYTHONDONTWRITEBYTECODE=1
|
| 22 |
-
ENV PYTHONUNBUFFERED=1
|
| 23 |
-
|
| 24 |
-
# Install minimal dependencies for runtime
|
| 25 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 26 |
-
curl \
|
| 27 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 28 |
-
|
| 29 |
-
# Create app directory and cache directory
|
| 30 |
-
RUN mkdir -p /app ${TRANSFORMERS_CACHE} && \
|
| 31 |
-
# Create a non-root user to run the application
|
| 32 |
-
useradd -m appuser && \
|
| 33 |
-
chown -R appuser:appuser /app ${TRANSFORMERS_CACHE}
|
| 34 |
-
|
| 35 |
WORKDIR /app
|
| 36 |
|
| 37 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
COPY requirements.txt .
|
| 39 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 40 |
|
| 41 |
# Copy application code
|
| 42 |
-
COPY
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
USER appuser
|
| 46 |
-
|
| 47 |
-
# Pre-download models to avoid cold starts in production
|
| 48 |
-
RUN python -c "from transformers import pipeline; \
|
| 49 |
-
pipeline('summarization', model='facebook/bart-large-cnn'); \
|
| 50 |
-
pipeline('image-to-text', model='nlpconnect/vit-gpt2-image-captioning')"
|
| 51 |
-
|
| 52 |
-
# Expose the port the app runs on
|
| 53 |
EXPOSE 8000
|
| 54 |
-
|
| 55 |
-
# Health check
|
| 56 |
-
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
| 57 |
-
CMD curl -f http://localhost:8000/ || exit 1
|
| 58 |
-
|
| 59 |
-
# Command to run the application
|
| 60 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Create and set cache directory for Hugging Face
|
| 6 |
+
RUN mkdir -p /app/cache && chown -R 1000:1000 /app/cache
|
| 7 |
+
ENV HF_HOME=/app/cache
|
| 8 |
+
|
| 9 |
+
# Install dependencies
|
| 10 |
COPY requirements.txt .
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
# Copy application code
|
| 14 |
+
COPY . .
|
| 15 |
|
| 16 |
+
# Expose port and run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
EXPOSE 8000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|