Optimize runner Docker image building
All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 19m17s

This commit is contained in:
2025-09-10 08:13:08 -07:00
parent dc26245136
commit e469da706c
3 changed files with 42 additions and 34 deletions

View File

@@ -1,23 +1,36 @@
# Use official Python image
FROM python:3.11-slim
FROM python:3.11-slim as builder
# Set working directory
WORKDIR /app
# Install dependencies
# Install system dependencies for building
RUN apt-get update && apt-get install -y \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Install tini for better signal handling in container
RUN apt-get update && apt-get install -y tini
# 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
RUN pip install --no-cache-dir -r 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
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Install tini for better signal handling in container
RUN apt-get update && apt-get install -y tini && \
rm -rf /var/lib/apt/lists/*
# 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
@@ -26,14 +39,9 @@ RUN groupadd -r bot && useradd -r -g bot bot
COPY --chown=bot:bot . .
# Create directories for persistent storage and modify permissions
RUN chown -R bot:bot /app && \
chmod -R 777 /app
RUN mkdir -p logs && \
chown -R bot:bot logs && \
chmod -R 777 logs && \
mkdir -p embed && \
chown -R bot:bot embed && \
chmod -R 777 embed
RUN mkdir -p logs embed && \
chown -R bot:bot /app logs embed && \
chmod -R 777 /app logs embed
# Switch to non root user
USER bot