File size: 1,644 Bytes
f238bbd
5511aad
 
f238bbd
5511aad
 
f238bbd
5511aad
 
 
 
 
 
 
f238bbd
5511aad
f238bbd
5511aad
cb7e73c
 
 
 
 
 
5511aad
a55dc06
 
f238bbd
a55dc06
 
cb7e73c
a55dc06
 
cb7e73c
a55dc06
 
 
cb7e73c
 
 
 
 
 
 
f238bbd
 
5511aad
 
a55dc06
 
 
f238bbd
 
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
# Use Python 3.9 slim image
FROM python:3.9-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    software-properties-common \
    git \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install Python dependencies
COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt

# Set NLTK data directory to a location with proper permissions
ENV NLTK_DATA=/usr/local/share/nltk_data
RUN mkdir -p $NLTK_DATA

# Download NLTK data as root (with permissions) and handle SSL issues
RUN python -c "import ssl; ssl._create_default_https_context = ssl._create_unverified_context; import nltk; nltk.download('stopwords', download_dir='/usr/local/share/nltk_data'); nltk.download('wordnet', download_dir='/usr/local/share/nltk_data'); nltk.download('omw-1.4', download_dir='/usr/local/share/nltk_data')"

# Create a non-root user first
RUN useradd -m -u 1000 user

# Copy the application code
COPY --chown=user:user . .

# Create necessary directories with proper permissions for the user
RUN mkdir -p /app/models /app/artifacts /app/vectorizers
RUN chown -R user:user /app
RUN chmod -R 755 /app

# Switch to non-root user
USER user

# Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONPATH=/app \
    NLTK_DATA=/usr/local/share/nltk_data

# Expose the port that Streamlit runs on
EXPOSE 8501

# Health check
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

# Run the application
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]