# ๐Ÿณ Docker Testing Guide - ROA2WEB Telegram Bot This guide provides instructions for testing the Telegram bot Docker deployment. ## ๐Ÿ“‹ Prerequisites Before testing Docker deployment: - [ ] Docker Engine installed (version 20.10+) - [ ] Docker Compose installed (version 2.0+) - [ ] At least 2GB RAM available for containers - [ ] At least 10GB disk space available ## ๐Ÿ” Pre-Build Verification ### 1. Check Dockerfile Syntax ```bash cd /path/to/roa2web/backend/modules/telegram # Verify Dockerfile exists and is valid cat Dockerfile # Check for common issues grep -n "COPY\|RUN\|ENV" Dockerfile ``` **Expected**: - Multi-stage build with `builder` and `production` stages - Non-root user `telegrambot` created - All required dependencies installed - Tini init system configured - Health check defined ### 2. Verify Required Files ```bash # Check all required files exist ls -la app/ ls -la requirements.txt ls -la .env.example ls -la Dockerfile ``` **Required files**: - โœ… `Dockerfile` - โœ… `requirements.txt` - โœ… `.env.example` - โœ… `app/` directory with all modules - โœ… `.dockerignore` (optional but recommended) ### 3. Check .dockerignore ```bash cat .dockerignore ``` **Should exclude**: - `venv/` - `__pycache__/` - `*.pyc` - `.env` - `data/*.db` - `.git/` - `tests/` --- ## ๐Ÿ—๏ธ Build Tests ### Test 1: Build Telegram Bot Image ```bash cd /path/to/roa2web/backend/modules/telegram # Build the image docker build -t roa2web/telegram-bot:test --target production . ``` **Expected**: - โœ… Build completes without errors - โœ… Both stages (builder + production) execute - โœ… Final image size < 500MB (typically ~300-400MB) - โœ… No security warnings in output **Troubleshooting**: - If build fails at requirements install โ†’ check `requirements.txt` syntax - If permission errors โ†’ ensure Dockerfile uses correct user - If large image size โ†’ verify multi-stage build is working ### Test 2: Inspect Built Image ```bash # Check image size docker images roa2web/telegram-bot:test # Inspect image details docker inspect roa2web/telegram-bot:test # Check layers docker history roa2web/telegram-bot:test ``` **Expected**: - Image size: 300-450 MB - Base: `python:3.11-slim` - User: `telegrambot` (not root) - Working dir: `/app` - Health check configured ### Test 3: Build with Docker Compose ```bash cd /path/to/roa2web # Build telegram-bot service docker-compose build roa-telegram-bot ``` **Expected**: - โœ… Service builds successfully - โœ… Image tagged as `roa2web/telegram-bot:latest` - โœ… No errors or warnings --- ## ๐Ÿš€ Runtime Tests ### Test 4: Run Standalone Container (Without Backend) ```bash # Create test .env file cat > .env.test < CLAUDE_API_KEY= BACKEND_URL=http://roa-backend:8000 SQLITE_DB_PATH=/app/data/telegram_bot.db INTERNAL_API_PORT=8002 ``` ### Test 9: Network Connectivity ```bash # Test bot can reach backend docker exec roa-telegram-bot curl -v http://roa-backend:8000/health # Test backend can reach bot internal API docker exec roa-backend curl -v http://roa-telegram-bot:8002/internal/health ``` **Expected**: - โœ… Both services can communicate via `roa-network` - โœ… DNS resolution works (service names resolve) - โœ… Health endpoints return 200 OK ### Test 10: Logs and Monitoring ```bash # View real-time logs docker-compose logs -f roa-telegram-bot # View last 100 lines docker-compose logs --tail=100 roa-telegram-bot # Search for errors docker-compose logs roa-telegram-bot | grep -i error ``` **Expected**: - โœ… Logs are readable and structured - โœ… No critical errors - โœ… Log level respects `LOG_LEVEL` env var --- ## ๐Ÿ”’ Security Tests ### Test 11: User Permissions ```bash # Check container is not running as root docker exec roa-telegram-bot whoami # Expected: telegrambot # Check file permissions docker exec roa-telegram-bot ls -la /app/ # Expected: All files owned by telegrambot:telegrambot ``` ### Test 12: Port Exposure ```bash # Check exposed ports docker port roa-telegram-bot # Should only show: # 8002/tcp -> 0.0.0.0:8002 ``` **Expected**: - โœ… Only internal API port (8002) exposed - โœ… No unnecessary ports open ### Test 13: Volume Mounts ```bash # Check volumes docker volume inspect roa2web_telegram-bot-data # Check mount point docker inspect roa-telegram-bot | grep -A 10 Mounts ``` **Expected**: - โœ… Only `/app/data` is mounted - โœ… Volume is named `telegram-bot-data` - โœ… No sensitive files mounted --- ## ๐Ÿงช Integration Tests ### Test 14: Full Stack Integration ```bash # Start all services cd /path/to/roa2web docker-compose up -d # Wait for all services to be healthy docker-compose ps # Test complete flow: # 1. Backend generates auth code # 2. Bot verifies code # 3. User links account # 4. Bot queries backend API ``` **Test Steps**: 1. **Generate Auth Code via Backend**: ```bash curl -X POST http://localhost:8000/api/telegram/auth/generate-code \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{"telegram_user_id": 123456}' ``` 2. **Verify Code in Bot Database**: ```bash docker exec roa-telegram-bot sqlite3 /app/data/telegram_bot.db \ "SELECT * FROM telegram_auth_codes WHERE telegram_user_id = 123456;" ``` 3. **Link via Telegram Bot**: - Send code to bot via Telegram app - Verify linking succeeds 4. **Query Dashboard**: - Ask bot: "Show dashboard for company 1" - Verify data is retrieved from backend --- ## ๐Ÿ›‘ Cleanup ### Remove Test Containers ```bash # Stop and remove containers docker-compose down # Remove volumes (WARNING: deletes data) docker-compose down -v # Remove images docker rmi roa2web/telegram-bot:test docker rmi roa2web/telegram-bot:latest ``` ### Clean Build Cache ```bash # Remove build cache docker builder prune -a # Remove unused images docker image prune -a ``` --- ## ๐Ÿ“Š Test Results Checklist | Test ID | Description | Status | Notes | |---------|-------------|--------|-------| | 1 | Build telegram-bot image | โฌœ | | | 2 | Inspect image | โฌœ | | | 3 | Build with docker-compose | โฌœ | | | 4 | Run standalone container | โฌœ | | | 5 | Run with docker-compose | โฌœ | | | 6 | Health check | โฌœ | | | 7 | Database persistence | โฌœ | | | 8 | Environment variables | โฌœ | | | 9 | Network connectivity | โฌœ | | | 10 | Logs and monitoring | โฌœ | | | 11 | User permissions | โฌœ | | | 12 | Port exposure | โฌœ | | | 13 | Volume mounts | โฌœ | | | 14 | Full stack integration | โฌœ | | **Overall Result**: โฌœ PASS โฌœ FAIL --- ## ๐Ÿ› Common Issues & Solutions ### Issue 1: Build Fails - "requirements.txt not found" **Solution**: Ensure you're in the correct directory (`telegram-bot/`) when building ### Issue 2: Permission Denied Errors **Solution**: Check Dockerfile uses correct user and permissions are set with `chown` ### Issue 3: Health Check Fails **Solution**: - Check internal API is starting on port 8002 - Verify httpx is installed in requirements.txt - Check logs: `docker logs roa-telegram-bot` ### Issue 4: Can't Connect to Backend **Solution**: - Ensure both containers are on `roa-network` - Check backend is healthy before starting bot - Use service name `roa-backend` not `localhost` ### Issue 5: Database Not Persisting **Solution**: - Verify volume is mounted: `docker inspect roa-telegram-bot` - Check volume exists: `docker volume ls | grep telegram-bot-data` - Ensure `/app/data` has write permissions --- ## โœ… Success Criteria For Docker deployment to be considered successful: - โœ… Image builds without errors - โœ… Container starts and runs stably - โœ… Health checks pass - โœ… Bot connects to Telegram API - โœ… Bot connects to backend API - โœ… Database persists across restarts - โœ… No security warnings or vulnerabilities - โœ… Logs are clean (no critical errors) - โœ… All network connectivity works - โœ… Full stack integration succeeds --- **Last Updated**: 2025-10-21