Refactor Docker configuration and improve database initialization
- Updated `.dockerignore` to streamline ignored files and directories, focusing on essential components. - Removed obsolete `Dockerfile.bot` to simplify the build process. - Enhanced `run_helper.py` with a new `init_db` function to initialize the SQLite database if it doesn't exist, improving setup reliability. - Removed the `/status` endpoint from `server_prometheus.py` to clean up unused functionality and improve code clarity.
This commit is contained in:
54
Dockerfile
Normal file
54
Dockerfile
Normal file
@@ -0,0 +1,54 @@
|
||||
###########################################
|
||||
# Этап 1: Сборщик (Builder)
|
||||
###########################################
|
||||
FROM python:3.9-alpine as builder
|
||||
|
||||
# Устанавливаем инструменты для компиляции + linux-headers для psutil
|
||||
RUN apk add --no-cache \
|
||||
gcc \
|
||||
g++ \
|
||||
musl-dev \
|
||||
python3-dev \
|
||||
linux-headers # ← ЭТО КРИТИЧЕСКИ ВАЖНО ДЛЯ psutil
|
||||
|
||||
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
|
||||
|
||||
# Минимальные рантайм-зависимости
|
||||
RUN apk add --no-cache \
|
||||
libstdc++ \
|
||||
sqlite-libs
|
||||
|
||||
# Создаем пользователя
|
||||
RUN addgroup -g 1001 deploy && adduser -D -u 1001 -G deploy deploy
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Копируем зависимости
|
||||
COPY --from=builder --chown=1001:1001 /install /usr/local/lib/python3.9/site-packages
|
||||
|
||||
# Создаем структуру папок
|
||||
RUN mkdir -p database logs voice_users && \
|
||||
chown -R 1001:1001 /app
|
||||
|
||||
# Копируем исходный код
|
||||
COPY --chown=1001:1001 . .
|
||||
|
||||
USER 1001
|
||||
|
||||
# Healthcheck
|
||||
HEALTHCHECK --interval=30s --timeout=15s --start-period=10s --retries=5 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/health', timeout=5)" || exit 1
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["python", "-u", "run_helper.py"]
|
||||
Reference in New Issue
Block a user