diff --git a/dockerfile b/dockerfile index 9c79aaf..ded24ea 100644 --- a/dockerfile +++ b/dockerfile @@ -1,4 +1,4 @@ -# Use official Python image +# Builder stage using slim Python image FROM python:3.11-slim as builder # Install system dependencies for building @@ -18,27 +18,30 @@ COPY requirements.txt . RUN --mount=type=cache,target=/root/.cache/pip \ pip install --no-cache-dir -r requirements.txt -# Final stage -FROM python:3.11-slim +# Final stage - using smaller base image +FROM python:3.11-alpine3.18 + +# Install minimal runtime dependencies +RUN apk add --no-cache \ + tini \ + && rm -rf /var/cache/apk/* # 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 +RUN addgroup -S bot && adduser -S bot -G bot -# Copy the rest of the application -COPY --chown=bot:bot . . +# Copy necessary files +COPY --chown=bot:bot *.py ./ +COPY --chown=bot:bot entrypoint.sh ./ +# Add other necessary directories/files as needed -# Create directories for persistent storage and modify permissions +# Create directories for persistent storage RUN mkdir -p logs embed && \ chown -R bot:bot /app logs embed && \ chmod -R 777 /app logs embed @@ -49,6 +52,8 @@ USER bot # Set environment variables for configuration ENV PYTHONUNBUFFERED=1 ENV CONFIG_PATH=/app/config.ini +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONPYCACHEPREFIX=/tmp # Run the bot using tini and entrypoint script ENTRYPOINT ["tini", "--", "/bin/sh", "entrypoint.sh"] \ No newline at end of file