|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +**WRPT** is a Rust CLI tool for deploying and managing Docker Compose stacks on Portainer. It supports both manual usage and CI/CD pipeline integration. Published on [crates.io](https://crates.io/crates/wrpt) and [Docker Hub](https://hub.docker.com/r/wahl/wrpt). |
| 6 | + |
| 7 | +- **Language:** Rust (Edition 2021) |
| 8 | +- **Version:** 0.6.3 |
| 9 | +- **License:** MIT |
| 10 | + |
| 11 | +## Quick Reference Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +# Build |
| 15 | +cargo build |
| 16 | +cargo build --release |
| 17 | + |
| 18 | +# Test |
| 19 | +cargo test --verbose |
| 20 | + |
| 21 | +# Lint |
| 22 | +cargo clippy --verbose |
| 23 | + |
| 24 | +# Format |
| 25 | +cargo fmt --all --verbose |
| 26 | + |
| 27 | +# Full CI check (matches GitHub Actions) |
| 28 | +cargo build --verbose && cargo test --verbose && cargo clippy --verbose && cargo fmt --all --verbose |
| 29 | +``` |
| 30 | + |
| 31 | +## Project Structure |
| 32 | + |
| 33 | +``` |
| 34 | +src/ |
| 35 | +├── main.rs # Entry point (minimal) |
| 36 | +└── commands/ |
| 37 | + ├── mod.rs # Command dispatch/routing |
| 38 | + ├── wrpt.rs # CLI args struct, logger init, global args |
| 39 | + ├── consts.rs # API endpoint path constants |
| 40 | + ├── helpers.rs # Shared utilities (HTTP client, table formatting, env parsing) |
| 41 | + ├── stacks/ # Stack management (deploy, remove, list, start, stop, resource-control) |
| 42 | + │ ├── args/ # clap argument definitions |
| 43 | + │ ├── handlers/ # Business logic |
| 44 | + │ └── models/ # Data structures |
| 45 | + ├── endpoints/ # Endpoint listing |
| 46 | + │ ├── args/ handlers/ models/ |
| 47 | + ├── teams/ # Team listing |
| 48 | + │ ├── args/ handlers/ models/ |
| 49 | + └── users/ # User listing |
| 50 | + ├── args/ handlers/ models/ |
| 51 | +``` |
| 52 | + |
| 53 | +## Architecture |
| 54 | + |
| 55 | +Each command domain follows **args → handlers → models**: |
| 56 | +- **args/**: CLI argument definitions using `clap::Args` and `clap::Subcommand` |
| 57 | +- **handlers/**: Business logic and API calls |
| 58 | +- **models/**: Data structures for API requests/responses (with Serde) |
| 59 | + |
| 60 | +Shared utilities live in `helpers.rs` (HTTP client factory, URL construction, table formatting, env file parsing, API response handling). |
| 61 | + |
| 62 | +## Code Conventions |
| 63 | + |
| 64 | +- **Naming:** snake_case for modules/functions, PascalCase for structs/enums, UPPER_SNAKE_CASE for constants |
| 65 | +- **Error handling:** `Result<T, ()>` with `log_err` for expect-based logging |
| 66 | +- **HTTP:** Centralized `create_client()` in helpers; custom headers for Portainer auth (`x-api-key`) |
| 67 | +- **Constants:** Compile-time string formatting via `const_format` crate for API paths |
| 68 | +- **Output:** `prettytable-rs` for ASCII table display; `simplelog` with Paris for colored logging |
| 69 | +- **Global args:** URL (`-l`/`PORTAINER_URL`), access token (`-A`/`PORTAINER_ACCESS_TOKEN`), `--insecure`, verbosity (`-v`), quiet (`-q`), color control |
| 70 | + |
| 71 | +## Key Dependencies |
| 72 | + |
| 73 | +| Crate | Purpose | |
| 74 | +|-------|---------| |
| 75 | +| `clap` (4.x) | CLI argument parsing with derive macros | |
| 76 | +| `reqwest` | HTTP client for Portainer API | |
| 77 | +| `serde` / `serde_json` | JSON serialization | |
| 78 | +| `prettytable-rs` | ASCII table output | |
| 79 | +| `simplelog` / `log` | Logging | |
| 80 | +| `chrono` | Date/time handling | |
| 81 | +| `const_format` | Compile-time string formatting | |
| 82 | + |
| 83 | +## CI/CD |
| 84 | + |
| 85 | +Three GitHub Actions workflows in `.github/workflows/`: |
| 86 | +- **tests.yml**: Build, test, clippy, fmt on push/PR |
| 87 | +- **release.yml**: Manual dispatch → Cocogitto SemVer bump → changelog → GitHub release → crates.io publish |
| 88 | +- **docker.yml**: Multi-platform Docker build (amd64/arm64) → Docker Hub |
| 89 | + |
| 90 | +## Release Process |
| 91 | + |
| 92 | +Uses [Cocogitto](https://docs.cocogitto.io/) (`cog.toml`) with conventional commits. Pre-bump hooks run test, clippy, and fmt. Post-bump hooks push and publish to crates.io. |
| 93 | + |
| 94 | +## Docker |
| 95 | + |
| 96 | +Multi-stage Dockerfile in `docker/Dockerfile`: Rust build → Debian 12 slim runtime with OpenSSL and Docker Compose. |
| 97 | + |
| 98 | +## Important Notes |
| 99 | + |
| 100 | +- Conventional commits are required (feat:, fix:, docs:, refactor:, etc.) |
| 101 | +- Branch whitelist for releases: `main` only |
| 102 | +- No `.rustfmt.toml` or `clippy.toml` overrides — uses default Rust toolchain settings |
| 103 | +- `.env` files are gitignored; the tool supports parsing them at runtime |
0 commit comments