CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a Crystal Language project called "mangrullo" - a Docker container update automation tool similar to Watchtower. The project is functional and includes container monitoring, update detection, container recreation, and filtering capabilities. It follows standard Crystal conventions with comprehensive tests and a modular architecture.
Development Commands
Building and Running
shards build- Build all targetsshards build mangrullo- Build CLI targetshards build mangrullo-web- Build web interface targetcrystal build src/mangrullo.cr- Compile the CLIcrystal run src/mangrullo.cr- Run the CLIcrystal tool format- Format code according to Crystal style guidelinesameba --fix- Fix linting issues automatically
Testing
crystal spec- Run all testscrystal spec spec/mangrullo_spec.cr- Run main test filecrystal spec --verbose- Run tests with detailed output
Dependencies
shards install- Install dependencies from shard.ymlshards build- Build all targets using shardsshards build mangrullo- Build CLI targetshards build mangrullo-web- Build web interface target
Project Structure
Source Files
src/mangrullo.cr- Main CLI entry pointsrc/cli.cr- CLI interface and main loopsrc/config.cr- Configuration management using Docoptsrc/types.cr- Core data structures and version comparisonsrc/docker_client.cr- Docker API wrapper and container operationssrc/image_checker.cr- Image update detection and registry accesssrc/update_manager.cr- Update coordination with container filteringsrc/update_job_queue.cr- Background update jobs with status retentionsrc/web.cr- Web interface entry point (Kemal.run)src/web_server.cr- Kemal routes, auth middleware, SSE endpointsrc/web_views.cr- Dashboard renderingsrc/templates/dashboard.ecr- Dashboard templatesrc/static_assets.cr- Bakespublic/(CSS, JS, favicons) into the binarysrc/sse.cr- Server-Sent Events registry and broadcastsrc/web_auth.cr- Optional HTTP Basic authenticationsrc/state_manager.cr- Shared state management for web interfacesrc/container_state.cr- Container state data structuressrc/error_handling.cr- Centralized error managementsrc/version.cr- Single-sourced version constant
Configuration
shard.yml- Project dependencies and build targetsshard.lock- Locked dependency versionsspec/mangrullo_spec.cr- Test suitespec/spec_helper.cr- Test configuration
Key Features Implemented
- Container Monitoring: Automatically detects running Docker containers
- Update Detection: Version comparison for versioned tags, digest comparison for moving tags (latest, postgres:16, digest pins)
- Target Image Resolution: Updates pull the newer tag, not the stale one
- Rollback-safe Recreation: Old container preserved as a backup and restored if a replacement fails
- Container Filtering: Check specific containers by name with flexible matching
- Multi-Registry Support: Docker Hub, GHCR, lscr.io (with proper mapping), registry ports
- Registry Credentials: Uses
~/.docker/config.jsonfor private images - Semantic Versioning: Intelligent version comparison with major upgrade control
- Dry Run Mode: Test updates without making changes with comprehensive results modal
- Full Web Interface: Mission Control themed dashboard with dark/light toggle
- Bulk Operations: Async updates through a job queue with dry run support
- Real-time Events: Server-Sent Events stream update progress to the dashboard
- Optional HTTP Basic Auth: Constant-time comparison,
/healthexempt - Custom Branding: Cell tower icons and favicon throughout interface
- Auto-refresh Dashboard: Real-time container status updates every 30 seconds
- Embedded Static Assets: All web assets baked into binary for easy deployment
- Multi-architecture Builds: Static binaries for Linux AMD64 and ARM64
- Comprehensive Testing: Unit tests for all major functionality (184 examples passing)
- CI/CD Integration: GitHub Actions with Ameba linting and automated testing
Code Style
Follow Crystal Language conventions:
- Use 2-space indentation
- Module names are CamelCase
- Constants are UPPER_SNAKE_CASE
- Method names are snake_case
- Use
crystal tool formatfor formatting - Avoid
not_nil!- use proper nilable handling - Prefer
unlessoverif !for negative conditions
Current State
The project is fully functional with:
- Complete CLI implementation with all planned features
- Container recreation with rollback safety (updates containers, never destroys them)
- Flexible container name matching (handles both "name" and "/name")
- Comprehensive test suite (184 examples, 0 failures)
- Web interface with theme toggle, SSE live events and optional Basic auth
- Multi-registry support with authentication
- Proper error handling and logging
Project Dependencies
From shard.yml:
docr- Docker API clientdocopt+docopt-config- Command-line parsingkemal- Web frameworkbaked_file_system- Embedded file system for static assetsbaked_file_handler- Handler for baked files in Kemalprogress- Progress bars for CLI operations
Crystal Version
This project requires Crystal >= 1.16.3 (CI runs on crystal: latest; developed with Crystal 1.21).