| description | Discussion of the devcontainers CLI project architecture, conventions, and development patterns |
|---|
The DevContainers CLI (@devcontainers/cli) is a TypeScript-based Node.js project that implements the Development Containers specification. It provides tooling for building, running, and managing development containers across different container runtimes and orchestrators.
src/spec-configuration/- Configuration parsing and validation for devcontainer.jsonsrc/spec-node/- Node.js-specific implementations of the specificationsrc/spec-utils/- Shared utilities for specification handlingsrc/test/- Comprehensive test suites including container tests
- Specification Compliance: All features must align with the official devcontainer specification
- Multi-Runtime Support: Support for Docker, Podman, and other container runtimes
- Cross-Platform: Works on Windows, macOS, and Linux
- Extensibility: Plugin architecture for features and lifecycle hooks
- Use strict TypeScript configuration with
noImplicitAnyandstrictNullChecks - Prefer interfaces over type aliases for object shapes
- Use proper async/await patterns, avoid callback-style APIs
- Export types and interfaces from dedicated
types.tsfiles
- Use custom error classes that extend base
Error - Provide meaningful error messages with context
- Include error codes for programmatic handling
- Log errors at appropriate levels using the project's logging system
- Unit tests in
src/test/with.test.tssuffix - Container integration tests that actually build and run containers
- Mock external dependencies (Docker API, file system operations)
- Use descriptive test names that explain the scenario being tested
- Docker: Primary runtime support via Docker API
- Podman: Alternative runtime with compatibility layer
- BuildKit: For advanced build features and caching
- Configuration discovery and parsing from workspace roots
- Template and feature resolution from local and remote sources
- Volume mounting and bind mount handling across platforms
- Container registries: For pulling base images and publishing
- Git repositories: For fetching features and templates
- Package managers: npm, pip, apt for installing tools in containers
- Define command in
src/spec-node/devContainersSpecCLI.ts - Implement handler function with proper argument parsing
- Add comprehensive error handling and logging
- Include unit and integration tests
- Update CLI help text and documentation
- Use
src/spec-configuration/utilities for parsing devcontainer.json - Validate configuration against JSON schema
- Handle inheritance and composition (extends, merging)
- Support both local and remote configuration sources
- Follow the specification's feature model
- Support installation scripts and lifecycle hooks
- Handle dependency resolution and ordering
- Provide proper cleanup and error recovery
- Path handling: Use
path.posixfor container paths,pathfor host paths - Line endings: Handle CRLF/LF differences in scripts and configs
- File permissions: Different behavior on Windows vs Unix systems
- Container mounting: Volume vs bind mount differences across platforms
- Docker Desktop vs Docker Engine behavior variations
- Podman compatibility quirks (networking, volumes, security contexts)
- Image building differences between runtimes
- Registry authentication handling
- Image caching: Leverage BuildKit and registry caching
- Parallel operations: Use proper concurrency for multi-container scenarios
- File watching: Efficient change detection for rebuild scenarios
- Network optimization: Minimize registry pulls and DNS lookups
# Install dependencies
npm install
# Build TypeScript
npm run build
# Run tests
npm test
# Run container tests (requires Docker)
npm run test:container- Always test with actual containers, not just mocks
- Test cross-platform scenarios when possible
- Include negative test cases for error conditions
- Verify cleanup behavior (containers, volumes, networks)
- Use
--log-level tracefor detailed operation logging - Container logs are available via runtime APIs
- File system operations are logged at debug level
- Network issues often manifest as timeout errors
- Implement in separate npm packages
- Follow feature specification format
- Provide proper metadata and documentation
- Test with multiple base images and scenarios
onCreateCommand,postCreateCommand,postStartCommand- Handle both synchronous and asynchronous operations
- Provide proper error propagation
- Support both shell commands and executable scripts
- Contributing Guidelines
- Development Container Specification
- Feature and Template specifications
- JSON Schema definitions
src/spec-node/devContainersSpecCLI.ts- Main CLI entry pointsrc/spec-configuration/configuration.ts- Configuration parsing logicsrc/spec-utils/- Shared utilities and helperssrc/test/container-features/- Feature integration tests.devcontainer/- Project's own development container configuration