File size: 2,119 Bytes
e947927
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
FROM python:3.10-slim

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements file
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code
COPY . .

# Create all necessary directories with proper permissions
RUN mkdir -p /app/tmp \
             /app/.config/matplotlib \
             /app/.cache \
             /app/.local && \
    chmod -R 777 /app/tmp /app/.config /app/.cache /app/.local

# Set comprehensive environment variables
ENV TMPDIR=/app/tmp \
    TEMP=/app/tmp \
    TMP=/app/tmp \
    MPLCONFIGDIR=/app/.config/matplotlib \
    XDG_CACHE_HOME=/app/.cache \
    XDG_CONFIG_HOME=/app/.config \
    HOME=/app \
    MPLBACKEND=Agg \
    PYTHONUNBUFFERED=1

# Expose the port FastAPI will run on
EXPOSE 7860

# Command to run the FastAPI application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]


# # Builder stage
# FROM python:3.10-slim AS builder
# WORKDIR /app
# COPY requirements.txt .
# RUN apt-get update && apt-get install -y gcc g++ \
#     && pip install --no-cache-dir -r requirements.txt \
#     && apt-get purge -y gcc g++ \
#     && apt-get autoremove -y \
#     && rm -rf /var/lib/apt/lists/*

# # Runtime stage
# FROM python:3.10-slim
# WORKDIR /app
# COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
# COPY . .
# # Create TMP directories
# RUN mkdir -p /app/tmp /app/.config/matplotlib /app/.cache /app/.local && \
#     chmod -R 777 /app/tmp /app/.config /app/.cache /app/.local
# ENV TMPDIR=/app/tmp \
#     TEMP=/app/tmp \
#     TMP=/app/tmp \
#     MPLCONFIGDIR=/app/.config/matplotlib \
#     XDG_CACHE_HOME=/app/.cache \
#     XDG_CONFIG_HOME=/app/.config \
#     HOME=/app \
#     MPLBACKEND=Agg \
#     PYTHONUNBUFFERED=1
# EXPOSE 7860
# CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]