-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
60 lines (44 loc) · 1.6 KB
/
Dockerfile
File metadata and controls
60 lines (44 loc) · 1.6 KB
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
60
# Multi-stage Dockerfile for Movie Recommendation System
# Stage 1: Build ETL artifacts
# Stage 2: Lightweight runtime
FROM python:3.11-slim as builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy source code
COPY etl/ ./etl/
COPY backend/ ./backend/
COPY streamlit_app.py .
# Copy Pre-computed Models and Data
COPY models/ ./models/
COPY data/processed/ ./data/processed/
# Create other directories
RUN mkdir -p data/raw logs
# -------------------------------------------
# Stage 2: Runtime image
FROM python:3.11-slim as runtime
WORKDIR /app
# Install runtime dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# 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
# Copy application code
COPY --from=builder /app /app
# Create non-root user
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
# Expose ports (7860 is required for Hugging Face Spaces, 8000 for Render, 8501 for Streamlit)
EXPOSE 7860 8000 8501
# Set default port to 7860 for Hugging Face Spaces
# Render will override this environment variable at runtime
ENV PORT=7860
# Default command: run backend API.
CMD ["sh", "-c", "uvicorn backend.main:app --host 0.0.0.0 --port $PORT"]