Files
Pterodisbot/dockerfile
T
k.eaven 346e6d9604
CI/CD Pipeline / Unit Tests (Python 3.11) (push) Successful in 29s
CI/CD Pipeline / Unit Tests (Python 3.12) (push) Successful in 30s
CI/CD Pipeline / Code Quality & Linting (push) Successful in 23s
CI/CD Pipeline / Unit Tests (Python 3.13) (push) Successful in 27s
CI/CD Pipeline / Integration Tests (push) Successful in 21s
CI/CD Pipeline / Security Scanning (push) Successful in 2m16s
CI/CD Pipeline / Generate Test Report (push) Successful in 4s
CI/CD Pipeline / Build Docker Image (push) Successful in 44s
CI/CD Pipeline / CI/CD Pipeline Status (push) Successful in 2s
Update: Major code refactor for modular extensibility
2026-10-24 10:58:01 +00:00

65 lines
1.7 KiB
Docker

# Builder stage using slim Python image
FROM python:3.12-slim as builder
# Install system dependencies for building
RUN apt-get update && apt-get install -y \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy requirements first to leverage Docker cache
COPY requirements.txt .
# Install Python dependencies with cache dir
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-cache-dir -r requirements.txt
# Final stage - using slim
FROM python:3.12-slim
# Install minimal runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
tini \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Create a non-root user
RUN groupadd -r bot && useradd -r -g bot bot
# Copy necessary files
COPY --chown=bot:bot *.py ./
COPY --chown=bot:bot entrypoint.sh ./
# Create directories for persistent storage
RUN mkdir -p logs embed && \
chown -R bot:bot /app logs embed && \
chmod -R 777 /app logs embed
# Create and set permissions for matplotlib config directory
RUN mkdir -p /tmp/matplotlib && \
chown -R bot:bot /tmp/matplotlib && \
chmod -R 777 /tmp/matplotlib
# Switch to non root user
USER bot
# Set environment variables for configuration
ENV PYTHONUNBUFFERED=1
ENV CONFIG_PATH=/app/config.ini
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONPYCACHEPREFIX=/tmp
ENV MPLCONFIGDIR=/tmp/matplotlib
ENV MPLBACKEND=Agg
# Run the bot using tini and entrypoint script
ENTRYPOINT ["tini", "--", "python", "main.py"]