Spaces:
Runtime error

Testingpot / Dockerfile
dpadhan's picture
Update Dockerfile
4a8764a verified
Raw History Blame Contribute Delete
1.54 kB
# ==========================================
# 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"]