From 0293bdd523ab0997612bb7fd3dff0eaa00ecd58f Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Fri, 13 Mar 2026 21:55:07 -0400 Subject: [PATCH] [O] Dockerize --- Dockerfile | 24 ++++++++++++++++++++++++ docker-compose.yml | 26 ++++++++++++++++++++++++++ src/db.py | 11 ++++++++--- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ed2cd43 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM python:3.13-slim + +# Install uv +COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv + +WORKDIR /app + +# Enable bytecode compilation +ENV UV_COMPILE_BYTECODE=1 + +# Copy project requirements +COPY pyproject.toml uv.lock ./ + +# Install dependencies (but not the project yet) +RUN uv sync --frozen --no-install-project + +# Copy the application code +COPY . . + +# Install the project +RUN uv sync --frozen + +# Start using uv run +CMD ["uv", "run", "python", "src/bot.py"] diff --git a/docker-compose.yml b/docker-compose.yml index d5f1187..8aee5ff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,30 @@ services: + bot: + build: . + container_name: tgtree-bot + restart: unless-stopped + command: ["uv", "run", "python", "src/bot.py"] + depends_on: + - postgres + environment: + - DATABASE_URL=postgresql://cat:meow@postgres:5432/tgtree + ports: + - "127.0.0.1:9498:9498" + volumes: + - .:/app + + gentree: + build: . + container_name: tgtree-gentree + restart: unless-stopped + command: ["uv", "run", "python", "src/gentree.py"] + depends_on: + - postgres + environment: + - DATABASE_URL=postgresql://cat:meow@postgres:5432/tgtree + volumes: + - .:/app + postgres: image: postgres:latest container_name: tgtree-db diff --git a/src/db.py b/src/db.py index 88ca209..a057cce 100644 --- a/src/db.py +++ b/src/db.py @@ -1,10 +1,15 @@ from peewee import Model, CharField, ForeignKeyField, IntegerField, BigIntegerField, BooleanField, CompositeKey, PostgresqlDatabase +from playhouse.db_url import connect from utils import CONFIG -# Database configuration -db = PostgresqlDatabase('tgtree', user='cat', - password=CONFIG["db-pass"], host=CONFIG["db-host"], port=CONFIG["db-port"]) +import os + +# Default local connection string based on config.toml (if any) +default_db_url = CONFIG.get("db-url", "postgresql://cat:meow@127.0.0.1:5444/tgtree") +db_url = os.environ.get("DATABASE_URL", default_db_url) + +db = connect(db_url) class BaseModel(Model):