File size: 1,358 Bytes
711e594
3d3009d
 
 
75d3db2
711e594
 
0e10ee2
711e594
3d3009d
0e10ee2
1149ecf
0e10ee2
 
 
 
 
 
 
 
 
711e594
3d3009d
75d3db2
711e594
3d3009d
0e10ee2
 
 
1149ecf
0e10ee2
 
1149ecf
75d3db2
 
1149ecf
75d3db2
711e594
0e10ee2
75d3db2
1149ecf
 
 
 
0e10ee2
 
 
1149ecf
 
 
75d3db2
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
FROM python:3.11-slim

WORKDIR /app

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

# Upgrade pip first
RUN pip install --no-cache-dir --upgrade pip

# Install specific versions to match your trained models
RUN pip install --no-cache-dir \
    numpy==1.26.4 \
    scikit-learn==1.7.0 \
    joblib==1.4.0

# Copy and install remaining dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code and model files
COPY . .

# Debug: List all files and check model files
RUN echo "=== Directory contents ===" && ls -la
RUN echo "=== Looking for model files ===" && find . -name "*.pkl" -o -name "*.joblib" || echo "No model files found"

# Set proper permissions
RUN chmod 644 *.pkl 2>/dev/null || echo "No .pkl files found to set permissions"

# Create a non-root user for security
RUN useradd -m -u 1000 user
RUN chown -R user:user /app
USER user

# Environment variables
ENV PORT=7860
ENV MODEL_PATH=./isoforest_dos.pkl
ENV SCALER_PATH=./scaler_dos.pkl
ENV ENCODER_PATH=./encoder_dos.pkl

EXPOSE $PORT

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:$PORT/health || exit 1

CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port $PORT"]