Files
prod/Dockerfile.optimized
Andrey 81a4069623 Refactor Ansible playbook for improved server setup and monitoring
- Update SSH user configuration for enhanced security
- Add tasks for UFW setup and Docker service management
- Optimize data migration processes for bots
- Implement checks for database permissions and sizes
- Clean up temporary files post-migration
2025-09-16 00:43:45 +03:00

45 lines
1.7 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
###########################################
# Этап 1: Сборщик (Builder)
###########################################
FROM python:3.9-slim as builder
# Устанавливаем ТОЧНО ТОЛЬКО то, что нужно для компиляции
RUN apt-get update && apt-get install --no-install-recommends -y \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
# Критически важный момент: устанавливаем в отдельную папку
RUN pip install --no-cache-dir --target /install -r requirements.txt
###########################################
# Этап 2: Финальный образ (Runtime)
###########################################
# Используем ОЧЕНЬ легковесный базовый образ
FROM python:3.9-alpine as runtime
# В Alpine Linux свои пакеты. apk вместо apt.
# Устанавливаем минимальные рантайм-зависимости для psutil и подобных.
RUN apk add --no-cache libstdc++
# Создаем пользователя (в Alpine другие команды)
RUN addgroup -g 1000 monitor && \
adduser -D -u 1000 -G monitor monitor
WORKDIR /app
# Копируем зависимости из сборщика
COPY --from=builder --chown=1000:1000 /install /usr/local/lib/python3.9/site-packages
# Копируем исходный код
COPY --chown=1000:1000 . .
USER 1000
# Важно: явно указываем Python искать зависимости в скопированной директории
ENV PYTHONPATH="/usr/local/lib/python3.9/site-packages:${PYTHONPATH}"
CMD ["python", "infra/monitoring/main.py"]