|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This is the **microdevops-formula** repository - a comprehensive SaltStack formula collection for managing infrastructure and applications. It's designed to handle everything from basic system configuration to complex application deployments across hundreds of servers. |
| 8 | + |
| 9 | +## Key Architecture Components |
| 10 | + |
| 11 | +### Formula Structure |
| 12 | +- **State files (.sls)**: Main configuration and deployment logic |
| 13 | +- **Pillar examples**: Configuration templates for each service/component |
| 14 | +- **Jinja templates**: Dynamic configuration generation |
| 15 | +- **Files directory**: Static configuration files, scripts, and assets |
| 16 | + |
| 17 | +### Core Service Categories |
| 18 | +- **Infrastructure**: nginx, php-fpm, docker-ce, ufw_simple (firewall), bootstrap (system setup) |
| 19 | +- **Applications**: app (web app deployment), wordpress, gitlab, nextcloud, sentry |
| 20 | +- **Monitoring**: netdata, prometheus, grafana, alertmanager, cmd_check_alert |
| 21 | +- **Databases**: percona (MySQL), postgresql, mongodb, redis |
| 22 | +- **Security**: authentik, keycloak, vault, wazuh |
| 23 | +- **Backup**: rsnapshot_backup with sysadmws-utils integration |
| 24 | +- **Networking**: keepalived, haproxy, consul |
| 25 | + |
| 26 | +### Application Deployment System |
| 27 | +The `app/` formula provides a sophisticated deployment system supporting: |
| 28 | +- **PHP-FPM applications** with nginx integration |
| 29 | +- **Python applications** with various WSGI servers |
| 30 | +- **Static sites** with nginx optimization |
| 31 | +- **WordPress** deployments with specialized configurations |
| 32 | +- **Docker-based applications** |
| 33 | + |
| 34 | +Key files: |
| 35 | +- `app/init.sls`: Main deployment orchestration |
| 36 | +- `app/deploy.sls`: Core deployment logic |
| 37 | +- `app/_nginx.sls`: Nginx vhost configuration |
| 38 | +- `app/_user_and_source.sls`: User setup and source code management |
| 39 | + |
| 40 | +## Common Salt Commands |
| 41 | + |
| 42 | +### Basic Operations |
| 43 | +```bash |
| 44 | +# Apply a specific state |
| 45 | +salt 'minion-id' state.apply nginx |
| 46 | + |
| 47 | +# Apply with specific pillar data |
| 48 | +salt 'minion-id' state.apply app.php-fpm pillar='{"nginx_reload": true}' |
| 49 | + |
| 50 | +# Test configuration |
| 51 | +salt 'minion-id' state.apply test.git_commit |
| 52 | +``` |
| 53 | + |
| 54 | +### Application Deployment |
| 55 | +```bash |
| 56 | +# Deploy PHP-FPM application |
| 57 | +salt 'minion-id' state.apply app.php-fpm |
| 58 | + |
| 59 | +# Deploy static application |
| 60 | +salt 'minion-id' state.apply app.static |
| 61 | + |
| 62 | +# Deploy Python application |
| 63 | +salt 'minion-id' state.apply app.python |
| 64 | +``` |
| 65 | + |
| 66 | +### System Management |
| 67 | +```bash |
| 68 | +# Bootstrap system (initial setup) |
| 69 | +salt 'minion-id' state.apply bootstrap |
| 70 | + |
| 71 | +# Update firewall rules |
| 72 | +salt 'minion-id' state.apply ufw_simple |
| 73 | + |
| 74 | +# Configure monitoring |
| 75 | +salt 'minion-id' state.apply netdata |
| 76 | +salt 'minion-id' state.apply cmd_check_alert |
| 77 | +``` |
| 78 | + |
| 79 | +### Backup Operations |
| 80 | +```bash |
| 81 | +# Update backup configuration |
| 82 | +salt 'minion-id' state.apply rsnapshot_backup.update_config |
| 83 | + |
| 84 | +# Check backup coverage |
| 85 | +salt 'minion-id' state.apply rsnapshot_backup.check_coverage |
| 86 | + |
| 87 | +# Run backup sync |
| 88 | +salt 'minion-id' cmd.run '/opt/sysadmws/rsnapshot_backup/rsnapshot_backup_sync_monthly_weekly_daily_check_backup.sh' |
| 89 | +``` |
| 90 | + |
| 91 | +## Configuration Management |
| 92 | + |
| 93 | +### Pillar Structure |
| 94 | +- Each service has a `pillar.example` file showing configuration options |
| 95 | +- Main pillar reference at `/pillar.example` points to individual service examples |
| 96 | +- Ready-to-use pillar templates in `pillar/` directory with common configurations |
| 97 | + |
| 98 | +### SSL/TLS with ACME |
| 99 | +The formula integrates with acme.sh for automated SSL certificate management: |
| 100 | +- Webroot validation for Let's Encrypt certificates |
| 101 | +- Automatic nginx configuration for HTTPS redirects |
| 102 | +- Integration with various DNS providers (CloudFlare, GoDaddy, etc.) |
| 103 | + |
| 104 | +### UFW Simple Firewall |
| 105 | +Advanced firewall management system (`ufw_simple/`) that: |
| 106 | +- Extends UFW with NAT and raw iptables rules |
| 107 | +- Manages firewall rules across hundreds of servers |
| 108 | +- Includes predefined rule sets for common scenarios |
| 109 | +- Supports Docker integration and complex networking |
| 110 | + |
| 111 | +### Monitoring Integration |
| 112 | +Comprehensive monitoring setup: |
| 113 | +- **Netdata**: Real-time system monitoring |
| 114 | +- **Prometheus**: Metrics collection and alerting |
| 115 | +- **Grafana**: Visualization and dashboards |
| 116 | +- **cmd_check_alert**: Custom health checks with alert integration |
| 117 | + |
| 118 | +## Development Workflow |
| 119 | + |
| 120 | +### Making Changes |
| 121 | +1. Modify the appropriate `.sls` state file |
| 122 | +2. Update corresponding `pillar.example` if configuration changes |
| 123 | +3. Test changes on development minions first |
| 124 | +4. Use `state.apply` to deploy changes |
| 125 | + |
| 126 | +### Testing |
| 127 | +- Use `salt-call --local state.apply` for local testing |
| 128 | +- The `test/` directory contains validation states |
| 129 | +- Bootstrap testing available via `bootstrap/test.sls` |
| 130 | + |
| 131 | +### Scripts and Automation |
| 132 | +- `scripts/ci_sudo/`: Scripts for running Salt states via CI/CD |
| 133 | +- `scripts/salt-ssh/`: Salt-SSH specific scripts |
| 134 | +- Integration with GitLab CI for automated deployments |
| 135 | + |
| 136 | +## File Organization |
| 137 | + |
| 138 | +- **Top-level directories**: Each represents a service or component |
| 139 | +- **init.sls**: Main state file for each service |
| 140 | +- **pillar.example**: Configuration template |
| 141 | +- **files/**: Static files, templates, and scripts |
| 142 | +- **defaults.yaml**: Default variables for complex services |
| 143 | +- **map.jinja**: OS-specific variable mapping where needed |
| 144 | + |
| 145 | +## Important Notes |
| 146 | + |
| 147 | +- This formula is designed for production environments managing hundreds of servers |
| 148 | +- Many services are configured to work together (nginx + php-fpm + app deployment) |
| 149 | +- The backup system (`rsnapshot_backup`) is tightly integrated with `sysadmws-utils` |
| 150 | +- Firewall rules (`ufw_simple`) are designed for complex multi-server environments |
| 151 | +- SSL certificates are automated via acme.sh integration |
0 commit comments