Files
metabuilder/frontends/emailclient/PHASE_8_INDEX.md
2026-03-09 22:30:41 +00:00

13 KiB

Phase 8: Redis Container - Complete Index

Overview

Phase 8 implements a production-ready Redis 7 container configured as a Celery broker and result backend for the Email Client system. This document serves as an index to all Phase 8 deliverables.

Quick Navigation

Document Purpose Audience
README [This page] Container quick reference Everyone
Deployment docs/DEPLOYMENT.md DevOps, System Admins
Summary PHASE_8_REDIS_SUMMARY.md Architects, Developers
Container Docs deployment/docker/redis/README.md DevOps, Platform Engineers
File Manifest PHASE_8_FILES.txt Reference

Files Created

Redis Container (8 files)

deployment/docker/redis/
├── Dockerfile                 Production Redis 7 Alpine image
├── redis.conf                Complete Redis configuration
├── docker-entrypoint.sh       Container initialization (executable)
├── backup.sh                  Backup/restore tool (executable)
├── monitor.sh                 Monitoring dashboard (executable)
├── README.md                  Container documentation
├── .env.redis                 Environment variables template
└── .dockerignore              Build context exclusions

Docker Compose (3 files)

./
├── docker-compose.yml         Updated with Redis + email-service
├── docker-compose.dev.yml     Development overrides (NEW)
└── docker-compose.prod.yml    Production overrides (NEW)

Documentation (4 files)

./
├── docs/DEPLOYMENT.md         Complete deployment guide (NEW)
├── PHASE_8_REDIS_SUMMARY.md   Implementation summary (NEW)
├── PHASE_8_FILES.txt          File manifest (NEW)
└── PHASE_8_INDEX.md           This file (NEW)

Core Components

1. Dockerfile

Location: deployment/docker/redis/Dockerfile

  • Redis 7 Alpine-based image
  • Health checks with native Docker support
  • Entrypoint script integration
  • Non-root user execution
  • Size: 41 lines

Key Features:

FROM redis:7-alpine
RUN apk add --no-cache curl bash ca-certificates
COPY redis.conf /usr/local/etc/redis/redis.conf
HEALTHCHECK --interval=30s redis-cli --raw incr ping
EXPOSE 6379
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]

2. Redis Configuration

Location: deployment/docker/redis/redis.conf

Memory Management:

  • Max memory: 512MB
  • Eviction policy: allkeys-lru
  • Memory sampling: 5 entries

Persistence:

  • RDB snapshots: 15min/1key, 5min/10keys, 1min/10k keys
  • AOF journaling with everysec fsync
  • Auto-rewrite at 64MB or 100% growth
  • LZF compression enabled

Authentication:

  • Password-based via requirepass directive
  • Substituted from REDIS_PASSWORD environment variable

Size: 223 lines with extensive documentation

3. Entrypoint Script

Location: deployment/docker/redis/docker-entrypoint.sh

  • Environment variable substitution
  • Redis readiness checks (30-attempt loop)
  • Configuration initialization
  • Background health monitoring
  • Error handling and logging

Size: 124 lines Executable: Yes (chmod +x)

4. Backup Tool

Location: deployment/docker/redis/backup.sh

Commands:

  • backup.sh backup - Create RDB backup
  • backup.sh restore <file> - Restore from backup
  • backup.sh analyze - Analyze database
  • backup.sh list - List available backups

Features:

  • BGSAVE with progress monitoring
  • MD5 and SHA256 checksums
  • Manifest generation
  • 30-day retention policy
  • Integrity verification
  • Color-coded output

Size: 306 lines Executable: Yes (chmod +x)

5. Monitoring Script

Location: deployment/docker/redis/monitor.sh

Commands:

  • monitor.sh health - One-time health check
  • monitor.sh monitor - Real-time dashboard (5s refresh)
  • monitor.sh slowlog - Show slow queries
  • monitor.sh stats - Command statistics

Metrics Displayed:

  • Memory usage with warning thresholds
  • Connected clients and blocked clients
  • Commands per second
  • Database size and key count
  • Eviction statistics
  • Persistence status
  • Uptime and role

Size: 329 lines Executable: Yes (chmod +x)

