A collection of reusable dev container features that can be easily shared and consumed by development teams. This repository provides a complete development workflow for creating, testing, and publishing dev container features.
Add features to your devcontainer.json
:
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/your-username/devcontainer-features/hello-world:1": {
"greeting": "Hello",
"name": "Developer"
},
"ghcr.io/your-username/devcontainer-features/hello-universe:1": {
"scope": "galaxy",
"language": "spanish"
}
}
}
-
Clone the repository:
git clone https://github.com/your-username/devcontainer-features.git cd devcontainer-features
-
Open in dev container:
- Open the repository in VS Code
- When prompted, click "Reopen in Container"
- Or use Command Palette:
Dev Containers: Reopen in Container
- Global commands will be automatically set up during container creation
-
Test features locally:
The dev container automatically sets up global commands for easy testing:
# Using global commands (recommended - work from any directory) test-feature hello-world test-all validate-feature hello-world build-feature hello-world # Or using scripts directly ./scripts/test-feature.sh hello-world ./scripts/test-all.sh ./scripts/validate-feature.sh hello-world ./scripts/build-feature.sh hello-world
A simple feature demonstrating basic dev container feature concepts.
- ID:
hello-world
- Description: Installs a customizable hello-world command
- Options:
greeting
,name
,includeDate
An advanced feature showcasing complex installation patterns and multiple tools.
- ID:
hello-universe
- Description: Advanced cosmic greeting with multiple tools and languages
- Options:
scope
,language
,installTools
,enableAsciiArt
.
βββ .devcontainer/ # Development environment
βββ .github/workflows/ # CI/CD pipelines
βββ src/ # Feature source code
β βββ hello-world/
β βββ hello-universe/
βββ test/ # Feature tests
β βββ _global/ # Shared test utilities
β βββ hello-world/
β βββ hello-universe/
βββ scripts/ # Development scripts
βββ docs/ # Documentation
βββ README.md
-
Create feature directory:
mkdir -p src/my-feature test/my-feature
-
Create feature files:
src/my-feature/devcontainer-feature.json
- Feature metadatasrc/my-feature/install.sh
- Installation scriptsrc/my-feature/README.md
- Documentation
-
Create tests:
test/my-feature/test.sh
- Test script
-
Validate and test:
# Using global commands (recommended) validate-feature my-feature test-feature my-feature # Or using scripts directly ./scripts/validate-feature.sh my-feature ./scripts/test-feature.sh my-feature
All scripts are available as global commands in the dev container:
Global Command | Script | Description |
---|---|---|
test-feature |
scripts/test-feature.sh |
Test individual feature |
test-all |
scripts/test-all.sh |
Test all features |
validate-feature |
scripts/validate-feature.sh |
Validate feature structure |
build-feature |
scripts/build-feature.sh |
Build feature package |
Note: Global commands are automatically set up when the dev container starts via the scripts/setup-global-commands.sh
script. You can use either the global commands (e.g., test-feature hello-world
) or run the scripts directly (e.g., ./scripts/test-feature.sh hello-world
).
Global Command Examples:
# Test a feature from anywhere in the container
test-feature hello-world
# Test with custom base image
test-feature hello-world mcr.microsoft.com/devcontainers/base:debian
# Validate feature structure
validate-feature my-new-feature
# Build feature package
build-feature hello-world
# Test all features
test-all
The repository includes comprehensive testing:
- Structure Validation: JSON schema validation, file presence checks
- Unit Testing: Individual feature functionality
- Integration Testing: Features against multiple base images
- Idempotency Testing: Safe re-installation
- Security Scanning: ShellCheck, secret detection
Run tests locally:
# Using global commands (recommended)
# Test specific feature against specific base image
test-feature hello-world mcr.microsoft.com/devcontainers/base:debian
# Test all features in parallel
BASE_IMAGES="ubuntu:22.04,debian:bullseye" test-all . true
# Test only specific features
FEATURES="hello-world" test-all
# Or using scripts directly
# Test specific feature against specific base image
./scripts/test-feature.sh hello-world mcr.microsoft.com/devcontainers/base:debian
# Test all features in parallel
BASE_IMAGES="ubuntu:22.04,debian:bullseye" ./scripts/test-all.sh . true
# Test only specific features
FEATURES="hello-world" ./scripts/test-all.sh
Every pull request triggers:
- Feature structure validation
- Multi-platform testing
- Security scanning
- Build verification
Features are automatically published when:
- Tags are pushed (
v*
) - Manual workflow dispatch
Published to: ghcr.io/your-username/devcontainer-features
test.yml
: Comprehensive testing on PRs and pushesrelease.yml
: Publishing and release management
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
See Contributing Guidelines for detailed information.
All features must:
- β
Include
devcontainer-feature.json
with proper metadata - β
Include
install.sh
with idempotent installation logic - β
Include
README.md
with usage documentation - β Support both root and non-root users
- β Handle platform detection and compatibility
- β Include comprehensive tests
- β Follow semantic versioning
- Idempotency: Features should be safe to run multiple times
- Platform Support: Detect and handle different base images
- Error Handling: Provide clear error messages
- Documentation: Include usage examples and option descriptions
- Testing: Cover all major functionality and edge cases
- Input Validation: Validate all user inputs
- Privilege Management: Minimize root operations
- Dependency Verification: Verify package checksums
- Secret Management: Never hardcode secrets
This project is licensed under the MIT License - see the LICENSE file for details.
Happy coding! π