Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files12345678910111213141516171819202122# Use a slim Python imageFROM python:3.10-slim# Set working directoryWORKDIR /app# Install system dependencies for tgcrypto and speedRUN apt-get update && apt-get install -y \gcc \python3-dev \&& rm -rf /var/lib/apt/lists/*# Copy and install requirementsCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txt# Copy the bot codeCOPY . .# Run the botCMD ["python", "bot.py"]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051# ==========================================# STAGE 1: Build & Compile Dependencies# ==========================================FROM python:3.11-slim AS builderWORKDIR /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 requirementsRUN python -m pip install --no-cache-dir --upgrade pipCOPY requirements.txt .# Install dependencies into a localized wheels folderRUN 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 runnerWORKDIR /app# Create a secure, non-privileged system user to prevent container breakout exploitsRUN useradd -u 8888 appuser && chown -R appuser:appuser /app# Copy compiled wheels from the builder stageCOPY --from=builder /app/wheels /wheelsCOPY --from=builder /app/requirements.txt .# Install the pre-compiled packages safelyRUN pip install --no-cache /wheels/*# Copy the actual application source code into the containerCOPY --chown=appuser:appuser bot.py .# Drop root privileges and switch to our secure userUSER appuser# Enforce Python logs to flush directly to stdout/stderr without bufferingENV PYTHONUNBUFFERED=1ENV PYTHONDONTWRITEBYTECODE=1# Execute the application engineCMD ["python", "bot.py"]
Dockerfile+40-11