$ show crazy-max/diun
Diun is a Go-based CLI daemon that monitors container image registries and notifies users when new versions or updates are available. It operates by polling container runtime environments (Docker, Swarm, Kubernetes, Nomad, containerd), or reading from YAML or Dockerfiles, to discover images, then compares their registry digests (or manifest list platform-specific digests) against a local bbolt database. When a change is detected, it sends notifications through one or more of 20+ channels (Slack, Discord, Telegram, email, webhook, MQTT, etc.). The system also exposes Prometheus metrics, a gRPC interface for image lifecycle management, and supports health checks via healthchecks.io. The architecture is modular: a scheduler component (cron-based with jitter and worker pool) triggers jobs that walk through configured providers (each implementing a `Handler` interface returning a list of `model.Image`), then for each image the registry client fetches the latest manifest (with tag sorting and filtering), compares it against the stored digest, updates the database, and dispatches notification entries through a notifier chain. The design cleanly separates provider discovery, registry inspection, state persistence, and notification delivery into independent packages. External dependencies include container runtime SDKs (Docker, containerd, Kubernetes, Nomad), the OCI distribution registry API, and each notification service's client library. The codebase is well-structured with strong test coverage, configuration via YAML and environment variables, and comprehensive CI/CD including e2e tests, static analysis, and vulnerability scanning. It is actively maintained with frequent releases and responsive issue triage. Primary entry points are `cmd/serve.go` (main daemon), `cmd/healthcheck.go`, `cmd/image.go` (gRPC-based image management), and `cmd/notif.go` (test notifications).
The LLM identified 5 files worth highlighting for reuse:
Provides a reusable message rendering system supporting Markdown, HTML, JSON, and environment-based template output. Includes custom template functions (upper, lower, replace, regexReplaceAll, etc.) and input validation. Isolated from internal state, can be extracted to format notifications or any similar structured message in future Go projects.
Implements a clean abstraction for loading secrets from either environment variable values or file paths (with automatic trailing newline trimming). `GetSecret()` is a pure function with zero internal imports beyond standard library, making it trivially reusable in any Go application that needs to read sensitive values without hardcoding.
A factory function `NewClient` that constructs an `*http.Client` with configurable TLS settings (skip verify, custom CA certificate), optional HTTP proxy, and timeout. Encapsulates common enterprise network configuration into a single call. Standalone module that can be dropped into any Go project needing a robust HTTP client with complex TLS/proxy requirements.
Implements a custom `prometheus.Collector` that tracks per-image status (new, update, error, skip) and exposes watch lifecycle metrics (last run timestamp, duration, update availability). Demonstrates non-obvious Prometheus collector pattern (Describe/Collect methods) with label-based dimensionality. Self-contained with only prometheus client dependency, extractable to instrument any batch job system.
A simple but robust string matcher that compiles a list of include/regex patterns and tests them against input strings. Used for tag filtering across providers. Minimal imports (stdlib only), zero internal coupling, and could be directly reused as a lightweight configuration-driven pattern matching library in any Go project.