Skip to content

Commit

Permalink
Add docker compose and add db
Browse files Browse the repository at this point in the history
  • Loading branch information
XetPy1030 committed Nov 20, 2024
1 parent 69c1df7 commit b9b13d1
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 2 deletions.
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.12-slim

WORKDIR /app

# Устанавливаем зависимости для системы (например, для Poetry и компиляции пакетов)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Устанавливаем Poetry
ENV POETRY_VERSION=1.6.1
RUN curl -sSL https://install.python-poetry.org | python3 -

# Добавляем Poetry в PATH
ENV PATH="/root/.local/bin:$PATH"

# Копируем файлы проекта в контейнер
COPY pyproject.toml poetry.lock ./

# Устанавливаем зависимости проекта
RUN poetry install --no-root --only main

# Копируем оставшиеся файлы проекта в контейнер
COPY . .

# Определяем команду по умолчанию для контейнера
CMD ["poetry", "run", "python", "main.py"]
File renamed without changes.
10 changes: 10 additions & 0 deletions app/database/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from tortoise import Tortoise


async def init():
await Tortoise.init(
db_url='sqlite://db.sqlite3',
modules={'models': ['app.database.models']}
)
# Генерируем схемы
await Tortoise.generate_schemas()
14 changes: 14 additions & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from tortoise import models, fields


class GoalTimeMessageChat(models.Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=255)
chat_id = fields.IntField()
message_id = fields.IntField()
goal_time = fields.DatetimeField()

created_at = fields.DatetimeField(auto_now_add=True)

class Meta:
table = "goal_time_message_chat"
60 changes: 60 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: '3.8'

services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: app
volumes:
- .:/app
command: python main.py
depends_on:
- redis
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0

celery:
build:
context: .
dockerfile: Dockerfile
container_name: celery
volumes:
- .:/app
command: celery -A main worker --loglevel=info
depends_on:
- redis
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0

celery_beat:
build:
context: .
dockerfile: Dockerfile
container_name: celery_beat
volumes:
- .:/app
command: celery -A main beat --loglevel=info
depends_on:
- redis
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0

redis:
image: redis:6.2
container_name: redis
ports:
- "6379:6379"

postgres:
image: postgres:17
container_name: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- "5432:5432"
14 changes: 13 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import asyncio

from loguru import logger

async def main():
from app import database


def configure_logging():
pass


async def main():
configure_logging()

await database.init()

logger.info('Starting bot...')


if __name__ == '__main__':
asyncio.run(main())
332 changes: 331 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"
telethon = "^1.38.1"
tortoise-orm = {extras = ["asyncpg"], version = "^0.22.0"}
loguru = "^0.7.2"


[build-system]
Expand Down

0 comments on commit b9b13d1

Please sign in to comment.