forked from Anda4ka/telegram-supervisor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
90 lines (67 loc) · 2.17 KB
/
Dockerfile
File metadata and controls
90 lines (67 loc) · 2.17 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
79
80
81
82
83
84
85
86
87
88
89
90
# Multi-stage build for optimized production image
FROM ghcr.io/astral-sh/uv:0.8.11-alpine AS dependencies
# Install system dependencies
RUN apk add --no-cache \
postgresql-client \
gcc \
python3-dev \
musl-dev \
linux-headers \
protobuf-dev
WORKDIR /app
ENV UV_PYTHON=3.12
# Copy dependency files for better caching
COPY pyproject.toml uv.lock README.md ./
# Install dependencies to virtual environment
RUN uv sync --frozen --python 3.12 --no-dev
# Development stage
FROM ghcr.io/astral-sh/uv:0.8.11-alpine AS development
# Install system dependencies
RUN apk add --no-cache \
postgresql-client \
gcc \
python3-dev \
musl-dev \
linux-headers
WORKDIR /app
ENV UV_PYTHON=3.12
# Copy dependency files for better caching
COPY pyproject.toml uv.lock README.md ./
# Install ALL dependencies including dev for development
RUN uv sync --frozen --python 3.12
# Copy application source code
COPY app/ ./app/
COPY alembic/ ./alembic/
COPY alembic.ini ./
COPY scripts/ ./scripts/
# Make sure we use venv
ENV PATH="/app/.venv/bin:$PATH"
# Make scripts executable
RUN chmod +x scripts/*.sh
# Development doesn't need to change user - keep as root for easier volume mounting
# Production stage
FROM python:3.12-alpine AS production
# Install runtime dependencies only
# Symlink python3 to /usr/bin so relocated venv scripts resolve correctly
RUN apk add --no-cache postgresql-client procps && \
ln -sf /usr/local/bin/python3 /usr/bin/python3
WORKDIR /app
# Copy virtual environment from dependencies stage
COPY --from=dependencies /app/.venv /app/.venv
# Copy application source code
COPY app/ ./app/
COPY alembic/ ./alembic/
COPY alembic.ini ./
COPY scripts/ ./scripts/
# Make sure we use venv
ENV PATH="/app/.venv/bin:$PATH"
# Create non-root user, logs dir, and set permissions
RUN addgroup -g 1001 -S appgroup && \
adduser -S appuser -u 1001 -G appgroup && \
chmod +x scripts/*.sh && \
mkdir -p /app/logs && \
chown -R appuser:appgroup /app
USER appuser
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD pgrep -f "python -m app.presentation.telegram" > /dev/null || exit 1
ENTRYPOINT ["scripts/entrypoint.sh"]