|
1 | | -We use Chef Cookstyle to lint our Chef cookbooks. We use Test Kitchen to integration test our cookbooks. Test cookbooks are in the test/cookbooks directory. We keep documentation in README.md and the documentation folder. When suggestion improvements ignore the test directory. |
| 1 | +# PostgreSQL Chef Cookbook Development Guide |
| 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). |
| 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.** |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### 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 |
| 70 | + |
| 71 | +### 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 | +``` |
| 126 | + |
| 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 |
0 commit comments