6. Environment Template

Location: deployment/docker/redis/.env.redis

Categories:

  • Redis authentication
  • Redis memory configuration
  • Redis persistence settings
  • Celery broker configuration
  • Celery task configuration
  • Email service integration
  • Development/debugging flags

Size: 80 lines with documentation

Docker Compose Configuration

Updated: docker-compose.yml

redis:
  build:
    context: ./deployment/docker/redis
    dockerfile: Dockerfile
  image: emailclient-redis:latest
  environment:
    REDIS_PASSWORD: ${REDIS_PASSWORD:-redis_development_password}
    REDIS_MAXMEMORY: ${REDIS_MAXMEMORY:-512mb}
    REDIS_MAXMEMORY_POLICY: ${REDIS_MAXMEMORY_POLICY:-allkeys-lru}
  healthcheck:
    test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
    interval: 30s
    timeout: 10s
    retries: 3
    start_period: 5s
  volumes:
    - redis-data:/data
  networks:
    - emailclient-net

New: docker-compose.dev.yml

Development-specific overrides:

  • Default passwords for quick setup
  • Debug logging enabled
  • Suitable for local development

Usage:

docker-compose -f docker-compose.yml -f docker-compose.dev.yml up

New: docker-compose.prod.yml

Production-specific configuration:

  • Strong password requirements
  • Increased memory allocations
  • Resource limits and reservations
  • Enhanced logging (100MB max, 10 files)
  • Volatile eviction policy
  • External volume mounts
  • Comprehensive monitoring

Usage:

docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Quick Start

Development

# 1. Build
docker-compose build redis

# 2. Start
docker-compose up -d redis

# 3. Verify
docker-compose exec redis redis-cli ping
# Output: PONG

# 4. Monitor
./deployment/docker/redis/monitor.sh health

Production

# 1. Generate password
export REDIS_PASSWORD=$(openssl rand -base64 32)

# 2. Build
docker-compose build

# 3. Start
docker-compose -f docker-compose.yml \
               -f docker-compose.prod.yml \
               up -d

# 4. Verify
docker-compose ps
docker-compose exec redis redis-cli -a $REDIS_PASSWORD ping

Integration

Email Service Connection

# services/email_service/celery_app.py
from celery import Celery

app = Celery('email_service')
app.conf.update(
    broker_url=os.getenv('CELERY_BROKER_URL'),
    result_backend=os.getenv('CELERY_RESULT_BACKEND'),
    task_serializer='json',
    result_serializer='json',
)

@app.task
def sync_imap_account(account_id):
    # Background task
    pass

# Usage
sync_imap_account.delay(account_id=123)

Environment Variables

# Required
CELERY_BROKER_URL=redis://:password@redis:6379/0
CELERY_RESULT_BACKEND=redis://:password@redis:6379/0

# Optional
REDIS_PASSWORD=redis_development_password
REDIS_MAXMEMORY=512mb
REDIS_MAXMEMORY_POLICY=allkeys-lru

Key Features

Memory Management

  • Configurable limit (default: 512MB)
  • LRU eviction when limit reached
  • Automatic cleanup of least-used keys

Persistence

  • RDB snapshots for point-in-time recovery
  • AOF journaling for durability
  • Automatic recovery on startup

Monitoring

  • Real-time dashboard with 5s refresh
  • Health checks every 30 seconds
  • Slow query logging
  • Command statistics

Backup & Recovery

  • Automated BGSAVE with progress monitoring
  • Full/partial database restore
  • Checksum verification
  • 30-day retention policy

Security

  • Password authentication
  • Non-root user execution
  • Volume-based persistence
  • Network isolation via docker bridge

Monitoring Commands

# Health check
./deployment/docker/redis/monitor.sh health

# Real-time monitoring
./deployment/docker/redis/monitor.sh monitor

# Slow query log
./deployment/docker/redis/monitor.sh slowlog

# Command statistics
./deployment/docker/redis/monitor.sh stats

# Manual health check
docker-compose exec redis redis-cli ping

# Memory stats
docker-compose exec redis redis-cli INFO memory

# Database size
docker-compose exec redis redis-cli DBSIZE

