|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Instructions for AI coding agents working on this project. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a Serverspec-based testing framework for validating Docker images. The project tests Node.js Docker images built from custom Dockerfiles by creating containers, running Serverspec tests against them, and cleaning up resources. |
| 8 | + |
| 9 | +**Tech Stack:** |
| 10 | +- Ruby 3.4+ and Ruby 4.0+ |
| 11 | +- Serverspec 2.43+ |
| 12 | +- Docker API gem 2.4+ |
| 13 | +- RSpec 3.13+ |
| 14 | +- Docker BuildKit |
| 15 | + |
| 16 | +**Current Node.js versions tested:** |
| 17 | +- Node.js 22.22.0 (Maintenance LTS) |
| 18 | +- Node.js 24.13.0 (Active LTS) |
| 19 | + |
| 20 | +## Setup Commands |
| 21 | + |
| 22 | +```bash |
| 23 | +# Install dependencies locally (no sudo required) |
| 24 | +bundle install |
| 25 | + |
| 26 | +# Docker BuildKit is enabled by default in Rakefile |
| 27 | +# Verify Docker is running |
| 28 | +docker info |
| 29 | +``` |
| 30 | + |
| 31 | +## Running Tests |
| 32 | + |
| 33 | +```bash |
| 34 | +# Run all tests in parallel (~18 seconds) |
| 35 | +bundle exec rake |
| 36 | + |
| 37 | +# Run tests for a specific Node.js version |
| 38 | +bundle exec rspec spec/22/Dockerfile_spec.rb |
| 39 | +bundle exec rspec spec/24/Dockerfile_spec.rb |
| 40 | + |
| 41 | +# Run with verbose output |
| 42 | +bundle exec rake --trace |
| 43 | +``` |
| 44 | + |
| 45 | +## Project Structure |
| 46 | + |
| 47 | +``` |
| 48 | +. |
| 49 | +├── 22/ # Node.js 22 Dockerfile |
| 50 | +├── 24/ # Node.js 24 Dockerfile |
| 51 | +├── spec/ |
| 52 | +│ ├── 22/Dockerfile_spec.rb # Tests for Node.js 22 |
| 53 | +│ ├── 24/Dockerfile_spec.rb # Tests for Node.js 24 |
| 54 | +│ ├── spec_helper.rb # Helper methods (create_image, delete_image) |
| 55 | +│ ├── node_tests.rb # Shared Node.js version tests |
| 56 | +│ └── npm_tests.rb # Shared npm tests |
| 57 | +├── Rakefile # Test runner with parallel execution |
| 58 | +├── Gemfile # Ruby dependencies |
| 59 | +└── .github/workflows/ruby.yml # CI with Ruby 3.4 & 4.0 matrix |
| 60 | +``` |
| 61 | + |
| 62 | +## Development Workflow |
| 63 | + |
| 64 | +### Adding a New Node.js Version |
| 65 | + |
| 66 | +1. Create new directory: `mkdir XX/` (where XX is the version) |
| 67 | +2. Copy Dockerfile from existing version and update `NODE_VERSION` |
| 68 | +3. Create test spec: `spec/XX/Dockerfile_spec.rb` |
| 69 | +4. Update Rakefile to include new task |
| 70 | +5. Test locally: `bundle exec rake` |
| 71 | +6. Update README.md to mention new version |
| 72 | + |
| 73 | +### Modifying Dockerfiles |
| 74 | + |
| 75 | +- Always update the `NODE_VERSION` environment variable |
| 76 | +- Verify GPG keys are current from nodejs/docker-node |
| 77 | +- Test on both amd64 and arm64 if possible |
| 78 | +- Use Debian trixie-slim as base image |
| 79 | + |
| 80 | +### Updating Dependencies |
| 81 | + |
| 82 | +```bash |
| 83 | +# Update specific gem |
| 84 | +bundle update <gem-name> |
| 85 | + |
| 86 | +# Update all gems (be careful) |
| 87 | +bundle update |
| 88 | + |
| 89 | +# Always remove BUNDLED WITH section from Gemfile.lock for CI compatibility |
| 90 | +``` |
| 91 | + |
| 92 | +## Testing Instructions |
| 93 | + |
| 94 | +### What Tests Validate |
| 95 | + |
| 96 | +1. **Node.js Version**: Correct version is installed |
| 97 | +2. **npm Functionality**: npm commands work correctly |
| 98 | +3. **Global Package Installation**: Can install global npm packages |
| 99 | +4. **Package Execution**: Installed packages run correctly |
| 100 | + |
| 101 | +### Writing Tests |
| 102 | + |
| 103 | +- Use shared test helpers in `spec/node_tests.rb` and `spec/npm_tests.rb` |
| 104 | +- Tests run inside Docker containers via docker-api gem |
| 105 | +- Each test spec must include proper setup/teardown: |
| 106 | + |
| 107 | +```ruby |
| 108 | +before(:all) do |
| 109 | + create_image(tag) # Builds Docker image |
| 110 | +end |
| 111 | + |
| 112 | +after(:all) do |
| 113 | + delete_image # Cleans up containers and images |
| 114 | +end |
| 115 | +``` |
| 116 | + |
| 117 | +### Test Execution |
| 118 | + |
| 119 | +- Tests run in PARALLEL by default (Rake multitask) |
| 120 | +- Each test gets isolated `ENV['TARGET_HOST']` |
| 121 | +- Containers are automatically cleaned up after tests |
| 122 | +- Images are removed only if tests pass |
| 123 | + |
| 124 | +## Code Style and Conventions |
| 125 | + |
| 126 | +### Ruby Style |
| 127 | + |
| 128 | +- Use 2 spaces for indentation |
| 129 | +- Follow existing patterns in spec files |
| 130 | +- Use double quotes for strings |
| 131 | +- Keep helper methods in `spec_helper.rb` |
| 132 | + |
| 133 | +### Serverspec Patterns |
| 134 | + |
| 135 | +```ruby |
| 136 | +# Use shared test methods |
| 137 | +test_node("24.13.0") # Preferred |
| 138 | +test_npm # Preferred |
| 139 | + |
| 140 | +# Resource types commonly used |
| 141 | +describe command("node --version") |
| 142 | +describe package("curl") |
| 143 | +describe file("/usr/local/bin/node") |
| 144 | +``` |
| 145 | + |
| 146 | +### Dockerfile Conventions |
| 147 | + |
| 148 | +- Use multi-line RUN with `&&` for layer efficiency |
| 149 | +- Always verify GPG signatures |
| 150 | +- Clean up apt cache: `rm -rf /var/lib/apt/lists/*` |
| 151 | +- Install CA certificates for HTTPS downloads |
| 152 | + |
| 153 | +## CI/CD Configuration |
| 154 | + |
| 155 | +### GitHub Actions Matrix |
| 156 | + |
| 157 | +Tests run on: |
| 158 | +- Ruby 3.4 (current stable) |
| 159 | +- Ruby 4.0 (latest stable) |
| 160 | + |
| 161 | +Both versions must pass before merge. |
| 162 | + |
| 163 | +### Environment Variables |
| 164 | + |
| 165 | +- `DOCKER_BUILDKIT=1`: Always enabled (set in workflow and Rakefile) |
| 166 | +- `TARGET_HOST`: Set per test for isolation (handled automatically) |
| 167 | + |
| 168 | +## Dos and Don'ts |
| 169 | + |
| 170 | +### DO ✅ |
| 171 | + |
| 172 | +- Test all changes locally before committing |
| 173 | +- Run full test suite: `bundle exec rake` |
| 174 | +- Keep Node.js versions on LTS releases |
| 175 | +- Update README.md when changing versions |
| 176 | +- Use version pinning in Gemfile (`~>` operator) |
| 177 | +- Clean up Docker resources properly |
| 178 | +- Use parallel test execution (Rake multitask) |
| 179 | +- Handle errors gracefully in helper methods |
| 180 | + |
| 181 | +### DON'T ❌ |
| 182 | + |
| 183 | +- Don't stop all Docker containers (only test containers) |
| 184 | +- Don't use `sudo` for bundle install (use local path) |
| 185 | +- Don't hardcode image IDs (use @image variable) |
| 186 | +- Don't skip the `after(:all)` cleanup block |
| 187 | +- Don't add BUNDLED WITH section to Gemfile.lock |
| 188 | +- Don't test EOL (End of Life) Node.js versions |
| 189 | +- Don't modify .bundle/config (project-level config) |
| 190 | +- Don't disable Docker BuildKit without good reason |
| 191 | + |
| 192 | +## Git Commit Guidelines |
| 193 | + |
| 194 | +### Commit Message Format |
| 195 | + |
| 196 | +``` |
| 197 | +<type>: <short summary> |
| 198 | +
|
| 199 | +<detailed description> |
| 200 | +
|
| 201 | +<optional breaking changes> |
| 202 | +
|
| 203 | +Co-authored-by: <AI agent or human collaborator> |
| 204 | +``` |
| 205 | + |
| 206 | +### Types |
| 207 | + |
| 208 | +- `fix`: Bug fixes |
| 209 | +- `feat`: New features |
| 210 | +- `perf`: Performance improvements |
| 211 | +- `test`: Test-only changes |
| 212 | +- `docs`: Documentation updates |
| 213 | +- `chore`: Dependency updates, tooling |
| 214 | + |
| 215 | +### Example |
| 216 | + |
| 217 | +``` |
| 218 | +feat: Add Node.js 26 LTS support |
| 219 | +
|
| 220 | +- Create 26/Dockerfile with NODE_VERSION=26.x.x |
| 221 | +- Add spec/26/Dockerfile_spec.rb with version tests |
| 222 | +- Update Rakefile to include node26 task |
| 223 | +- Update README.md to list version 26 |
| 224 | +
|
| 225 | +Tests pass on Ruby 3.4 and 4.0. |
| 226 | +``` |
| 227 | + |
| 228 | +## Pull Request Guidelines |
| 229 | + |
| 230 | +1. **One change per PR**: Keep PRs focused |
| 231 | +2. **Test coverage**: Ensure all tests pass locally and in CI |
| 232 | +3. **Update docs**: Update README.md if user-facing changes |
| 233 | +4. **Commit history**: Squash commits for cleaner history |
| 234 | +5. **Co-authorship**: Add co-author tags for collaborators |
| 235 | + |
| 236 | +## Security Considerations |
| 237 | + |
| 238 | +### Dockerfile Security |
| 239 | + |
| 240 | +- Always verify GPG signatures for Node.js downloads |
| 241 | +- Use specific Debian versions (not `latest`) |
| 242 | +- Minimize installed packages |
| 243 | +- Clean up package manager cache |
| 244 | + |
| 245 | +### Dependency Security |
| 246 | + |
| 247 | +- Keep gems updated for security patches |
| 248 | +- Review CVEs for docker-api and other dependencies |
| 249 | +- Use `bundle audit` to check for vulnerabilities |
| 250 | + |
| 251 | +### Container Isolation |
| 252 | + |
| 253 | +- Tests create isolated containers per version |
| 254 | +- Containers are removed after tests complete |
| 255 | +- Only stop containers created by tests (not system-wide) |
| 256 | + |
| 257 | +## Debugging |
| 258 | + |
| 259 | +### Common Issues |
| 260 | + |
| 261 | +**Tests fail with "container not found"** |
| 262 | +- Check that Docker daemon is running |
| 263 | +- Verify container cleanup in after(:all) block |
| 264 | + |
| 265 | +**Image build fails** |
| 266 | +- Verify Node.js version exists on nodejs.org |
| 267 | +- Check GPG key servers are accessible |
| 268 | +- Review Docker BuildKit logs |
| 269 | + |
| 270 | +**Bundler version conflicts** |
| 271 | +- Remove BUNDLED WITH section from Gemfile.lock |
| 272 | +- Let CI use its native Bundler version |
| 273 | + |
| 274 | +**Performance Issues** |
| 275 | +- Ensure Docker BuildKit is enabled |
| 276 | +- Verify parallel execution (multitask) is working |
| 277 | +- Check if Docker daemon has resource constraints |
| 278 | + |
| 279 | +### Debug Commands |
| 280 | + |
| 281 | +```bash |
| 282 | +# List Docker images created by tests |
| 283 | +docker images | grep test |
| 284 | + |
| 285 | +# Check running containers |
| 286 | +docker ps -a |
| 287 | + |
| 288 | +# View Docker BuildKit cache |
| 289 | +docker buildx du |
| 290 | + |
| 291 | +# Run with verbose Rake output |
| 292 | +bundle exec rake --trace |
| 293 | + |
| 294 | +# Run single test with RSpec output |
| 295 | +bundle exec rspec spec/24/Dockerfile_spec.rb --format documentation |
| 296 | +``` |
| 297 | + |
| 298 | +## Resources |
| 299 | + |
| 300 | +- **Serverspec Documentation**: http://serverspec.org/resource_types.html |
| 301 | +- **Docker API Gem**: https://github.com/swipely/docker-api |
| 302 | +- **Node.js Releases**: https://nodejs.org/en/about/previous-releases |
| 303 | +- **Ruby Releases**: https://www.ruby-lang.org/en/downloads/releases/ |
| 304 | + |
| 305 | +## Questions? |
| 306 | + |
| 307 | +When working on this project: |
| 308 | +1. Check existing patterns in similar files |
| 309 | +2. Run tests locally before committing |
| 310 | +3. Review CI output for multi-version compatibility |
| 311 | +4. Keep changes focused and well-tested |
| 312 | + |
| 313 | +--- |
| 314 | + |
| 315 | +**Note**: For historical information about AI contributions to this project, see [AI-CONTRIBUTIONS.md](./AI-CONTRIBUTIONS.md). |
0 commit comments