Spaces:
Runtime error

File size: 1,540 Bytes
4a8764a
 
 
 
fd4d03c
 
 
4a8764a
 
 
fd4d03c
 
 
4a8764a
 
 
fd4d03c
 
4a8764a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd4d03c
4a8764a
 
 
02eb874
4a8764a
fd4d03c
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
# ==========================================
# STAGE 1: Build & Compile Dependencies
# ==========================================
FROM python:3.11-slim AS builder

WORKDIR /app

# Install system compilation tools required for premium crypto libraries (TGCrypto)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    gcc \
    && rm -rf /var/lib/apt/lists/*

# Upgrade pip and copy requirements
RUN python -m pip install --no-cache-dir --upgrade pip

COPY requirements.txt .

# Install dependencies into a localized wheels folder
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt


# ==========================================
# STAGE 2: Final Runtime Environment
# ==========================================
FROM python:3.11-slim AS runner

WORKDIR /app

# Create a secure, non-privileged system user to prevent container breakout exploits
RUN useradd -u 8888 appuser && chown -R appuser:appuser /app

# Copy compiled wheels from the builder stage
COPY --from=builder /app/wheels /wheels
COPY --from=builder /app/requirements.txt .

# Install the pre-compiled packages safely
RUN pip install --no-cache /wheels/*

# Copy the actual application source code into the container
COPY --chown=appuser:appuser bot.py .

# Drop root privileges and switch to our secure user
USER appuser

# Enforce Python logs to flush directly to stdout/stderr without buffering
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# Execute the application engine
CMD ["python", "bot.py"]