File size: 1,031 Bytes
2e94196
d2ba52b
2e94196
d2ba52b
 
 
 
 
 
95c4487
4dc1e6c
d2ba52b
95c4487
d2ba52b
 
95c4487
 
2e94196
 
9a2f1ba
95c4487
d2ba52b
ff1a300
d2ba52b
2e94196
 
 
9a2f1ba
95c4487
 
c86d940
2e94196
d2ba52b
 
95c4487
d2ba52b
 
2e94196
 
 
 
 
 
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
FROM python:3.11-slim

# Install system dependencies with security updates
RUN apt-get update && apt-get install -y \
    curl \
    && apt-get upgrade -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Create non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser -m -u 1000 appuser

# Set working directory
WORKDIR /app

# Copy requirements and install Python packages
COPY requirements.txt .
RUN pip3 install --no-cache-dir --upgrade pip && \
    pip3 install --no-cache-dir -r requirements.txt

# Copy your FastAPI app
COPY fast.py .
COPY app.py .

# Create logs directory and change ownership
RUN mkdir -p /app/logs && \
    chown -R appuser:appuser /app

# Set environment variables
ENV HOME=/home/appuser

# Expose port
EXPOSE 7860

# Switch to non-root user
USER appuser

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

# Start FastAPI application
CMD ["python3", "app.py"]