-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (60 loc) · 2.13 KB
/
Copy pathDockerfile
File metadata and controls
78 lines (60 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 蔚-上城人 Discord Bot - Production Dockerfile
# Multi-stage build for optimized image size
# Stage 1: Builder
FROM python:3.11.10-slim AS builder
# Set environment variables for Python
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
POETRY_VERSION=1.8.2 \
POETRY_HOME="/opt/poetry" \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_VIRTUALENVS_CREATE=true
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - \
&& ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry
# Set working directory
WORKDIR /app
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Install dependencies (without dev dependencies)
RUN poetry install --no-dev --no-root --no-interaction --no-ansi
# Stage 2: Runtime
FROM python:3.11.10-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH="/app:/app/src" \
PATH="/app/.venv/bin:$PATH"
# Install runtime dependencies (FFmpeg, libopus for voice features)
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libopus0 \
libopus-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create app user (non-root for security)
RUN useradd -m -u 1000 -s /bin/bash appuser
# Set working directory
WORKDIR /app
# Copy virtual environment from builder
COPY --from=builder --chown=appuser:appuser /app/.venv /app/.venv
# Copy application code
COPY --chown=appuser:appuser . .
# Create necessary directories
RUN mkdir -p logs static/audio static/builds ddragon_cache opgg_cache .prom_multiproc && \
chown -R appuser:appuser logs static ddragon_cache opgg_cache .prom_multiproc
# Switch to non-root user
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD python -c "import sys; sys.exit(0)" || exit 1
# Default command (will be overridden in docker-compose)
CMD ["python", "main.py"]