File size: 2,405 Bytes
8c546bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
# Dockerfile

# 1. Base Image: Python 3.10 on Debian (Bullseye for ffmpeg availability)
# Using a slim image to keep the size down.
FROM python:3.10-slim-bullseye

# 2. Set Environment Variables
ENV PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=off \
    PIP_DISABLE_PIP_VERSION_CHECK=on \
    PIP_DEFAULT_TIMEOUT=100 \
    # For Hugging Face cache inside the container (optional, models will download on first run)
    HF_HOME="/app/.huggingface_cache" \
    TRANSFORMERS_CACHE="/app/.huggingface_cache/transformers" \
    HUGGINGFACE_HUB_CACHE="/app/.huggingface_cache/hub"

# 3. Install System Dependencies
# - ffmpeg: for video processing
# - git: in case any pip package needs to be installed from a git source
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    ffmpeg \
    git \
    curl \
    && apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 4. Set Working Directory
WORKDIR /app

# 5. Copy requirements.txt and Install Python Dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 6. Copy Application Code and Secrets
# First, copy the secrets file (if it exists and you intend to build it into the image)
# WARNING: Building secrets into the image is generally NOT recommended for production.
#          Manage secrets via environment variables or Docker secrets/volume mounts at runtime.
#          This is included for completeness if you are managing it this way for development.
COPY .streamlit/secrets.toml .streamlit/secrets.toml

# Copy the rest of your application code
COPY app.py .
# If you have other Python modules or asset files, copy them as well:
# COPY your_module.py .
# COPY assets/ /app/assets/

# 7. Create Hugging Face cache directory and set permissions (optional)
# This helps if the user running the container is not root and needs to write to cache.
RUN mkdir -p /app/.huggingface_cache && \
    chmod -R 777 /app/.huggingface_cache

# 8. Expose Port for Streamlit
EXPOSE 8501

# 9. Healthcheck (Optional but recommended)
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl --fail http://localhost:8501/_stcore/health || exit 1

# 10. Command to Run the Streamlit Application
# The --server.address=0.0.0.0 makes the app accessible externally from the container.
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--logger.level=info"]