Spaces:
Runtime error

dpadhan commited on
Commit
4a8764a
·
verified ·
1 Parent(s): a38c7ab

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +40 -11
Dockerfile CHANGED
@@ -1,22 +1,51 @@
1
- # Use a slim Python image
2
- FROM python:3.10-slim
 
 
3
 
4
- # Set working directory
5
  WORKDIR /app
6
 
7
- # Install system dependencies for tgcrypto and speed
8
- RUN apt-get update && apt-get install -y \
 
9
  gcc \
10
- python3-dev \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
- # Copy and install requirements
 
 
14
  COPY requirements.txt .
15
- RUN pip install --no-cache-dir -r requirements.txt
16
 
17
- # Copy the bot code
18
- COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
 
 
 
20
 
21
- # Run the bot
22
  CMD ["python", "bot.py"]
 
1
+ # ==========================================
2
+ # STAGE 1: Build & Compile Dependencies
3
+ # ==========================================
4
+ FROM python:3.11-slim AS builder
5
 
 
6
  WORKDIR /app
7
 
8
+ # Install system compilation tools required for premium crypto libraries (TGCrypto)
9
+ RUN apt-get update && apt-get install -y --no-install-recommends \
10
+ build-essential \
11
  gcc \
 
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Upgrade pip and copy requirements
15
+ RUN python -m pip install --no-cache-dir --upgrade pip
16
+
17
  COPY requirements.txt .
 
18
 
19
+ # Install dependencies into a localized wheels folder
20
+ RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
21
+
22
+
23
+ # ==========================================
24
+ # STAGE 2: Final Runtime Environment
25
+ # ==========================================
26
+ FROM python:3.11-slim AS runner
27
+
28
+ WORKDIR /app
29
+
30
+ # Create a secure, non-privileged system user to prevent container breakout exploits
31
+ RUN useradd -u 8888 appuser && chown -R appuser:appuser /app
32
+
33
+ # Copy compiled wheels from the builder stage
34
+ COPY --from=builder /app/wheels /wheels
35
+ COPY --from=builder /app/requirements.txt .
36
+
37
+ # Install the pre-compiled packages safely
38
+ RUN pip install --no-cache /wheels/*
39
+
40
+ # Copy the actual application source code into the container
41
+ COPY --chown=appuser:appuser bot.py .
42
+
43
+ # Drop root privileges and switch to our secure user
44
+ USER appuser
45
 
46
+ # Enforce Python logs to flush directly to stdout/stderr without buffering
47
+ ENV PYTHONUNBUFFERED=1
48
+ ENV PYTHONDONTWRITEBYTECODE=1
49
 
50
+ # Execute the application engine
51
  CMD ["python", "bot.py"]