feat: Add Docker Compose setup for the bot and PostgreSQL database, and update Dockerfile to expose port 8000 and unbuffer Python output.

This commit is contained in:
virtus
2026-01-16 19:39:45 +07:00
parent b24365927a
commit e120474b9d
3 changed files with 72 additions and 4 deletions
+4
View File
@@ -14,4 +14,8 @@ RUN useradd --create-home --shell /bin/bash app && \
chown -R app:app /app
USER app
ENV PYTHONUNBUFFERED=1
EXPOSE 8000
CMD ["uv", "run", "python", "main.py"]
+35 -2
View File
@@ -76,7 +76,40 @@ virtus-bot/
```
## Docker Support
Dự án hỗ trợ chạy bằng Docker.
Dự án hỗ trợ triển khai nhanh bằng Docker Compose với image đã được build sẵn.
### Yêu cầu
- Docker
- Docker Compose
### Cài đặt và chạy
1. Tạo file `.env` (nếu chưa có):
```bash
docker-compose up --build -d
cp CONFIG_EXAMPLE.md .env
# Hoặc tạo mới và điền các giá trị cần thiết
```
> **Lưu ý Database**:
> - Mặc định, bot sẽ kết nối tới Postgres container được tạo kèm trong `docker-compose.yml`.
> - Nếu bạn muốn dùng Database riêng (bên ngoài Docker hoặc host khác), hãy cấu hình biến `POSTGRES_URL` trong file `.env`.
> - Nếu dùng Database mặc định, bạn không cần sửa `POSTGRES_URL`.
2. Chạy ứng dụng:
```bash
docker-compose up -d
```
3. Cập nhật phiên bản mới nhất:
```bash
docker-compose pull
docker-compose up -d
```
4. Truy cập Admin Dashboard tại `http://localhost:8000`.
### Cấu hình Docker Compose
File `docker-compose.yml` bao gồm:
- `bot`: Sử dụng image `fevirtus/virtus-bot:latest`.
- `db`: PostgreSQL 15 (chạy song song phục vụ cho bot).
- Dữ liệu được lưu tại volume `postgres_data`.
+31
View File
@@ -0,0 +1,31 @@
version: '3.8'
services:
bot:
image: fevirtus/virtus-bot:latest
container_name: virtus_bot
restart: always
ports:
- "8000:8000"
environment:
- BOT_TOKEN=${BOT_TOKEN}
- POSTGRES_URL=${POSTGRES_URL:-postgresql+asyncpg://virtus:password@db:5432/virtus_bot}
depends_on:
- db
command: uv run python main.py
db:
image: postgres:15-alpine
container_name: virtus_db
restart: always
environment:
- POSTGRES_USER=${POSTGRES_USER:-virtus}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
- POSTGRES_DB=${POSTGRES_DB:-virtus_bot}
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
postgres_data: