Ofelia is a modern, Go-powered job scheduler for Docker containers that provides a lightweight alternative to traditional cron with container orchestration capabilities.
- Container Job Scheduling: Schedule tasks within running containers or spawn new ones
- Multiple Job Types: Support for RunJob, ExecJob, LocalJob, ServiceJob, and ComposeJob
- Dynamic Docker Integration: Auto-discover containers via labels or events
- Resilient Execution: Built-in retry logic, circuit breakers, and rate limiting
- Comprehensive Monitoring: Prometheus metrics, structured logging, and health checks
- Web UI & API: Interactive dashboard for job management and monitoring
- Security-First Design: Input validation, JWT authentication, and sanitization
ofelia/
βββ π¦ core/ # Core business logic and job execution
βββ π₯οΈ cli/ # Command-line interface and configuration
βββ π web/ # Web UI and API endpoints
βββ π metrics/ # Prometheus metrics collection
βββ π logging/ # Structured logging system
βββ β
config/ # Configuration validation and sanitization
βββ π middlewares/ # Job execution middlewares (mail, slack, etc.)
βββ π§ͺ test/ # Test utilities and helpers
βββ π docs/ # Documentation
βββ π¨ static/ # Web UI static assets
βββ πΌ example/ # Example configurations
- RunJob: Execute commands in new containers
- ExecJob: Execute commands in existing containers
- LocalJob: Execute commands on the host
- ServiceJob: Run as Docker Swarm services
- ComposeJob: Execute docker-compose operations
- Scheduler: Cron-based job scheduling engine
- Context: Execution context and middleware chain
- Docker Client: Docker API operations wrapper
- Container Monitor: Container lifecycle tracking
- Resilience: Retry policies, circuit breakers, rate limiting
- Config Manager: INI/Docker labels configuration loading
- Validator: Configuration validation rules
- Sanitizer: Input sanitization and security
- Docker Labels: Docker label-based configuration
- Server: HTTP server and routing
- JWT Auth: JWT-based authentication
- Health Checks: Liveness and readiness probes
- Middleware: HTTP request processing
- Prometheus Metrics: Job and system metrics
- Structured Logging: stdlib
log/slog(used directly, no wrapper)
- Mail: Email notifications
- Slack: Slack integration
- Save: Output persistence
- Overlap: Overlap prevention
- Sanitize: Output sanitization
graph TD
A[Scheduler] --> B[Job Trigger]
B --> C[Context Creation]
C --> D[Middleware Chain]
D --> E[Job Execution]
E --> F{Job Type}
F -->|RunJob| G[New Container]
F -->|ExecJob| H[Existing Container]
F -->|LocalJob| I[Host Command]
F -->|ServiceJob| J[Swarm Service]
E --> K[Metrics Recording]
E --> L[Logging]
E --> M{Retry Needed?}
M -->|Yes| N[Retry Logic]
M -->|No| O[Complete]
- Command injection prevention
- Path traversal protection
- SQL/LDAP injection guards
- Docker image name validation
- Cron expression validation
- JWT-based API authentication
- Secure token management
- Session handling
- CORS protection
- Circuit Breakers: Prevent cascade failures
- Rate Limiting: Token bucket algorithm
- Retry Policies: Exponential backoff with jitter
- Bulkhead Pattern: Resource isolation
ofelia_jobs_total # Total jobs executed
ofelia_jobs_failed_total # Failed job count
ofelia_jobs_running # Currently running jobs
ofelia_job_duration_seconds # Job execution duration histogram
ofelia_docker_operations_total # Docker API operations
ofelia_docker_errors_total # Docker API errors
ofelia_http_requests_total # HTTP request count
ofelia_circuit_breaker_* # Circuit breaker states
/health/liveness: Service availability/health/readiness: Service readiness/metrics: Prometheus metrics endpoint
GET /api/jobs: List all jobsGET /api/job/{name}: Get job detailsPOST /api/job/{name}/run: Trigger job executionPUT /api/job/{name}: Update job configurationDELETE /api/job/{name}: Remove job
POST /api/login: Authenticate and receive JWTPOST /api/refresh: Refresh JWT tokenPOST /api/logout: Invalidate token
[job-local "backup"]
schedule = @daily
command = /usr/local/bin/backup.sh
[job-exec "db-maintenance"]
schedule = 0 2 * * *
container = postgres
command = vacuumdb --all --analyze
[job-run "report-generator"]
schedule = 0 */6 * * *
image = myapp/reporter:latest
command = generate-report --type=dailylabels:
ofelia.enabled: "true"
ofelia.job-exec.db-backup.schedule: "@midnight"
ofelia.job-exec.db-backup.command: "pg_dump -U postgres mydb"- Unit tests for all core components
- Integration tests for Docker operations
- End-to-end tests for job execution
- Benchmark tests for performance-critical paths
go test ./... # Run all tests
go test -race ./... # Run with race detector
go test -cover ./... # Show coverage
go test -bench=. ./core # Run benchmarkscore: Job execution and schedulingcli: Configuration and CLI commandsweb: HTTP server and APImetrics: Monitoring and observabilitylogging: Structured loggingconfig: Validation and sanitizationmiddlewares: Job execution plugins
- Architecture Diagrams: 8 comprehensive mermaid diagrams
- Job execution lifecycle (sequence)
- Configuration precedence (5-layer)
- Docker integration architecture
- Middleware chain execution
- Resilience patterns (circuit breaker, retry, rate limiting)
- Scheduler state machine
- Web UI & API flow
- Component interaction map
-
Integration Patterns: Real-world integration scenarios
- Database management (backups, maintenance)
- Log management and archiving
- Backup & recovery strategies
- Health monitoring patterns
- Data synchronization
- Cleanup & maintenance
- CI/CD integration
- Multi-environment patterns
- Performance optimization
- Security patterns
-
Quick Reference: Fast-lookup cheat sheet
- CLI commands
- Cron schedule formats
- All job types with examples
- Docker labels format
- API endpoints
- Troubleshooting quick fixes
- Common patterns
- Security checklist
cli/config.go β config/validator.go β config/sanitizer.go β core/scheduler.go
core/scheduler.go β core/context.go β middlewares/* β core/*job.go
core/docker_client.go β core/container_monitor.go β core/runjob.go
core/resilient_job.go β metrics/prometheus.go β web/server.go
- Getting Started
- Configuration Guide
- API Documentation
- Development Guide
- Git Hooks System
- Security Considerations
- Troubleshooting
Last Updated: 2025-11-21 | Enhanced with architecture diagrams, integration patterns, and quick reference