File size: 1,718 Bytes
8cf8241
853c436
 
8cf8241
853c436
 
8cf8241
853c436
 
 
 
 
959dce1
 
853c436
 
8cf8241
 
b5267d4
 
8cf8241
3ad7721
8cf8241
 
 
 
b5267d4
8cf8241
 
 
 
3ad7721
1055087
8cf8241
b5267d4
 
 
 
 
853c436
959dce1
8cf8241
 
959dce1
 
853c436
 
959dce1
 
853c436
959dce1
b5267d4
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
# Use Python 3.9 slim as the base image
FROM python:3.9-slim

# Set working directory
WORKDIR /app

# Install necessary dependencies for OpenCV, PyTorch, and other utilities
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    software-properties-common \
    git \
    libgl1-mesa-glx \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user to avoid permission issues
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app

# Switch to non-root user
USER appuser

# Set environment variables for Streamlit and Hugging Face
ENV STREAMLIT_CONFIG_DIR=/app/.streamlit
ENV HF_HOME=/app/.cache/huggingface
ENV STREAMLIT_SERVER_FILE_WATCHER_TYPE=none
ENV PATH=/home/appuser/.local/bin:$PATH

# Create necessary directories with correct permissions
RUN mkdir -p /app/.streamlit /app/.cache/huggingface
RUN chmod -R 777 /app/.streamlit /app/.cache

# Copy the requirements and install them
COPY --chown=appuser:appuser requirements.txt ./
RUN pip3 install --user --no-cache-dir -r requirements.txt
RUN pip3 install --user --no-cache-dir streamlit

# Verify Streamlit installation
RUN streamlit --version || { echo "Streamlit installation failed"; exit 1; }

# Copy the source code and modules directory
COPY --chown=appuser:appuser src/ ./src/
COPY --chown=appuser:appuser modules/ ./modules/

# Expose the port that Streamlit will run on
EXPOSE 8501

# Health check to ensure the container is running properly
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1

# Set the entry point to run the Streamlit app
ENTRYPOINT ["/home/appuser/.local/bin/streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]