Refactor project structure and enhance Docker support
- Removed unnecessary `__init__.py` and `Dockerfile` to streamline project organization. - Updated `.dockerignore` and `.gitignore` to improve exclusion patterns for build artifacts and environment files. - Enhanced `Makefile` with new commands for managing Docker containers and added help documentation. - Introduced `pyproject.toml` for better project metadata management and dependency tracking. - Updated `requirements.txt` to reflect changes in dependencies for metrics and monitoring. - Refactored various handler files to improve code organization and maintainability.
This commit is contained in:
124
Makefile
124
Makefile
@@ -1,88 +1,68 @@
|
||||
.PHONY: help test test-db test-coverage test-html clean install test-monitor
|
||||
.PHONY: help build up down logs clean restart status
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@echo "Available commands:"
|
||||
@echo " install - Install dependencies"
|
||||
@echo " test - Run all tests"
|
||||
@echo " test-db - Run database tests only"
|
||||
@echo " test-bot - Run bot startup and handler tests only"
|
||||
@echo " test-media - Run media handler tests only"
|
||||
@echo " test-errors - Run error handling tests only"
|
||||
@echo " test-utils - Run utility functions tests only"
|
||||
@echo " test-keyboards - Run keyboard and filter tests only"
|
||||
@echo " test-monitor - Test server monitoring module"
|
||||
@echo " test-coverage - Run tests with coverage report (helper_bot + database)"
|
||||
@echo " test-html - Run tests and generate HTML coverage report"
|
||||
@echo " clean - Clean up generated files"
|
||||
@echo " coverage - Show coverage report only"
|
||||
help: ## Показать справку
|
||||
@echo "🐍 Telegram Bot - Доступные команды (Python 3.9):"
|
||||
@echo ""
|
||||
@echo "🔧 Основные команды:"
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||
@echo ""
|
||||
@echo "📊 Мониторинг:"
|
||||
@echo " Prometheus: http://localhost:9090"
|
||||
@echo " Grafana: http://localhost:3000 (admin/admin)"
|
||||
|
||||
# Install dependencies
|
||||
install:
|
||||
python3 -m pip install -r requirements.txt
|
||||
python3 -m pip install pytest-cov
|
||||
build: ## Собрать все контейнеры с Python 3.9
|
||||
docker-compose build
|
||||
|
||||
# Run all tests
|
||||
test:
|
||||
python3 -m pytest tests/ -v
|
||||
up: ## Запустить все сервисы с Python 3.9
|
||||
docker-compose up -d
|
||||
|
||||
# Run database tests only
|
||||
test-db:
|
||||
python3 -m pytest tests/test_db.py -v
|
||||
down: ## Остановить все сервисы
|
||||
docker-compose down
|
||||
|
||||
# Run bot tests only
|
||||
test-bot:
|
||||
python3 -m pytest tests/test_bot.py -v
|
||||
logs: ## Показать логи всех сервисов
|
||||
docker-compose logs -f
|
||||
|
||||
# Run media handler tests only
|
||||
test-media:
|
||||
python3 -m pytest tests/test_media_handlers.py -v
|
||||
logs-bot: ## Показать логи бота
|
||||
docker-compose logs -f telegram-bot
|
||||
|
||||
# Run error handling tests only
|
||||
test-errors:
|
||||
python3 -m pytest tests/test_error_handling.py -v
|
||||
logs-prometheus: ## Показать логи Prometheus
|
||||
docker-compose logs -f prometheus
|
||||
|
||||
# Run utils tests only
|
||||
test-utils:
|
||||
python3 -m pytest tests/test_utils.py -v
|
||||
logs-grafana: ## Показать логи Grafana
|
||||
docker-compose logs -f grafana
|
||||
|
||||
# Run keyboard and filter tests only
|
||||
test-keyboards:
|
||||
python3 -m pytest tests/test_keyboards_and_filters.py -v
|
||||
restart: ## Перезапустить все сервисы (с пересборкой Python 3.9)
|
||||
docker-compose down
|
||||
docker-compose build
|
||||
docker-compose up -d
|
||||
|
||||
# Test server monitoring module
|
||||
test-monitor:
|
||||
python3 tests/test_monitor.py
|
||||
status: ## Показать статус контейнеров
|
||||
docker-compose ps
|
||||
|
||||
# Test auto unban scheduler
|
||||
test-auto-unban:
|
||||
python3 -m pytest tests/test_auto_unban_scheduler.py -v
|
||||
check-python: ## Проверить версию Python в контейнере
|
||||
@echo "🐍 Проверяю версию Python в контейнере..."
|
||||
@docker exec telegram-bot .venv/bin/python --version || echo "Контейнер не запущен"
|
||||
|
||||
# Test auto unban integration
|
||||
test-auto-unban-integration:
|
||||
python3 -m pytest tests/test_auto_unban_integration.py -v
|
||||
test-compatibility: ## Тест совместимости с Python 3.8+
|
||||
@echo "🐍 Тестирую совместимость с Python 3.8+..."
|
||||
@python3 test_python38_compatibility.py
|
||||
|
||||
# Run tests with coverage
|
||||
test-coverage:
|
||||
python3 -m pytest tests/ --cov=helper_bot --cov=database --cov-report=term
|
||||
clean: ## Очистить все контейнеры и образы Python 3.9
|
||||
docker-compose down -v --rmi all
|
||||
docker system prune -f
|
||||
|
||||
# Run tests and generate HTML coverage report
|
||||
test-html:
|
||||
python3 -m pytest tests/ --cov=helper_bot --cov=database --cov-report=html:htmlcov --cov-report=term
|
||||
@echo "HTML coverage report generated in htmlcov/index.html"
|
||||
|
||||
# Show coverage report only
|
||||
coverage:
|
||||
python3 -m coverage report --include="helper_bot/*,database/*"
|
||||
|
||||
# Clean up generated files
|
||||
clean:
|
||||
rm -rf htmlcov/
|
||||
rm -f coverage.xml
|
||||
rm -f .coverage
|
||||
rm -f database/test.db
|
||||
rm -f test.db
|
||||
rm -f helper_bot.pid
|
||||
rm -f voice_bot.pid
|
||||
find . -type d -name "__pycache__" -exec rm -rf {} +
|
||||
find . -type f -name "*.pyc" -delete
|
||||
start: build up ## Собрать и запустить все сервисы с Python 3.9
|
||||
@echo "🐍 Python 3.9 контейнер собран и запущен!"
|
||||
@echo "📊 Prometheus: http://localhost:9090"
|
||||
@echo "📈 Grafana: http://localhost:3000 (admin/admin)"
|
||||
@echo "🤖 Бот запущен в контейнере с Python 3.9"
|
||||
@echo "📝 Логи: make logs"
|
||||
|
||||
start-script: ## Запустить через скрипт start_docker.sh
|
||||
@echo "🐍 Запуск через скрипт start_docker.sh..."
|
||||
@./start_docker.sh
|
||||
|
||||
stop: down ## Остановить все сервисы
|
||||
@echo "🛑 Все сервисы остановлены"
|
||||
|
||||
Reference in New Issue
Block a user