Add Docker support and improve PDF conversion

Features:
- Dockerfile for containerized deployment
- Docker Compose configuration with health checks
- Automated database initialization via entrypoint script
- Quick start script for easy Docker deployment
- Comprehensive Docker deployment documentation (DOCKER.md)
- Complete README with installation and usage instructions
- .dockerignore for optimized image builds

Improvements:
- PDF conversion now preserves orientation (portrait/landscape)
- PDF rendering at 300 DPI for sharp quality
- Maintains aspect ratio during conversion
- Compact media library view with image thumbnails
- Better media preview with scrollable gallery

Docker Features:
- Multi-stage build for smaller images
- Non-root user for security
- Health checks for container monitoring
- Volume mounts for persistent data
- Production-ready Gunicorn configuration
- Support for Redis caching (optional)
This commit is contained in:
DigiServer Developer
2025-11-17 21:05:49 +02:00
parent 2e3e181bb2
commit 2db0033bc0
9 changed files with 827 additions and 42 deletions

252
DOCKER.md Normal file
View File

@@ -0,0 +1,252 @@
# Docker Deployment Guide
## Quick Start
### 1. Build and Run with Docker Compose
```bash
# Build the Docker image
docker-compose build
# Start the container
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the container
docker-compose down
```
The application will be available at `http://localhost:5000`
Default credentials:
- Username: `admin`
- Password: `admin123`
### 2. Build Docker Image Only
```bash
# Build the image
docker build -t digiserver-v2:latest .
# Run the container
docker run -d \
-p 5000:5000 \
-v $(pwd)/instance:/app/instance \
-v $(pwd)/app/static/uploads:/app/app/static/uploads \
--name digiserver \
digiserver-v2:latest
```
## Configuration
### Environment Variables
Create a `.env` file based on `.env.example`:
```bash
cp .env.example .env
```
Edit the `.env` file to set your configuration:
- `SECRET_KEY`: Change to a random secret key
- `FLASK_ENV`: Set to `production` for production deployments
### Persistent Data
The following directories are mounted as volumes:
- `./instance`: Database storage
- `./app/static/uploads`: Uploaded media files
These persist even when containers are recreated.
## Production Deployment
### 1. Using Docker Compose (Recommended)
```bash
# Create .env file with production settings
cp .env.example .env
nano .env # Edit with your settings
# Start in production mode
docker-compose up -d
```
### 2. Behind a Reverse Proxy (Nginx/Traefik)
Example Nginx configuration:
```nginx
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# For large file uploads
client_max_body_size 100M;
}
}
```
### 3. Enable Redis Caching (Optional)
Uncomment the Redis service in `docker-compose.yml`:
```yaml
redis:
image: redis:7-alpine
container_name: digiserver-redis
restart: unless-stopped
volumes:
- redis-data:/data
volumes:
redis-data:
```
Update `.env`:
```
REDIS_URL=redis://redis:6379/0
```
## Backup
### Database Backup
```bash
# Backup database
docker exec digiserver tar -czf /tmp/backup.tar.gz /app/instance
docker cp digiserver:/tmp/backup.tar.gz ./backup-$(date +%Y%m%d).tar.gz
```
### Full Backup (Database + Uploads)
```bash
# Backup everything
tar -czf digiserver-backup-$(date +%Y%m%d).tar.gz instance/ app/static/uploads/
```
## Maintenance
### View Logs
```bash
# All logs
docker-compose logs -f
# Last 100 lines
docker-compose logs --tail=100
# Specific service
docker-compose logs -f digiserver
```
### Update Application
```bash
# Pull latest code
git pull
# Rebuild and restart
docker-compose down
docker-compose build
docker-compose up -d
```
### Shell Access
```bash
# Access container shell
docker-compose exec digiserver bash
# Or with docker directly
docker exec -it digiserver bash
```
## Troubleshooting
### Port Already in Use
Change the port mapping in `docker-compose.yml`:
```yaml
ports:
- "8080:5000" # Change 8080 to your desired port
```
### Permission Issues
Ensure the volumes have correct permissions:
```bash
sudo chown -R 1000:1000 instance/ app/static/uploads/
```
### Container Won't Start
Check logs:
```bash
docker-compose logs digiserver
```
### Reset Database
```bash
# Stop containers
docker-compose down
# Remove database
rm instance/*.db
# Start fresh
docker-compose up -d
```
## System Requirements
- Docker 20.10+
- Docker Compose 2.0+
- 2GB RAM minimum
- 10GB disk space for media files
## Security Recommendations
1. **Change default credentials** immediately after first login
2. **Set a strong SECRET_KEY** in `.env`
3. **Use HTTPS** with a reverse proxy in production
4. **Regular backups** of database and uploads
5. **Update regularly** to get security patches
6. **Restrict network access** using firewall rules
7. **Monitor logs** for suspicious activity
## Performance Tuning
### Adjust Workers
Edit `Dockerfile` CMD line:
```dockerfile
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "8", "--timeout", "120", "app.app:create_app()"]
```
### Resource Limits
Add to `docker-compose.yml`:
```yaml
services:
digiserver:
# ... existing config ...
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
```