# Check eviction
docker-compose exec redis redis-cli INFO stats | grep evicted

Backup Operations

# Create backup
./deployment/docker/redis/backup.sh backup
# Output: redis-data/redis_backup_20260124_020000.rdb

# Restore from backup
./deployment/docker/redis/backup.sh restore ./redis_backup_20260124_020000.rdb

# List backups
./deployment/docker/redis/backup.sh list

# Analyze database
./deployment/docker/redis/backup.sh analyze

# Schedule automated backups
0 2 * * * /path/to/backup.sh backup

Troubleshooting

Container Won't Start

# Check logs
docker-compose logs redis

# Verify configuration
docker build -t test-redis deployment/docker/redis/
docker run --rm test-redis redis-cli --help

High Memory Usage

# Check memory stats
docker-compose exec redis redis-cli INFO memory

# Identify large keys
docker-compose exec redis redis-cli --bigkeys

# Check eviction events
./deployment/docker/redis/monitor.sh analyze

Slow Performance

# Check slow log
./deployment/docker/redis/monitor.sh slowlog

# Check command statistics
./deployment/docker/redis/monitor.sh stats

# Monitor in real-time
./deployment/docker/redis/monitor.sh monitor

Performance Characteristics

Baseline Performance

  • Empty container: ~2-3MB RAM
  • 1M keys (avg 100B): ~100-150MB
  • Throughput: 50-100k ops/sec

Scaling Limits

  • Single instance suitable for <50k QPS
  • Scaling options: Cluster, Sentinel, Managed
  • Current configuration: Email client with moderate load

Security Considerations

Development

  • Default password acceptable
  • Debug logging enabled
  • Local network only

Production

  • Strong random password: openssl rand -base64 32
  • Volatile eviction (TTL keys only)
  • External persistent storage
  • Resource limits enforced
  • Comprehensive logging
  • ACL configuration recommended

Documentation Index

Document Location Content
Deployment Guide docs/DEPLOYMENT.md Complete setup and operational guide
Implementation Summary PHASE_8_REDIS_SUMMARY.md Architecture, features, and configuration
Container README deployment/docker/redis/README.md Build, run, and configure container
File Manifest PHASE_8_FILES.txt Complete file listing and descriptions
This Index PHASE_8_INDEX.md Quick navigation and reference

Requirements Checklist

  • Redis 7+ official image (7-alpine)
  • Configure as Celery broker and result backend
  • Set memory limit (512MB)
  • Enable persistence (RDB snapshots)
  • Configure maxmemory-policy: allkeys-lru
  • Set requirepass for authentication
  • Volume mount for data persistence
  • Health check on port 6379
  • Expose port 6379
  • docker-compose service definition with environment variables
  • Production-ready documentation
  • Backup and recovery tooling
  • Monitoring and health checks
  • Development and production configurations

Testing Checklist

  • Dockerfile builds successfully
  • Container starts and passes health checks
  • Redis CLI accessible
  • Environment variables substituted
  • Health check responds quickly
  • RDB/AOF persistence works
  • Backup tool creates valid backups
  • Monitor tool shows metrics
  • Docker Compose integration complete
  • Email-service can connect with password

Next Steps

  1. Review Documentation: Start with docs/DEPLOYMENT.md
  2. Build Container: docker-compose build redis
  3. Start Development: docker-compose up -d
  4. Verify Health: ./deployment/docker/redis/monitor.sh health
  5. Test Backup: ./deployment/docker/redis/backup.sh backup
  6. Deploy Production: Use docker-compose.prod.yml
  7. Setup Monitoring: Schedule monitor.sh and backup.sh jobs

References

Support

For issues or questions:

  1. Check PHASE_8_REDIS_SUMMARY.md troubleshooting section
  2. Review deployment/docker/redis/README.md for detailed configuration
  3. Run ./deployment/docker/redis/monitor.sh health for diagnostics

Status

Phase 8: COMPLETE ✓ Version: 1.0.0 Release Date: 2026-01-24 Status: Production-Ready

All requirements satisfied. Ready for development and production deployment.


Last Updated: 2026-01-24 Maintainer: Email Client Development Team License: Project License