mirror of
https://github.com/EDeev/alertbot.git
synced 2026-10-07 20:49:56 +03:00
Docker: образ на python:3.12-slim, compose с томом для базы
Лог в файл стал необязательным (ALERTBOT_LOG_FILE): в контейнере пишем только в stdout.
This commit is contained in:
parent
4a77957e93
commit
56638f5878
4 changed files with 45 additions and 2 deletions
8
.dockerignore
Normal file
8
.dockerignore
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
**/__pycache__
|
||||||
|
.env
|
||||||
|
tests
|
||||||
|
*.md
|
||||||
|
*.db
|
||||||
|
*.log
|
||||||
17
Dockerfile
Normal file
17
Dockerfile
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
ALERTBOT_LOG_FILE= \
|
||||||
|
PYTHONUNBUFFERED=1 \
|
||||||
|
ALERTBOT_DB=/data/notifications.db
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY *.py ./
|
||||||
|
RUN useradd --create-home --uid 1000 app && mkdir -p /data && chown -R app:app /app /data
|
||||||
|
USER app
|
||||||
|
VOLUME ["/data"]
|
||||||
|
|
||||||
|
CMD ["python", "bot.py"]
|
||||||
8
bot.py
8
bot.py
|
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from aiogram.types import BotCommand
|
from aiogram.types import BotCommand
|
||||||
|
|
@ -7,11 +8,14 @@ from aiogram.types import BotCommand
|
||||||
from init import bot, dp
|
from init import bot, dp
|
||||||
from handlers import router, alert_poller
|
from handlers import router, alert_poller
|
||||||
|
|
||||||
|
_log_handlers = [logging.StreamHandler(sys.stdout)]
|
||||||
|
# File log is optional: in Docker set ALERTBOT_LOG_FILE= (empty) and read `docker logs`
|
||||||
|
if os.environ.get("ALERTBOT_LOG_FILE", "bot.log"):
|
||||||
|
_log_handlers.append(logging.FileHandler(os.environ.get("ALERTBOT_LOG_FILE", "bot.log"), encoding="utf-8"))
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
handlers=[logging.StreamHandler(sys.stdout),
|
handlers=_log_handlers,
|
||||||
logging.FileHandler('bot.log', encoding='utf-8')],
|
|
||||||
)
|
)
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
||||||
14
compose.yaml
Normal file
14
compose.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
services:
|
||||||
|
bot:
|
||||||
|
build: .
|
||||||
|
image: ghcr.io/edeev/alertbot:latest
|
||||||
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
ALERTBOT_DB: /data/notifications.db
|
||||||
|
ALERTBOT_LOG_FILE: ""
|
||||||
|
volumes:
|
||||||
|
- data:/data
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
data:
|
||||||
Loading…
Add table
Reference in a new issue