Development Setup¶
Set up a local development environment for contributing to kube-chainsaw.
Prerequisites¶
- Go 1.21 or later
- Git
- (Optional) Docker for testing the container image
- (Optional) golangci-lint for linting
Clone and Install¶
Clone the repository:
Install dependencies:
Build the binary:
Install to GOPATH/bin:
Run Tests¶
Run the full test suite:
Run with coverage:
Run specific tests:
Code Quality¶
Format code:
Vet code:
Lint with golangci-lint (if installed):
Install golangci-lint:
Project Structure¶
kube-chainsaw/
├── cmd/
│ └── kube-chainsaw/
│ └── main.go # CLI entry point
├── pkg/
│ ├── analyzer/
│ │ ├── analyzer.go # Main analysis logic
│ │ └── rules.go # Detection rule definitions
│ ├── loader/
│ │ └── loader.go # YAML manifest loading
│ ├── models/
│ │ └── models.go # Data structures
│ ├── reporter/
│ │ ├── console.go # Console output
│ │ ├── json.go # JSON output
│ │ └── sarif.go # SARIF output
│ └── suppression/
│ └── suppression.go # Suppression loading and matching
├── internal/
│ └── version/
│ └── version.go # Version metadata
├── tests/
│ └── fixtures/ # Test YAML manifests
├── site/ # MkDocs Material site
├── .goreleaser.yaml # Release configuration
├── .github/
│ └── action.yml # GitHub Action
├── go.mod
└── README.md
Running Locally¶
Test the CLI during development:
Or use the built binary:
Building Documentation¶
Build MkDocs site:
Open http://127.0.0.1:8000/ to preview.
Build static HTML:
Docker Development¶
Build the Docker image:
Run the container:
Release Process¶
Releases are automated via goreleaser on Git tags:
- Tag a release:
- GitHub Actions builds binaries, Docker images, and creates a GitHub Release
- Artifacts include:
- Linux/macOS/Windows binaries (amd64, arm64)
- Docker image pushed to ghcr.io
- Checksums file
Debugging¶
Use Delve for debugging:
Enable verbose logging:
Next Steps¶
- Adding Rules: Create new detection rules
- Architecture: Understand the codebase structure
- Go API: Library usage examples