|
1 | | -# PostgreSQL Chef Cookbook Development Guide |
| 1 | +# Copilot Instructions for Sous Chefs Cookbooks |
2 | 2 |
|
3 | | -The PostgreSQL cookbook is a Chef cookbook that provides resources for installing and configuring PostgreSQL database servers and clients across multiple Linux distributions and PostgreSQL versions (15, 16, 17). |
| 3 | +## Repository Overview |
4 | 4 |
|
5 | | -**Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.** |
| 5 | +**Chef cookbook** for managing software installation and configuration. Part of the Sous Chefs cookbook ecosystem. |
6 | 6 |
|
7 | | -## Working Effectively |
| 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 |
8 | 24 |
|
9 | 25 | ### Environment Setup |
10 | | -- **CRITICAL**: Ruby development environment setup (required for all tasks): |
11 | | - ```bash |
12 | | - # Install Ruby development tools (required for linting and testing) |
13 | | - gem install --user-install bundler cookstyle deepsort inifile |
14 | | - |
15 | | - # ALWAYS set PATH for user-installed gems before running any cookbook commands |
16 | | - export PATH="$HOME/.local/share/gem/ruby/3.2.0/bin:$PATH" |
17 | | - ``` |
18 | | - |
19 | | -### Linting and Code Quality |
20 | | -- **VALIDATED**: Run Cookstyle linter (takes ~2-3 seconds): |
21 | | - ```bash |
22 | | - export PATH="$HOME/.local/share/gem/ruby/3.2.0/bin:$PATH" |
23 | | - cookstyle . |
24 | | - ``` |
25 | | -- **VALIDATED**: Check Ruby syntax (instant): |
26 | | - ```bash |
27 | | - ruby -c libraries/helpers.rb |
28 | | - ruby -c resources/install.rb |
29 | | - # Check any .rb file for syntax errors |
30 | | - ``` |
31 | | -- **ALWAYS run `cookstyle .` before committing changes** - the CI will fail if there are style violations |
32 | | - |
33 | | -### Testing Limitations in Sandbox Environment |
34 | | -- **RSpec/ChefSpec unit tests**: Cannot run due to gem version conflicts between RSpec versions |
35 | | -- **Test Kitchen integration tests**: Cannot run due to blocked network access to supermarket.chef.io |
36 | | -- **Docker/Vagrant testing**: Not available in sandbox environment |
37 | | -- **Working alternative**: Use syntax checking and Cookstyle linting for validation |
38 | | - |
39 | | -### What Works for Development |
40 | | -- All Ruby file syntax validation |
41 | | -- Cookstyle linting and style checking |
42 | | -- Code exploration and modification |
43 | | -- Documentation updates |
44 | | -- Resource parameter validation through code review |
45 | | - |
46 | | -## Repository Structure |
47 | | - |
48 | | -### Key Locations |
49 | | -- **Resources**: `/resources/` - Main cookbook functionality (install.rb, config.rb, service.rb, etc.) |
50 | | -- **Libraries**: `/libraries/` - Helper modules and utility functions |
51 | | -- **Test Examples**: `/test/cookbooks/test/recipes/` - Example usage patterns for each resource |
52 | | -- **Documentation**: `/documentation/` - Detailed resource documentation |
53 | | -- **Integration Tests**: `/test/integration/` - InSpec test suites (reference only in sandbox) |
54 | | - |
55 | | -### Important Files |
56 | | -- `metadata.rb` - Cookbook metadata, dependencies, and supported platforms |
57 | | -- `kitchen.yml` - Test Kitchen configuration (defines test suites and platforms) |
58 | | -- `.rubocop.yml` - Cookstyle/RuboCop linting configuration |
59 | | -- `Berksfile` - Cookbook dependency management (network dependent) |
60 | | - |
61 | | -## Common Development Tasks |
62 | | - |
63 | | -### Adding New Functionality |
64 | | -1. Modify resources in `/resources/` directory |
65 | | -2. Update helper libraries in `/libraries/` if needed |
66 | | -3. Add example usage in `/test/cookbooks/test/recipes/` |
67 | | -4. Update documentation in `/documentation/` |
68 | | -5. **ALWAYS run**: `cookstyle .` before committing |
69 | | -6. **ALWAYS run**: `ruby -c filename.rb` for syntax validation |
| 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 |
70 | 68 |
|
71 | 69 | ### Resource Development |
72 | | -- Main resources: `postgresql_install`, `postgresql_config`, `postgresql_service`, `postgresql_database`, `postgresql_role`, `postgresql_access`, `postgresql_ident`, `postgresql_extension` |
73 | | -- Each resource has corresponding documentation in `/documentation/postgresql_[resource].md` |
74 | | -- Example usage patterns available in `/test/cookbooks/test/recipes/` |
75 | | - |
76 | | -### Dependencies and Platforms |
77 | | -- **Dependencies**: Requires `yum` cookbook (>= 7.2.0) for DNF module resource |
78 | | -- **Supported platforms**: Amazon Linux, Debian 9+, Ubuntu 18.04+, Red Hat/CentOS/Scientific 7+ |
79 | | -- **PostgreSQL versions**: 15, 16, 17 (following official PostgreSQL support policy) |
80 | | -- **Chef version**: Requires Chef 16+ |
81 | | - |
82 | | -## Validation Workflows |
83 | | - |
84 | | -### Before Committing |
85 | | -1. **NEVER skip**: `export PATH="$HOME/.local/share/gem/ruby/3.2.0/bin:$PATH"` |
86 | | -2. **ALWAYS run**: `cookstyle .` (takes 2-3 seconds, NEVER CANCEL) |
87 | | -3. **ALWAYS run**: `ruby -c` on any modified .rb files |
88 | | -4. Review changes against existing patterns in `/test/cookbooks/test/recipes/` |
89 | | - |
90 | | -### CI/CD Expectations |
91 | | -- GitHub Actions CI runs on 12+ OS platforms with 3 PostgreSQL versions |
92 | | -- Integration tests use Test Kitchen with Docker (kitchen.dokken.yml) |
93 | | -- Lint-unit workflow must pass before integration tests run |
94 | | -- **Timeout expectations**: CI integration tests can take 15-30+ minutes per platform/version combination |
95 | | - |
96 | | -## Working with Limited Network Access |
97 | | -- **Cannot access**: supermarket.chef.io for cookbook dependencies |
98 | | -- **Cannot run**: `berks install` or full Test Kitchen suites |
99 | | -- **Can validate**: Code syntax, style, and logical structure |
100 | | -- **Best practice**: Use existing test recipes as patterns for new functionality |
101 | | - |
102 | | -## Key Configuration Files Referenced |
103 | | -``` |
104 | | -ls -la [repo-root] |
105 | | -. |
106 | | -.. |
107 | | -.github/ # GitHub workflows and this instruction file |
108 | | -.rubocop.yml # Cookstyle configuration |
109 | | -.overcommit.yml # Git hooks configuration |
110 | | -Berksfile # Cookbook dependencies (network dependent) |
111 | | -CHANGELOG.md # Version history |
112 | | -CODE_OF_CONDUCT.md # Community guidelines |
113 | | -CONTRIBUTING.md # Contribution guidelines |
114 | | -LICENSE # Apache 2.0 license |
115 | | -README.md # Main cookbook documentation |
116 | | -TESTING.md # Testing guidelines |
117 | | -UPGRADING.md # Version upgrade instructions |
118 | | -documentation/ # Resource documentation |
119 | | -kitchen.yml # Test Kitchen configuration |
120 | | -libraries/ # Helper libraries and utilities |
121 | | -metadata.rb # Cookbook metadata and dependencies |
122 | | -resources/ # Main cookbook resources |
123 | | -spec/ # Unit test specifications (RSpec/ChefSpec) |
124 | | -test/ # Integration tests and test cookbooks |
125 | | -``` |
| 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 |
126 | 94 |
|
127 | | -## Performance Notes |
128 | | -- **Cookstyle linting**: ~2-3 seconds for full cookbook |
129 | | -- **Ruby syntax checking**: Instant per file |
130 | | -- **Full CI integration suite**: 15-30+ minutes (multiple platforms/versions) |
131 | | -- **File validation**: Use syntax checking over attempting to run code in sandbox |
| 95 | +The CI system uses these exact commands - following them matches CI behavior precisely. |
0 commit comments