Files
prod/Dockerfile
Andrey dd8b1c02a4 chore: update Python version in Dockerfile and improve test commands in Makefile
- Upgraded Python version in Dockerfile from 3.9 to 3.11.9 for enhanced performance and security.
- Adjusted paths in Dockerfile to reflect the new Python version.
- Modified test commands in Makefile to activate the virtual environment before running tests, ensuring proper dependency management.
2026-01-25 15:27:57 +03:00

46 lines
1.8 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.11.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.11.9-alpine as runtime
# В Alpine Linux свои пакеты. apk вместо apt.
# Устанавливаем минимальные рантайм-зависимости
RUN apk add --no-cache libstdc++
# Создаем пользователя (в Alpine другие команды)
RUN addgroup -g 1000 app && \
adduser -D -u 1000 -G app app
WORKDIR /app
# Копируем зависимости из сборщика (если есть)
COPY --from=builder --chown=1000:1000 /install /usr/local/lib/python3.11/site-packages
# Копируем исходный код
COPY --chown=1000:1000 . .
USER 1000
# Важно: явно указываем Python искать зависимости в скопированной директории
ENV PYTHONPATH="/usr/local/lib/python3.11/site-packages:${PYTHONPATH}"
# Оставляем базовую команду для совместимости
CMD ["python", "-c", "print('Dockerfile готов для использования')"]