|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a GitOps tool for managing multiple applications across Kubernetes clusters. It consists of two main components: |
| 8 | + |
| 9 | +1. **GitOps CLI** (`gitops/`) - Command-line tool for managing app deployments, built using the `invoke` framework |
| 10 | +2. **GitOps Server** (`gitops_server/`) - FastAPI-based webhook server that handles deployment automation |
| 11 | + |
| 12 | +## Development Commands |
| 13 | + |
| 14 | +### Setup |
| 15 | +```bash |
| 16 | +# Install dependencies using uv |
| 17 | +uv sync |
| 18 | + |
| 19 | +# Install the CLI tool for development |
| 20 | +uv tool install -e . |
| 21 | +``` |
| 22 | + |
| 23 | +### Testing |
| 24 | +```bash |
| 25 | +# Run all tests |
| 26 | +uv run pytest |
| 27 | + |
| 28 | +# Run specific test file |
| 29 | +uv run pytest tests/test_core.py |
| 30 | + |
| 31 | +# Run with coverage |
| 32 | +uv run pytest --cov=gitops --cov=gitops_server |
| 33 | +``` |
| 34 | + |
| 35 | +### Linting and Formatting |
| 36 | +```bash |
| 37 | +# Format code with ruff |
| 38 | +uv run ruff format . |
| 39 | + |
| 40 | +# Lint code |
| 41 | +uv run ruff check . |
| 42 | + |
| 43 | +# Fix auto-fixable linting issues |
| 44 | +uv run ruff check --fix . |
| 45 | + |
| 46 | +# Type checking with mypy |
| 47 | +uv run mypy gitops/ gitops_server/ |
| 48 | +``` |
| 49 | + |
| 50 | +### Running the CLI |
| 51 | +```bash |
| 52 | +# Run gitops commands during development |
| 53 | +uv run python -m gitops.main --help |
| 54 | + |
| 55 | +# Or if installed globally |
| 56 | +gitops --help |
| 57 | +``` |
| 58 | + |
| 59 | +### Running the Server |
| 60 | +```bash |
| 61 | +# Run the gitops server locally |
| 62 | +uv run uvicorn gitops_server.main:app --reload |
| 63 | +``` |
| 64 | + |
| 65 | +## Architecture |
| 66 | + |
| 67 | +### CLI Component (`gitops/`) |
| 68 | +- **main.py**: Entry point using invoke's Program framework |
| 69 | +- **core.py**: Main CLI commands (bump, summary, etc.) |
| 70 | +- **shorthands.py**: Shorthand command aliases |
| 71 | +- **settings.py**: Configuration management |
| 72 | +- **utils/**: Helper modules for apps, images, kubernetes operations, CLI formatting, etc. |
| 73 | + |
| 74 | +### Server Component (`gitops_server/`) |
| 75 | +- **main.py**: FastAPI application entry point with webhook endpoint |
| 76 | +- **app.py**: FastAPI app configuration |
| 77 | +- **workers/**: Background workers for deployment operations |
| 78 | +- **workers/deploy.py**: Main deployment loop code |
| 79 | +- **workers/worker.py**: Entry point for recieving webhook |
| 80 | +- **utils/**: Git, GitHub, and Slack integration utilities |
| 81 | + |
| 82 | +### Key Patterns |
| 83 | +- Uses `invoke` framework for CLI task definitions |
| 84 | +- Async operations with progress bars for CLI commands |
| 85 | +- FastAPI with webhook validation for server component |
| 86 | +- Kubernetes operations through the `kubernetes_asyncio` library |
| 87 | +- Git operations for managing cluster repository state |
| 88 | + |
| 89 | +## Configuration |
| 90 | + |
| 91 | +- **Environment Variables**: Set `GITOPS_APPS_DIRECTORY` to specify the apps directory location |
| 92 | +- **Secrets**: Server configuration goes in `secrets.env` (see `secrets.example.env`) |
| 93 | +- **Ruff Config**: Located in `ruff.toml` with specific rules for this codebase |
| 94 | +- **Dependencies**: Managed through `pyproject.toml` with separate server optional dependencies |
| 95 | + |
| 96 | +## Testing Structure |
| 97 | + |
| 98 | +- Tests are in the `tests/` directory |
| 99 | +- Uses pytest with async support (`pytest-asyncio`) |
| 100 | +- Sample data and webhook fixtures in `sample_data.py` and `webhook_sample_data.py` |
| 101 | +- Conftest provides shared test configuration |
0 commit comments