File size: 1,694 Bytes
781f7b0
 
 
 
3146a2c
 
781f7b0
 
 
 
 
 
 
 
 
 
 
 
 
3146a2c
 
 
781f7b0
 
 
 
 
 
3628ccf
781f7b0
 
3146a2c
781f7b0
 
3146a2c
781f7b0
 
3146a2c
781f7b0
 
 
 
bd98b15
781f7b0
 
 
 
d09ee28
3146a2c
781f7b0
cda1137
bd98b15
781f7b0
3146a2c
781f7b0
 
 
3146a2c
781f7b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Stage 1: Builder - Install dependencies
FROM python:3.11-slim AS builder

WORKDIR /app

# Install Poetry
RUN pip install --no-cache-dir poetry==1.8.0

# Configure Poetry for non-interactive installation
RUN poetry config virtualenvs.create false

# Copy only dependency files first (cache layer)
COPY pyproject.toml poetry.lock ./

# Install only production dependencies
RUN poetry install --only main --no-interaction --no-ansi --no-root

# Stage 2: Runtime - Minimal production image
FROM python:3.11-slim AS runtime

WORKDIR /app

# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# Create non-root user for security
RUN useradd --create-home --shell /bin/bash appuser

# Create directories with proper ownership
RUN mkdir -p /app/logs /app/models && chown -R appuser:appuser /app

# Copy application code (separate layer for faster rebuilds)
COPY --chown=appuser:appuser app/ ./app/

# Switch to non-root user
USER appuser

# Environment configuration
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app

# Hugging Face model cache directory
ENV HF_HOME=/app/models
ENV TRANSFORMERS_CACHE=/app/models
ENV SENTENCE_TRANSFORMERS_HOME=/app/models
ENV WHISPER_MODELS_DIR=/app/models

# Disable file logging in container
ENV DISABLE_FILE_LOGGING=true

EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" || exit 1

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]