Skip to content

Commit d98aaf6

Browse files
Dependencies update: August 2024 (#28)
* Updated dependencies * Updated code to use new pydantic-settings and new aiogram * Using distroless docker image to run bot
1 parent 1011771 commit d98aaf6

7 files changed

+96
-31
lines changed

Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Separate "build" image
2-
FROM python:3.11-slim-bullseye as compile-image
2+
FROM python:3.11-slim-bookworm as compile-image
33
RUN python -m venv /opt/venv
44
ENV PATH="/opt/venv/bin:$PATH"
55
COPY requirements.txt .
66
RUN pip install --no-cache-dir --upgrade pip \
77
&& pip install --no-cache-dir -r requirements.txt
88

99
# "Run" image
10-
FROM python:3.11-slim-bullseye
11-
COPY --from=compile-image /opt/venv /opt/venv
12-
ENV PATH="/opt/venv/bin:$PATH"
10+
FROM gcr.io/distroless/python3
1311
WORKDIR /app
12+
COPY --from=compile-image /opt/venv /app/venv
13+
ENV PYTHONPATH="/app/venv/lib/python3.11/site-packages"
1414
COPY bot /app/bot
15-
CMD ["python", "-m", "bot"]
15+
CMD ["-m", "bot"]

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2023 Groosha (also known as MasterGroosha on GitHub)
3+
Copyright (c) 2019-2024 Groosha (also known as MasterGroosha on GitHub)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This is a simple bot written with [aiogram 3.x](https://github.com/aiogram/aiogr
1515
* Group to supergroup migrate information (both old and new ID).
1616

1717
## Requirements:
18-
* Python 3.9 and newer;
18+
* Python 3.11 and newer;
1919
* Linux (should work on Windows, but not tested);
2020
* Systemd init system (optional).
2121
* Docker (optional).

bot/__main__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import structlog
55
from aiogram import Bot, Dispatcher
6+
from aiogram.client.default import DefaultBotProperties
7+
from aiogram.enums import ParseMode
68
from structlog.typing import FilteringBoundLogger
79

810
from bot.config_reader import bot_config, log_config
@@ -18,7 +20,12 @@
1820
async def main():
1921
structlog.configure(**get_structlog_config(log_config))
2022

21-
bot = Bot(bot_config.bot_token.get_secret_value(), parse_mode="HTML")
23+
bot = Bot(
24+
bot_config.bot_token.get_secret_value(),
25+
default=DefaultBotProperties(
26+
parse_mode=ParseMode.HTML,
27+
)
28+
)
2229

2330
# Setup dispatcher and bind routers to it
2431
dp = Dispatcher()

bot/config_reader.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
from enum import Enum
1+
from enum import StrEnum, auto
22

3-
from pydantic import BaseSettings, SecretStr
3+
from pydantic import SecretStr
4+
from pydantic_settings import BaseSettings, SettingsConfigDict
45

56

6-
class ModeEnum(str, Enum):
7-
DEVELOPMENT = "dev"
8-
PRODUCTION = "prod"
9-
10-
11-
class LoggingRenderer(str, Enum):
12-
JSON = "json"
13-
CONSOLE = "console"
7+
class LoggingRenderer(StrEnum):
8+
JSON = auto()
9+
CONSOLE = auto()
1410

1511

1612
class LoggingSettings(BaseSettings):
@@ -20,18 +16,22 @@ class LoggingSettings(BaseSettings):
2016
renderer: LoggingRenderer = LoggingRenderer.JSON
2117
log_unhandled: bool = False
2218

23-
class Config:
24-
env_file = '.env'
25-
env_file_encoding = 'utf-8'
26-
env_prefix = "LOGGING_"
19+
model_config = SettingsConfigDict(
20+
env_file=".env",
21+
env_file_encoding="UTF-8",
22+
env_prefix="LOGGING_",
23+
extra="allow",
24+
)
2725

2826

2927
class BotSettings(BaseSettings):
3028
bot_token: SecretStr
3129

32-
class Config:
33-
env_file = '.env'
34-
env_file_encoding = 'utf-8'
30+
model_config = SettingsConfigDict(
31+
env_file=".env",
32+
env_file_encoding="UTF-8",
33+
extra="allow",
34+
)
3535

3636

3737
bot_config = BotSettings()

my-id-bot.example.service

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ After=network.target
55
[Service]
66
Type=simple
77
WorkingDirectory=/home/user/my-id-bot
8+
EnvironmentFile=/home/user/my-id-bot/.env
89
ExecStart=/home/user/my-id-bot/venv/bin/python -m bot
910
KillMode=process
1011
Restart=always

requirements.txt

+63-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,63 @@
1-
aiogram==3.0.0b7
2-
cachetools==5.3.0
3-
python-dotenv==1.0.0
4-
pydantic==1.10.6
5-
fluent.runtime==0.4.0
6-
structlog==22.3.0
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile requirements.in -o requirements.txt
3+
aiofiles==23.2.1
4+
# via aiogram
5+
aiogram==3.12.0
6+
# via -r requirements.in
7+
aiohappyeyeballs==2.3.5
8+
# via aiohttp
9+
aiohttp==3.10.3
10+
# via aiogram
11+
aiosignal==1.3.1
12+
# via aiohttp
13+
annotated-types==0.7.0
14+
# via pydantic
15+
attrs==24.2.0
16+
# via
17+
# aiohttp
18+
# fluent-runtime
19+
babel==2.16.0
20+
# via fluent-runtime
21+
cachetools==5.4.0
22+
# via -r requirements.in
23+
certifi==2024.7.4
24+
# via aiogram
25+
fluent-runtime==0.4.0
26+
# via -r requirements.in
27+
fluent-syntax==0.19.0
28+
# via fluent-runtime
29+
frozenlist==1.4.1
30+
# via
31+
# aiohttp
32+
# aiosignal
33+
idna==3.7
34+
# via yarl
35+
magic-filter==1.0.12
36+
# via aiogram
37+
multidict==6.0.5
38+
# via
39+
# aiohttp
40+
# yarl
41+
pydantic==2.8.2
42+
# via
43+
# aiogram
44+
# pydantic-settings
45+
pydantic-core==2.20.1
46+
# via pydantic
47+
pydantic-settings==2.4.0
48+
# via -r requirements.in
49+
python-dotenv==1.0.1
50+
# via pydantic-settings
51+
pytz==2024.1
52+
# via fluent-runtime
53+
structlog==24.4.0
54+
# via -r requirements.in
55+
typing-extensions==4.12.2
56+
# via
57+
# aiogram
58+
# fluent-runtime
59+
# fluent-syntax
60+
# pydantic
61+
# pydantic-core
62+
yarl==1.9.4
63+
# via aiohttp

0 commit comments

Comments
 (0)