Files
telegram-helper-bot/Dockerfile.bot
Andrey fc0517c011 Enhance bot functionality with new features and improvements
- Added a new `/status` endpoint in `server_prometheus.py` to provide process status information, including uptime and resource usage metrics.
- Implemented a PID manager in `run_helper.py` to track the bot's process, improving monitoring capabilities.
- Introduced a method to delete audio moderation records in `audio_repository.py`, enhancing database management.
- Updated voice message handling in callback handlers to ensure proper deletion of audio moderation records.
- Improved error handling and logging in various services, ensuring better tracking of media processing and file downloads.
- Refactored media handling functions to streamline operations and improve code readability.
- Enhanced metrics tracking for file downloads and media processing, providing better insights into bot performance.
2025-09-04 00:46:45 +03:00

77 lines
2.0 KiB
Docker

# Multi-stage build for production
FROM python:3.9-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy and install requirements
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Production stage
FROM python:3.9-slim
# Set security options
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install runtime dependencies only
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
curl \
sqlite3 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user with fixed UID
RUN groupadd -g 1001 deploy && useradd -u 1001 -g deploy deploy
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN chown -R 1001:1001 /opt/venv
# Create app directory and set permissions
WORKDIR /app
RUN mkdir -p /app/database /app/logs /app/voice_users && \
chown -R 1001:1001 /app
# Copy application code
COPY --chown=1001:1001 . .
# Initialize SQLite database with schema
RUN sqlite3 /app/database/tg-bot-database.db < /app/database/schema.sql && \
chown 1001:1001 /app/database/tg-bot-database.db && \
chmod 644 /app/database/tg-bot-database.db
# Switch to non-root user
USER deploy
# Health check with better timeout handling
HEALTHCHECK --interval=30s --timeout=15s --start-period=10s --retries=5 \
CMD curl -f --connect-timeout 5 --max-time 10 http://localhost:8080/health || exit 1
# Expose metrics port
EXPOSE 8080
# Graceful shutdown with longer timeout
STOPSIGNAL SIGTERM
# Set environment variables for better network stability
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONHASHSEED=random
# Run application with proper signal handling
CMD ["python", "-u", "run_helper.py"]