From 6f904438e26cec7d8b5c63ee1342f436339101a5 Mon Sep 17 00:00:00 2001 From: Dmitrii Krosh Date: Fri, 10 Jul 2026 00:03:30 +0300 Subject: [PATCH] add docker --- .dockerignore | 12 ++++++++++++ Dockerfile | 20 ++++++++++++++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++-- docker-compose.yml | 8 ++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b435f3e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.git +.venv +__pycache__ +.pytest_cache +*.pyc +*.pyo +*.pyd +*.sqlite3 +bot.sqlite3 +data +config.toml +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..af5657c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.13-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY bot.py ./ +COPY vpn_bot ./vpn_bot + +RUN useradd --create-home --uid 10001 botuser \ + && mkdir -p /app/data \ + && chown -R botuser:botuser /app + +USER botuser + +CMD ["python", "bot.py", "--config", "/app/config.toml"] diff --git a/README.md b/README.md index 0cc69eb..cacafc3 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ The bot uses: - `PUT /api/user/{username}` - `POST /api/user/{username}/reset` -## Install +## Install locally ```bash python -m venv .venv @@ -49,12 +49,54 @@ cp config.example.toml config.toml Edit `config.toml`. -## Run +For local runs, `database_path = "bot.sqlite3"` is fine. + +## Run locally ```bash python bot.py --config config.toml ``` +## Run with Docker Compose + +Copy and edit the config first: + +```bash +cp config.example.toml config.toml +mkdir -p data +``` + +For Docker Compose, set the SQLite path in `config.toml` to the mounted data directory: + +```toml +database_path = "/app/data/bot.sqlite3" +``` + +Start the bot: + +```bash +docker compose up -d --build +``` + +View logs: + +```bash +docker compose logs -f vpn-bot +``` + +Stop the bot: + +```bash +docker compose down +``` + +Files used by Docker: + +- `Dockerfile` builds a small Python image for the bot. +- `docker-compose.yml` mounts `./config.toml` read-only into the container. +- `docker-compose.yml` mounts `./data` to `/app/data` so SQLite data persists across restarts/rebuilds. +- `.dockerignore` keeps secrets, local DB files, virtualenvs, and caches out of the image build context. + ## Admin usage Start the bot from an admin Telegram account, then use: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5a2c1f9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +services: + vpn-bot: + build: . + container_name: marzban-vpn-bot + restart: unless-stopped + volumes: + - ./config.toml:/app/config.toml:ro + - ./data:/app/data