File size: 2,023 Bytes
9ede49e
5afbe18
264ac69
5e1192b
16973c0
 
5e1192b
264ac69
 
 
ce859c4
264ac69
 
 
 
 
16973c0
264ac69
 
 
 
ce859c4
 
264ac69
5e1192b
 
 
 
 
264ac69
5e1192b
5afbe18
264ac69
 
 
 
5e1192b
264ac69
 
 
 
 
 
5e1192b
264ac69
5afbe18
264ac69
 
 
 
61208d7
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
FROM python:3.10-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1
# Prevents interactive prompts during apt-get install
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies including ffmpeg and fonts
# Using ttf-mscorefonts-installer for Arial and other common Microsoft fonts
# fontconfig is needed to make fonts available to applications
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        ffmpeg \
        libsm6 \
        libxext6 \
        fontconfig \
    # For Microsoft Core Fonts EULA pre-acceptance
    && echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-sections \
    && apt-get install -y --no-install-recommends ttf-mscorefonts-installer \
    && apt-get clean && \
    fc-cache -f -v && \ # Rebuild font cache to make newly installed fonts available
    rm -rf /var/lib/apt/lists/*

# Create a non-root user and group for security and permission handling
ARG APP_USER_UID=1000
ARG APP_USER_GID=1000
RUN groupadd --gid $APP_USER_GID appgroup && \
    useradd --uid $APP_USER_UID --gid appgroup --shell /bin/bash --create-home appuser

# Set the working directory (this will also be appuser's home directory)
WORKDIR /home/appuser/app

# Copy requirements.txt first to leverage Docker build cache
COPY --chown=appuser:appgroup requirements.txt ./

# Upgrade pip and install Python dependencies as the appuser
USER appuser
RUN python -m pip install --no-cache-dir --upgrade pip
RUN python -m pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code as the appuser
# This ensures correct ownership from the start
COPY --chown=appuser:appgroup . .

# Expose Streamlit's default port
EXPOSE 8501

# Command to run Streamlit
# Using server.headless=true is good practice for containers.
# Streamlit will try to create .streamlit in the user's home dir (/home/appuser)
CMD ["streamlit", "run", "app.py", "--server.headless=true", "--server.port=8501", "--server.fileWatcherType=none"]