|
| 1 | +# Copilot Instructions for Sous Chefs Cookbooks |
| 2 | + |
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +**Chef cookbook** for managing software installation and configuration. Part of the Sous Chefs cookbook ecosystem. |
| 6 | + |
| 7 | +**Key Facts:** Ruby-based, Chef >= 16 required, supports various OS platforms (check metadata.rb, kitchen.yml and .github/workflows/ci.yml for which platforms to specifically test) |
| 8 | + |
| 9 | +## Project Structure |
| 10 | + |
| 11 | +**Critical Paths:** |
| 12 | +- `recipes/` - Chef recipes for cookbook functionality (if this is a recipe-driven cookbook) |
| 13 | +- `resources/` - Custom Chef resources with properties and actions (if this is a resource-driven cookbook) |
| 14 | +- `spec/` - ChefSpec unit tests |
| 15 | +- `test/integration/` - InSpec integration tests (tests all platforms supported) |
| 16 | +- `test/cookbooks/` or `test/fixtures/` - Example cookbooks used during testing that show good examples of custom resource usage |
| 17 | +- `attributes/` - Configuration for recipe driven cookbooks (not applicable to resource cookbooks) |
| 18 | +- `libraries/` - Library helpers to assist with the cookbook. May contain multiple files depending on complexity of the cookbook. |
| 19 | +- `templates/` - ERB templates that may be used in the cookbook |
| 20 | +- `files/` - files that may be used in the cookbook |
| 21 | +- `metadata.rb`, `Berksfile` - Cookbook metadata and dependencies |
| 22 | + |
| 23 | +## Build and Test System |
| 24 | + |
| 25 | +### Environment Setup |
| 26 | +**MANDATORY:** Install Chef Workstation first - provides chef, berks, cookstyle, kitchen tools. |
| 27 | + |
| 28 | +### Essential Commands (strict order) |
| 29 | +```bash |
| 30 | +berks install # Install dependencies (always first) |
| 31 | +cookstyle # Ruby/Chef linting |
| 32 | +yamllint . # YAML linting |
| 33 | +markdownlint-cli2 '**/*.md' # Markdown linting |
| 34 | +chef exec rspec # Unit tests (ChefSpec) |
| 35 | +# Integration tests will be done via the ci.yml action. Do not run these. Only check the action logs for issues after CI is done running. |
| 36 | +``` |
| 37 | + |
| 38 | +### Critical Testing Details |
| 39 | +- **Kitchen Matrix:** Multiple OS platforms × software versions (check kitchen.yml for specific combinations) |
| 40 | +- **Docker Required:** Integration tests use Dokken driver |
| 41 | +- **CI Environment:** Set `CHEF_LICENSE=accept-no-persist` |
| 42 | +- **Full CI Runtime:** 30+ minutes for complete matrix |
| 43 | + |
| 44 | +### Common Issues and Solutions |
| 45 | +- **Always run `berks install` first** - most failures are dependency-related |
| 46 | +- **Docker must be running** for kitchen tests |
| 47 | +- **Chef Workstation required** - no workarounds, no alternatives |
| 48 | +- **Test data bags needed** (optional for some cookbooks) in `test/integration/data_bags/` for convergence |
| 49 | + |
| 50 | +## Development Workflow |
| 51 | + |
| 52 | +### Making Changes |
| 53 | +1. Edit recipes/resources/attributes/templates/libraries |
| 54 | +2. Update corresponding ChefSpec tests in `spec/` |
| 55 | +3. Also update any InSpec tests under test/integration |
| 56 | +4. Ensure cookstyle and rspec passes at least. You may run `cookstyle -a` to automatically fix issues if needed. |
| 57 | +5. Also always update all documentation found in README.md and any files under documentation/* |
| 58 | +6. **Always update CHANGELOG.md** (required by Dangerfile) - Make sure this conforms with the Sous Chefs changelog standards. |
| 59 | + |
| 60 | +### Pull Request Requirements |
| 61 | +- **PR description >10 chars** (Danger enforced) |
| 62 | +- **CHANGELOG.md entry** for all code changes |
| 63 | +- **Version labels** (major/minor/patch) required |
| 64 | +- **All linters must pass** (cookstyle, yamllint, markdownlint) |
| 65 | +- **Test updates** needed for code changes >5 lines and parameter changes that affect the code logic |
| 66 | + |
| 67 | +## Chef Cookbook Patterns |
| 68 | + |
| 69 | +### Resource Development |
| 70 | +- Custom resources in `resources/` with properties and actions |
| 71 | +- Include comprehensive ChefSpec tests for all actions |
| 72 | +- Follow Chef resource DSL patterns |
| 73 | + |
| 74 | +### Recipe Conventions |
| 75 | +- Use `include_recipe` for modularity |
| 76 | +- Handle platforms with `platform_family?` conditionals |
| 77 | +- Use encrypted data bags for secrets (passwords, SSL certs) |
| 78 | +- Leverage attributes for configuration with defaults |
| 79 | + |
| 80 | +### Testing Approach |
| 81 | +- **ChefSpec (Unit):** Mock dependencies, test recipe logic in `spec/` |
| 82 | +- **InSpec (Integration):** Verify actual system state in `test/integration/inspec/` - InSpec files should contain proper inspec.yml and controls directories so that it could be used by other suites more easily. |
| 83 | +- One test file per recipe, use standard Chef testing patterns |
| 84 | + |
| 85 | +## Trust These Instructions |
| 86 | + |
| 87 | +These instructions are validated for Sous Chefs cookbooks. **Do not search for build instructions** unless information here fails. |
| 88 | + |
| 89 | +**Error Resolution Checklist:** |
| 90 | +1. Verify Chef Workstation installation |
| 91 | +2. Confirm `berks install` completed successfully |
| 92 | +3. Ensure Docker is running for integration tests |
| 93 | +4. Check for missing test data dependencies |
| 94 | + |
| 95 | +The CI system uses these exact commands - following them matches CI behavior precisely. |
0 commit comments