|
1 | | -# Node.js Chef Cookbook Development |
| 1 | +# Copilot Instructions for Sous Chefs Cookbooks |
2 | 2 |
|
3 | | -This is a Chef cookbook for installing and managing Node.js and NPM across multiple operating systems including Debian/Ubuntu, RHEL/CentOS/Scientific/Amazon/Oracle, openSUSE, and Windows. |
| 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 | 8 |
|
9 | | -- **Bootstrap, build, and test the repository:** |
10 | | - - `sudo gem install bundler` -- Install Ruby bundler |
11 | | - - `sudo gem install chefspec berkshelf cookstyle rspec mdl --no-user-install` -- Install Chef development tools. Takes 3-5 minutes. NEVER CANCEL. Set timeout to 10+ minutes. |
12 | | - - Note: Internet connectivity issues may prevent `berks install` from working in some environments. |
| 9 | +## Project Structure |
13 | 10 |
|
14 | | -- **Run unit tests:** |
15 | | - - Unit testing has known gem dependency conflicts between RSpec versions that need resolution |
16 | | - - `rspec spec/` -- Currently fails due to ChefSpec/RSpec version conflicts. Requires manual gem dependency resolution. |
| 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 |
17 | 22 |
|
18 | | -- **Run linting and validation:** |
19 | | - - `cookstyle` -- Ruby/Chef code linting. Takes ~1.6 seconds. Always passes after auto-correction. |
20 | | - - `cookstyle --autocorrect` -- Auto-fix Ruby style issues. Takes ~1.8 seconds. NEVER CANCEL. |
21 | | - - `yamllint -c .yamllint .` -- YAML linting. Takes ~0.5 seconds. |
22 | | - - `mdl -c .mdlrc README.md CHANGELOG.md CONTRIBUTING.md` -- Markdown linting. Takes ~0.3 seconds. May find indentation issues. |
| 23 | +## Build and Test System |
23 | 24 |
|
24 | | -- **Integration testing:** |
25 | | - - Uses Test Kitchen with Dokken (Docker-based testing) |
26 | | - - `kitchen list` -- List available test suites (requires Test Kitchen installation) |
27 | | - - Integration tests run across multiple OS platforms: AlmaLinux, Rocky Linux, Amazon Linux, CentOS, Debian, Ubuntu |
28 | | - - Docker is available but Test Kitchen installation has dependency conflicts |
| 25 | +### Environment Setup |
| 26 | +**MANDATORY:** Install Chef Workstation first - provides chef, berks, cookstyle, kitchen tools. |
29 | 27 |
|
30 | | -## Validation |
31 | | - |
32 | | -- **CRITICAL**: Internet connectivity limitations prevent downloading cookbook dependencies via Berkshelf (`berks install` fails with network errors) |
33 | | -- **ALWAYS** run `cookstyle` and `yamllint` before committing changes |
34 | | -- Unit testing requires resolving RSpec gem version conflicts (ChefSpec expects rspec-expectations <= 3.12.3 but system has 3.13.5) |
35 | | -- Integration testing via Test Kitchen requires proper gem installation which has conflicts |
36 | | -- **Manual validation scenarios**: After making cookbook changes, the cookbook should successfully install Node.js and NPM on target platforms |
37 | | - |
38 | | -## Common Tasks |
39 | | - |
40 | | -### Repository structure |
41 | | -``` |
42 | | -/home/runner/work/nodejs/nodejs/ |
43 | | -├── README.md # Main documentation |
44 | | -├── CONTRIBUTING.md # Contribution guidelines |
45 | | -├── TESTING.md # Testing information |
46 | | -├── metadata.rb # Cookbook metadata and dependencies |
47 | | -├── Berksfile # Cookbook dependency management |
48 | | -├── recipes/ # Chef recipes for different install methods |
49 | | -├── resources/ # Custom Chef resources (npm_package) |
50 | | -├── libraries/ # Helper libraries |
51 | | -├── attributes/ # Default attribute values |
52 | | -├── spec/ # Unit tests (RSpec/ChefSpec) |
53 | | -├── test/ # Integration tests (Test Kitchen/InSpec) |
54 | | -├── kitchen.yml # Test Kitchen configuration |
55 | | -├── kitchen.dokken.yml # Docker-based testing config |
56 | | -├── .github/workflows/ # CI/CD pipelines |
57 | | -├── .rubocop.yml # Ruby style configuration |
58 | | -├── .yamllint # YAML linting rules |
59 | | -└── .mdlrc # Markdown linting rules |
| 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. |
60 | 36 | ``` |
61 | 37 |
|
62 | | -### Key recipes |
63 | | -- `recipes/default.rb` -- Main entry point, includes nodejs recipe |
64 | | -- `recipes/nodejs_from_package.rb` -- Install from OS packages (default method) |
65 | | -- `recipes/nodejs_from_binary.rb` -- Install from official binaries |
66 | | -- `recipes/nodejs_from_source.rb` -- Compile from source |
67 | | -- `recipes/nodejs_from_chocolatey.rb` -- Windows Chocolatey installation |
68 | | -- `recipes/npm.rb` -- NPM installation and management |
69 | | - |
70 | | -### Resources |
71 | | -- `resources/npm_package.rb` -- Custom resource for managing NPM packages |
72 | | - |
73 | | -### Testing suites (kitchen.yml) |
74 | | -- `default` -- Standard installation with package management |
75 | | -- `package` -- Package-only installation |
76 | | -- `source` -- Source compilation installation |
77 | | -- `npm_embedded` -- Embedded NPM testing |
78 | | -- `npm_source` -- NPM from source |
79 | | -- `chocolatey` -- Windows Chocolatey testing |
80 | | - |
81 | | -## Build and Test Times |
82 | | - |
83 | | -- **Cookstyle linting**: ~1.6 seconds (always succeeds after auto-correction) |
84 | | -- **YAML linting**: ~0.5 seconds |
85 | | -- **Markdown linting**: ~0.3 seconds |
86 | | -- **Cookstyle auto-correction**: ~1.8 seconds |
87 | | -- **Unit tests**: Currently broken due to gem conflicts |
88 | | -- **Integration tests**: Not measurable due to dependency installation issues |
89 | | -- **Gem installation**: 3-5 minutes for full Chef toolchain. NEVER CANCEL. Set timeout to 10+ minutes. |
90 | | - |
91 | | -## Known Issues and Workarounds |
92 | | - |
93 | | -- **Berkshelf dependency installation fails** due to network connectivity restrictions (`berks install` returns SocketError) |
94 | | -- **Unit testing broken** due to RSpec version conflicts (ChefSpec requires older RSpec versions) |
95 | | -- **Test Kitchen installation fails** due to gem executable conflicts during installation |
96 | | -- **Chef CLI exec fails** due to missing omnibus installation directory |
97 | | -- **Internet connectivity limitations** prevent downloading external cookbook dependencies |
| 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 |
98 | 43 |
|
99 | | -## Development Workflow |
| 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 |
100 | 49 |
|
101 | | -1. **Always run linting first**: `cookstyle && yamllint -c .yamllint . && mdl -c .mdlrc README.md` |
102 | | -2. **Auto-fix style issues**: `cookstyle --autocorrect` |
103 | | -3. **Manual testing**: Test cookbook functionality by examining recipes and ensuring they follow Chef best practices |
104 | | -4. **CI/CD**: GitHub Actions handles comprehensive testing across multiple OS platforms using containerized environments |
105 | | - |
106 | | -## Environment Requirements |
107 | | - |
108 | | -- **Ruby 3.2.3+** (system provided) |
109 | | -- **Bundler** (install via `sudo gem install bundler`) |
110 | | -- **Chef development gems**: chefspec, berkshelf, cookstyle, rspec, mdl |
111 | | -- **Docker** (available for Test Kitchen integration testing) |
112 | | -- **Limited internet access**: External cookbook dependencies cannot be downloaded |
113 | | - |
114 | | -## Troubleshooting |
| 50 | +## Development Workflow |
115 | 51 |
|
116 | | -- If `berks install` fails with network errors, this is expected in restricted environments |
117 | | -- If unit tests fail with gem conflicts, gem dependency resolution is required |
118 | | -- Always use `sudo gem install --no-user-install` for system-wide gem installation |
119 | | -- Use `CHEF_LICENSE=accept-no-persist` environment variable when Chef tools require license acceptance |
| 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