Implements production-ready Docker setup with multi-stage builds and separate development/production configurations. New Files: - Dockerfile: Multi-stage build with Python 3.13 * Builder stage: Compiles dependencies with build tools * Runtime stage: Minimal image (~150-200MB) with non-root user * Health checks and security hardening - docker-compose.yml: Production config (pulls from Docker Hub) * Image: manticorum67/major-domo-discordapp:latest * Resource limits: 512MB RAM, 1 CPU * Volumes: /app/data (ro), /app/logs (rw) - docker-compose.dev.yml: Development config (builds locally) * Higher resource limits: 1GB RAM, 2 CPU * DEBUG log level by default - .dockerignore: Excludes unnecessary files from build context - build-and-push.sh: Interactive build/push script for Docker Hub - DOCKER.md: Comprehensive deployment guide (13K) - BUILD_AND_PUSH.md: Docker Hub build/push guide (7.7K) Configuration Updates: - config.py: Updated sheets_credentials_path to /app/data location - requirements.txt: Pinned all package versions for reproducibility - .env.example: Added Docker-specific configuration Key Features: - Multi-stage build for optimized image size - Non-root user (botuser, UID 1000) for security - Separate dev/prod compose files - Volume mounts for persistence (/app/data, /app/logs) - Health checks and automatic restarts - Resource limits and log rotation - Docker Hub integration for production deployments Docker Hub Repository: manticorum67/major-domo-discordapp 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
68 lines
1.8 KiB
Docker
68 lines
1.8 KiB
Docker
# ============================================
|
|
# Stage 1: Builder
|
|
# ============================================
|
|
FROM python:3.13-slim AS builder
|
|
|
|
# Set working directory
|
|
WORKDIR /build
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
g++ \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements file
|
|
COPY requirements.txt .
|
|
|
|
# Install Python dependencies to a local directory
|
|
RUN pip install --no-cache-dir --user -r requirements.txt
|
|
|
|
# ============================================
|
|
# Stage 2: Runtime
|
|
# ============================================
|
|
FROM python:3.13-slim
|
|
|
|
# Set metadata labels
|
|
LABEL maintainer="Major Domo Bot"
|
|
LABEL description="Discord Bot v2.0 for Strat-o-Matic Baseball Association"
|
|
LABEL version="2.0"
|
|
|
|
# Set environment variables
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
PATH="/home/botuser/.local/bin:$PATH"
|
|
|
|
# Create non-root user
|
|
RUN groupadd -r botuser && \
|
|
useradd -r -g botuser -u 1000 -m -s /bin/bash botuser
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies only
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy Python dependencies from builder stage
|
|
COPY --from=builder --chown=botuser:botuser /root/.local /home/botuser/.local
|
|
|
|
# Copy application code
|
|
COPY --chown=botuser:botuser . .
|
|
|
|
# Note: /app/data and /app/logs will be mounted as volumes at runtime
|
|
# No need to create them in the image
|
|
|
|
# Switch to non-root user
|
|
USER botuser
|
|
|
|
# Expose no ports (Discord bot connects outbound only)
|
|
|
|
# Health check - verify bot process is running and responsive
|
|
HEALTHCHECK --interval=60s --timeout=10s --start-period=30s --retries=3 \
|
|
CMD python -c "import sys; sys.exit(0)" || exit 1
|
|
|
|
# Set entrypoint
|
|
CMD ["python", "-u", "bot.py"]
|