Update OPENCODE.md with Dockerfile docs and CI/CD information
Changes: - Add Dockerfile Configuration section with code example - Document Debian-based image choice (python:3.11-slim) - Add all system dependencies (libgl1, libsm6, etc.) - Extend Common Issues with Docker build troubleshooting - New CI/CD section for Gitea Actions - Document both workflows (autobuild and manual) - Add required secrets and registry configuration - Add version history overview
This commit is contained in:
104
OPENCODE.md
104
OPENCODE.md
@@ -13,25 +13,31 @@ This is a Telegram bot for managing sticker packs. Built with python-telegram-bo
|
|||||||
- **Video Processing**: FFmpeg for GIF to WebM conversion
|
- **Video Processing**: FFmpeg for GIF to WebM conversion
|
||||||
- **Background Removal**: rembg (local) + remove.bg API (optional)
|
- **Background Removal**: rembg (local) + remove.bg API (optional)
|
||||||
- **Container**: Docker + Docker Compose
|
- **Container**: Docker + Docker Compose
|
||||||
|
- **Base Image**: python:3.11-slim (Debian-based for better compatibility)
|
||||||
- **Environment**: python-dotenv for configuration
|
- **Environment**: python-dotenv for configuration
|
||||||
|
|
||||||
### Project Structure
|
### Dockerfile Configuration
|
||||||
```
|
```dockerfile
|
||||||
stickerbot/
|
FROM python:3.11-slim
|
||||||
├── bot.py # Main bot with ConversationHandler
|
|
||||||
├── config.py # Configuration and environment loading
|
# System dependencies for OpenCV, FFmpeg and rembg
|
||||||
├── database.py # SQLite database operations
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
├── sticker_manager.py # Sticker management utilities
|
ffmpeg \
|
||||||
├── image_processor.py # Automatic image conversion
|
libgl1 \
|
||||||
├── gif_processor.py # GIF to WebM conversion
|
libglib2.0-0 \
|
||||||
├── background_remover.py # Background removal (local + API)
|
libsm6 \
|
||||||
├── requirements.txt # Python dependencies
|
libxext6 \
|
||||||
├── Dockerfile # Docker image configuration
|
libxrender-dev \
|
||||||
├── docker-compose.yml # Docker Compose configuration
|
libgomp1 \
|
||||||
├── .env.example # Environment template
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
└── data/ # Persistent data directory
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Key points:**
|
||||||
|
- Uses `python:3.11-slim` (Debian-based) instead of Alpine for better Python package compatibility
|
||||||
|
- Includes OpenCV dependencies: `libgl1`, `libglib2.0-0`, `libsm6`, `libxext6`, `libxrender-dev`
|
||||||
|
- Includes `libgomp1` for OpenMP support (required by numba/llvmlite)
|
||||||
|
- Non-root user for security
|
||||||
|
|
||||||
### Database Schema
|
### Database Schema
|
||||||
- **sticker_sets**: Tracks created sticker sets (user_id, set_name, set_title, timestamps)
|
- **sticker_sets**: Tracks created sticker sets (user_id, set_name, set_title, timestamps)
|
||||||
- **user_premium**: Caches user premium status with last check timestamp
|
- **user_premium**: Caches user premium status with last check timestamp
|
||||||
@@ -321,9 +327,21 @@ sudo docker-compose up -d --build --force-recreate
|
|||||||
5. **API limit reached**: Check current usage with `/hilfe` or in database
|
5. **API limit reached**: Check current usage with `/hilfe` or in database
|
||||||
6. **Background removal slow**: First run downloads ML model (~180MB)
|
6. **Background removal slow**: First run downloads ML model (~180MB)
|
||||||
7. **GIF conversion fails**: Ensure GIF is under 10MB before upload
|
7. **GIF conversion fails**: Ensure GIF is under 10MB before upload
|
||||||
|
8. **Docker build fails with Alpine**: We use `python:3.11-slim` (Debian) instead of Alpine because rembg requires compilation tools that don't work well with Alpine's musl libc
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Docker Build Issues
|
||||||
|
If the Docker build fails with package errors:
|
||||||
|
```bash
|
||||||
|
# The Dockerfile uses Debian-based python:3.11-slim
|
||||||
|
# NOT Alpine - this is intentional for better Python package compatibility
|
||||||
|
|
||||||
|
# Check Dockerfile has correct base image:
|
||||||
|
grep "FROM" Dockerfile
|
||||||
|
# Should show: FROM python:3.11-slim
|
||||||
|
```
|
||||||
|
|
||||||
### Bot not responding
|
### Bot not responding
|
||||||
```bash
|
```bash
|
||||||
# Check if container is running
|
# Check if container is running
|
||||||
@@ -344,3 +362,59 @@ sudo docker-compose restart
|
|||||||
- Verify REMOVE_BG_API_KEY is correct
|
- Verify REMOVE_BG_API_KEY is correct
|
||||||
- Check API usage in database: `sqlite3 data/sticker_bot.db "SELECT * FROM api_usage;"`
|
- Check API usage in database: `sqlite3 data/sticker_bot.db "SELECT * FROM api_usage;"`
|
||||||
- API automatically falls back to local processing on errors
|
- API automatically falls back to local processing on errors
|
||||||
|
|
||||||
|
## CI/CD with Gitea Actions
|
||||||
|
|
||||||
|
The project includes automated Docker builds via Gitea Actions.
|
||||||
|
|
||||||
|
### Workflow Files
|
||||||
|
|
||||||
|
**`.gitea/workflows/docker-autobuild.yaml`** - Automatic builds on push
|
||||||
|
- Triggers on push to `main` or `master` branch
|
||||||
|
- Builds and pushes to local registry: `192.168.88.201:5000`
|
||||||
|
- Tags: `latest` and `v{run_number}-autobuild`
|
||||||
|
- Features:
|
||||||
|
- Path ignores for markdown/docs changes
|
||||||
|
- Docker Buildx with layer caching
|
||||||
|
- Automatic cleanup after build
|
||||||
|
|
||||||
|
**`.gitea/workflows/docker-build.yaml`** - Manual builds
|
||||||
|
- Triggered manually via Gitea web interface
|
||||||
|
- Options:
|
||||||
|
- Custom version tag (e.g., `1.0.0`, `v1.0.0`)
|
||||||
|
- Additional tags (comma-separated, e.g., `stable,production`)
|
||||||
|
- Toggle `latest` tag
|
||||||
|
- Features:
|
||||||
|
- Flexible versioning
|
||||||
|
- Multiple tag support
|
||||||
|
- Docker layer caching
|
||||||
|
|
||||||
|
### Required Secrets
|
||||||
|
|
||||||
|
Configure these in Gitea repository settings:
|
||||||
|
- `REGISTRY_USERNAME` - Username for Docker registry
|
||||||
|
- `REGISTRY_PASSWORD` - Password for Docker registry
|
||||||
|
|
||||||
|
### Registry Configuration
|
||||||
|
|
||||||
|
Default registry: `192.168.88.201:5000`
|
||||||
|
|
||||||
|
To change the registry, edit both workflow files:
|
||||||
|
```yaml
|
||||||
|
REGISTRY="your-registry:port"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Version History
|
||||||
|
|
||||||
|
See git log for detailed commit history:
|
||||||
|
```bash
|
||||||
|
git log --oneline
|
||||||
|
```
|
||||||
|
|
||||||
|
Current features:
|
||||||
|
- ✅ Telegram Sticker Bot with full management capabilities
|
||||||
|
- ✅ Automatic image optimization (WebP conversion)
|
||||||
|
- ✅ GIF to Video Sticker conversion
|
||||||
|
- ✅ Background removal (local + API)
|
||||||
|
- ✅ Existing sticker set import
|
||||||
|
- ✅ Gitea Actions CI/CD
|
||||||
|
|||||||
Reference in New Issue
Block a user