add docker

This commit is contained in:
2026-07-10 00:03:30 +03:00
parent 11f03eae41
commit 6f904438e2
4 changed files with 84 additions and 2 deletions
+12
View File
@@ -0,0 +1,12 @@
.git
.venv
__pycache__
.pytest_cache
*.pyc
*.pyo
*.pyd
*.sqlite3
bot.sqlite3
data
config.toml
.env
+20
View File
@@ -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"]
+44 -2
View File
@@ -38,7 +38,7 @@ The bot uses:
- `PUT /api/user/{username}` - `PUT /api/user/{username}`
- `POST /api/user/{username}/reset` - `POST /api/user/{username}/reset`
## Install ## Install locally
```bash ```bash
python -m venv .venv python -m venv .venv
@@ -49,12 +49,54 @@ cp config.example.toml config.toml
Edit `config.toml`. Edit `config.toml`.
## Run For local runs, `database_path = "bot.sqlite3"` is fine.
## Run locally
```bash ```bash
python bot.py --config config.toml 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 ## Admin usage
Start the bot from an admin Telegram account, then use: Start the bot from an admin Telegram account, then use:
+8
View File
@@ -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